@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 CHANGED
@@ -1,6 +1,5 @@
1
1
  import { DBAdapter, DBAdapterDebugLogOption } from "@better-auth/core/db/adapter";
2
2
  import { BetterAuthOptions } from "@better-auth/core";
3
-
4
3
  //#region src/drizzle-adapter.d.ts
5
4
  interface DB {
6
5
  [key: string]: any;
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's drivers report affected rows under different shapes: postgres-js
45
- * exposes `rowCount`, mysql2 reports `affectedRows`/`rowsAffected` (sometimes as
46
- * the first element of a result-header array), and better-sqlite3 uses
47
- * `changes`. This normalizes those so write methods that depend on affected
48
- * rows honor the adapter contract instead of leaking the raw driver result.
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
- const r = result;
69
- return r.affectedRows ?? r.rowsAffected ?? r.changes;
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
- return await withReturning(model, db.insert(schemaModel).values(values), values);
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
- return await withReturning(model, db.update(schemaModel).set(values).where(...clause), values, where);
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.22",
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.22"
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.21.1",
54
- "typescript": "^5.9.3",
55
- "@better-auth/core": "1.6.22"
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",