@better-auth/drizzle-adapter 1.6.22 → 1.6.23

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.
Files changed (2) hide show
  1. package/dist/index.mjs +20 -10
  2. package/package.json +3 -3
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;
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.23",
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.23"
44
44
  },
45
45
  "peerDependenciesMeta": {
46
46
  "drizzle-orm": {
@@ -52,7 +52,7 @@
52
52
  "drizzle-orm": "^0.45.2",
53
53
  "tsdown": "0.21.1",
54
54
  "typescript": "^5.9.3",
55
- "@better-auth/core": "1.6.22"
55
+ "@better-auth/core": "1.6.23"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "tsdown",