@better-auth/drizzle-adapter 1.6.22 → 1.6.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +0 -1
- package/dist/index.mjs +24 -12
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -41,15 +41,19 @@ function insensitiveNe(column, value) {
|
|
|
41
41
|
/**
|
|
42
42
|
* Derive the number of affected rows from a Drizzle write result.
|
|
43
43
|
*
|
|
44
|
-
* Drizzle
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* `
|
|
48
|
-
*
|
|
44
|
+
* Drizzle returns the raw per-driver result for a non-returning write, so the
|
|
45
|
+
* count lives under a different field per driver: node-postgres / neon expose
|
|
46
|
+
* `rowCount`, postgres-js / bun-sql carry `count` on an Array subclass, mysql2
|
|
47
|
+
* reports `affectedRows` (in a result-header array), planetscale and other
|
|
48
|
+
* serverless drivers use `rowsAffected`, better-sqlite3 uses `changes`, and
|
|
49
|
+
* Cloudflare D1 nests the count under `meta.changes`. This normalizes them so
|
|
50
|
+
* write methods that depend on affected rows honor the adapter contract instead
|
|
51
|
+
* of leaking the raw driver result.
|
|
49
52
|
*/
|
|
50
53
|
function getAffectedRowCount(result, operation, context) {
|
|
51
54
|
let count = 0;
|
|
52
55
|
if (result && typeof result === "object" && "rowCount" in result) count = result.rowCount;
|
|
56
|
+
else if (result && typeof result === "object" && typeof result.count === "number") count = result.count;
|
|
53
57
|
else if (Array.isArray(result)) count = result.length > 0 && hasDriverRowCount(result[0]) ? readDriverRowCount(result[0]) : result.length;
|
|
54
58
|
else if (hasDriverRowCount(result)) count = readDriverRowCount(result);
|
|
55
59
|
if (typeof count !== "number") {
|
|
@@ -61,12 +65,18 @@ function getAffectedRowCount(result, operation, context) {
|
|
|
61
65
|
}
|
|
62
66
|
return count;
|
|
63
67
|
}
|
|
64
|
-
function hasDriverRowCount(result) {
|
|
65
|
-
return !!result && typeof result === "object" && ("affectedRows" in result || "rowsAffected" in result || "changes" in result);
|
|
66
|
-
}
|
|
67
68
|
function readDriverRowCount(result) {
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
if (!result || typeof result !== "object") return void 0;
|
|
70
|
+
if ("affectedRows" in result) return result.affectedRows;
|
|
71
|
+
if ("rowsAffected" in result) return result.rowsAffected;
|
|
72
|
+
if ("changes" in result) return result.changes;
|
|
73
|
+
if ("meta" in result) {
|
|
74
|
+
const meta = result.meta;
|
|
75
|
+
if (meta && typeof meta === "object" && "changes" in meta) return meta.changes;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function hasDriverRowCount(result) {
|
|
79
|
+
return readDriverRowCount(result) !== void 0;
|
|
70
80
|
}
|
|
71
81
|
const drizzleAdapter = (db, config) => {
|
|
72
82
|
let lazyOptions = null;
|
|
@@ -321,7 +331,8 @@ const drizzleAdapter = (db, config) => {
|
|
|
321
331
|
async create({ model, data: values }) {
|
|
322
332
|
const schemaModel = getSchema(model);
|
|
323
333
|
checkMissingFields(schemaModel, model, values);
|
|
324
|
-
|
|
334
|
+
const builder = db.insert(schemaModel).values(values);
|
|
335
|
+
return await withReturning(model, builder, values);
|
|
325
336
|
},
|
|
326
337
|
async findOne({ model, where, select, join }) {
|
|
327
338
|
const schemaModel = getSchema(model);
|
|
@@ -456,7 +467,8 @@ const drizzleAdapter = (db, config) => {
|
|
|
456
467
|
async update({ model, where, update: values }) {
|
|
457
468
|
const schemaModel = getSchema(model);
|
|
458
469
|
const clause = convertWhereClause(where, model);
|
|
459
|
-
|
|
470
|
+
const builder = db.update(schemaModel).set(values).where(...clause);
|
|
471
|
+
return await withReturning(model, builder, values, where);
|
|
460
472
|
},
|
|
461
473
|
async updateMany({ model, where, update: values }) {
|
|
462
474
|
const schemaModel = getSchema(model);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/drizzle-adapter",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.24",
|
|
4
4
|
"bugs": {
|
|
5
5
|
"url": "https://github.com/better-auth/better-auth/issues"
|
|
6
6
|
},
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@better-auth/utils": "0.4.2",
|
|
42
42
|
"drizzle-orm": "^0.45.2",
|
|
43
|
-
"@better-auth/core": "^1.6.
|
|
43
|
+
"@better-auth/core": "^1.6.24"
|
|
44
44
|
},
|
|
45
45
|
"peerDependenciesMeta": {
|
|
46
46
|
"drizzle-orm": {
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@better-auth/utils": "0.4.2",
|
|
52
52
|
"drizzle-orm": "^0.45.2",
|
|
53
|
-
"tsdown": "0.
|
|
54
|
-
"typescript": "^
|
|
55
|
-
"@better-auth/core": "1.6.
|
|
53
|
+
"tsdown": "0.22.7",
|
|
54
|
+
"typescript": "^6.0.3",
|
|
55
|
+
"@better-auth/core": "1.6.24"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "tsdown",
|