@better-auth/kysely-adapter 1.6.15 → 1.6.17

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.
@@ -61,7 +61,14 @@ var BunSqliteConnection = class {
61
61
  executeQuery(compiledQuery) {
62
62
  const { sql, parameters } = compiledQuery;
63
63
  const stmt = this.#db.prepare(sql);
64
- return Promise.resolve({ rows: stmt.all(parameters) });
64
+ const params = parameters;
65
+ if (stmt.columnNames.length > 0) return Promise.resolve({ rows: stmt.all(...params) });
66
+ const { changes, lastInsertRowid } = stmt.run(...params);
67
+ return Promise.resolve({
68
+ rows: [],
69
+ numAffectedRows: BigInt(changes),
70
+ insertId: typeof lastInsertRowid === "bigint" ? lastInsertRowid : BigInt(lastInsertRowid)
71
+ });
65
72
  }
66
73
  async *streamQuery() {
67
74
  throw new Error("Streaming query is not supported by SQLite driver.");
package/dist/index.mjs CHANGED
@@ -44,7 +44,7 @@ const createKyselyAdapter = async (config) => {
44
44
  if ("getConnection" in db) dialect = new MysqlDialect(db);
45
45
  if ("connect" in db) dialect = new PostgresDialect({ pool: db });
46
46
  if ("fileControl" in db) {
47
- const { BunSqliteDialect } = await import("./bun-sqlite-dialect-DApWON3g.mjs");
47
+ const { BunSqliteDialect } = await import("./bun-sqlite-dialect-BW9W1_Ps.mjs");
48
48
  dialect = new BunSqliteDialect({ database: db });
49
49
  }
50
50
  if ("createSession" in db) {
@@ -490,9 +490,41 @@ const kyselyAdapter = (db, config) => {
490
490
  };
491
491
  return inTransaction ? claimFromTransaction(db) : db.transaction().execute(claimFromTransaction);
492
492
  }
493
- const targetIds = applyWhere(db.selectFrom(model).select(`${model}.${idField}`)).limit(1);
493
+ const selectIds = applyWhere(db.selectFrom(model).select(`${model}.${idField}`));
494
+ const targetIds = config?.type === "mssql" ? selectIds.top(1) : selectIds.limit(1);
494
495
  return deleteWithReturning(db.deleteFrom(model).where(`${model}.${idField}`, "in", targetIds));
495
496
  },
497
+ async incrementOne({ model, where, increment, set }) {
498
+ const { and, or } = convertWhereClause(model, where);
499
+ const applyWhere = (query) => {
500
+ if (and) query = query.where((eb) => eb.and(and.map((expr) => expr(eb))));
501
+ if (or) query = query.where((eb) => eb.or(or.map((expr) => expr(eb))));
502
+ return query;
503
+ };
504
+ const assignments = { ...set ?? {} };
505
+ for (const [field, delta] of Object.entries(increment)) assignments[field] = sql`${sql.ref(field)} + ${delta}`;
506
+ const idField = getFieldName({
507
+ model,
508
+ field: "id"
509
+ });
510
+ if (config?.type === "mysql") {
511
+ const incrementInTransaction = async (trx) => {
512
+ const target = await applyWhere(trx.selectFrom(model).select(`${model}.${idField}`).forUpdate()).limit(1).executeTakeFirst();
513
+ if (!target) return null;
514
+ const targetId = target[idField] ?? target.id;
515
+ if (targetId === void 0 || targetId === null) return null;
516
+ const updated = await applyWhere(trx.updateTable(model).set(assignments)).where(`${model}.${idField}`, "=", targetId).executeTakeFirst();
517
+ if (Number(updated.numUpdatedRows) === 0) return null;
518
+ return await trx.selectFrom(model).selectAll().where(`${model}.${idField}`, "=", targetId).limit(1).executeTakeFirst() ?? null;
519
+ };
520
+ return inTransaction ? incrementInTransaction(db) : db.transaction().execute(incrementInTransaction);
521
+ }
522
+ const selectIds = applyWhere(db.selectFrom(model).select(`${model}.${idField}`));
523
+ const targetIds = config?.type === "mssql" ? selectIds.top(1) : selectIds.limit(1);
524
+ const updateQuery = db.updateTable(model).set(assignments).where(`${model}.${idField}`, "in", targetIds);
525
+ if (config?.type === "mssql") return await updateQuery.outputAll("inserted").executeTakeFirst() ?? null;
526
+ return await updateQuery.returningAll().executeTakeFirst() ?? null;
527
+ },
496
528
  options: config
497
529
  };
498
530
  };
@@ -60,8 +60,15 @@ var NodeSqliteConnection = class {
60
60
  }
61
61
  executeQuery(compiledQuery) {
62
62
  const { sql, parameters } = compiledQuery;
63
- const rows = this.#db.prepare(sql).all(...parameters);
64
- return Promise.resolve({ rows });
63
+ const stmt = this.#db.prepare(sql);
64
+ const params = parameters;
65
+ if (stmt.columns().length > 0) return Promise.resolve({ rows: stmt.all(...params) });
66
+ const { changes, lastInsertRowid } = stmt.run(...params);
67
+ return Promise.resolve({
68
+ rows: [],
69
+ numAffectedRows: BigInt(changes),
70
+ insertId: typeof lastInsertRowid === "bigint" ? lastInsertRowid : BigInt(lastInsertRowid)
71
+ });
65
72
  }
66
73
  async *streamQuery() {
67
74
  throw new Error("Streaming query is not supported by SQLite driver.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth/kysely-adapter",
3
- "version": "1.6.15",
3
+ "version": "1.6.17",
4
4
  "description": "Kysely adapter for Better Auth",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -42,7 +42,7 @@
42
42
  "peerDependencies": {
43
43
  "@better-auth/utils": "0.4.1",
44
44
  "kysely": "^0.28.17 || ^0.29.0",
45
- "@better-auth/core": "^1.6.15"
45
+ "@better-auth/core": "^1.6.17"
46
46
  },
47
47
  "peerDependenciesMeta": {
48
48
  "kysely": {
@@ -55,7 +55,7 @@
55
55
  "kysely": "^0.28.17 || ^0.29.0",
56
56
  "tsdown": "0.21.1",
57
57
  "typescript": "^5.9.3",
58
- "@better-auth/core": "1.6.15"
58
+ "@better-auth/core": "1.6.17"
59
59
  },
60
60
  "scripts": {
61
61
  "build": "tsdown",