@better-auth/kysely-adapter 1.8.0-beta.1 → 1.8.0-beta.11
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/{bun-sqlite-dialect-DoOVo4ja.mjs → bun-sqlite-dialect-C1xgdqho.mjs} +2 -3
- package/dist/{d1-sqlite-dialect-m0f01-4z.mjs → d1-sqlite-dialect-CFQyWgtB.mjs} +4 -4
- package/dist/index.d.mts +21 -21
- package/dist/index.mjs +96 -23
- package/dist/node-sqlite-dialect.d.mts +3 -7
- package/dist/node-sqlite-dialect.mjs +2 -3
- package/dist/{sqlite-introspector-DSCAP82F.mjs → sqlite-introspector-DeY-XxNH.mjs} +2 -4
- package/package.json +7 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as createSqliteIntrospector } from "./sqlite-introspector-
|
|
1
|
+
import { t as createSqliteIntrospector } from "./sqlite-introspector-DeY-XxNH.mjs";
|
|
2
2
|
import { CompiledQuery, DefaultQueryCompiler } from "kysely";
|
|
3
|
-
|
|
3
|
+
// src/bun-sqlite-dialect.ts
|
|
4
4
|
var BunSqliteAdapter = class {
|
|
5
5
|
get supportsCreateIfNotExists() {
|
|
6
6
|
return true;
|
|
@@ -119,5 +119,4 @@ var BunSqliteDialect = class {
|
|
|
119
119
|
return createSqliteIntrospector(db);
|
|
120
120
|
}
|
|
121
121
|
};
|
|
122
|
-
//#endregion
|
|
123
122
|
export { BunSqliteDialect };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as DEFAULT_MIGRATION_LOCK_TABLE, i as toSqliteTableMetadata, o as DEFAULT_MIGRATION_TABLE, r as sqliteIntegerPrimaryKeyColumn } from "./sqlite-introspector-
|
|
1
|
+
import { a as DEFAULT_MIGRATION_LOCK_TABLE, i as toSqliteTableMetadata, o as DEFAULT_MIGRATION_TABLE, r as sqliteIntegerPrimaryKeyColumn } from "./sqlite-introspector-DeY-XxNH.mjs";
|
|
2
2
|
import { SqliteAdapter, SqliteQueryCompiler } from "kysely";
|
|
3
|
-
|
|
3
|
+
// src/d1-sqlite-dialect.ts
|
|
4
4
|
function quoteSqliteStringLiteral(value) {
|
|
5
5
|
return `'${value.replaceAll("'", "''")}'`;
|
|
6
6
|
}
|
|
@@ -107,7 +107,8 @@ var D1SqliteIntrospector = class {
|
|
|
107
107
|
const indexResults = rowidCandidates.length ? await this.#d1.batch(rowidCandidates.map(({ tableName }) => this.#d1.prepare(`PRAGMA index_list(${quoteSqliteStringLiteral(tableName)})`))) : [];
|
|
108
108
|
const generatedColumns = new Map(rowidCandidates.filter((_, index) => !indexResults[index]?.results?.some((row) => row.origin === "pk")).map(({ index, column }) => [index, column]));
|
|
109
109
|
return tables.map((table, index) => {
|
|
110
|
-
|
|
110
|
+
const columns = batchResults[index]?.results ?? [];
|
|
111
|
+
return toSqliteTableMetadata(table, columns, generatedColumns.get(index));
|
|
111
112
|
});
|
|
112
113
|
}
|
|
113
114
|
async getMetadata(options) {
|
|
@@ -133,5 +134,4 @@ var D1SqliteDialect = class {
|
|
|
133
134
|
return new D1SqliteIntrospector(db, this.#config.database);
|
|
134
135
|
}
|
|
135
136
|
};
|
|
136
|
-
//#endregion
|
|
137
137
|
export { D1SqliteDialect, createD1IndexIntrospector };
|
package/dist/index.d.mts
CHANGED
|
@@ -2,13 +2,11 @@ import { Kysely, TableMetadata } from "kysely";
|
|
|
2
2
|
import { DBAdapter, DBAdapterDebugLogOption } from "@better-auth/core/db/adapter";
|
|
3
3
|
import { ExpectedSchema, IntrospectedTable } from "@better-auth/core/db/internal";
|
|
4
4
|
import { BetterAuthOptions } from "@better-auth/core";
|
|
5
|
-
|
|
6
|
-
//#region src/types.d.ts
|
|
7
|
-
type KyselyDatabaseType = "postgres" | "mysql" | "sqlite" | "mssql";
|
|
5
|
+
export type KyselyDatabaseType = "postgres" | "mysql" | "sqlite" | "mssql";
|
|
8
6
|
/**
|
|
9
7
|
* Metadata for a column that participates in a database index.
|
|
10
8
|
*/
|
|
11
|
-
interface DatabaseIndexColumnMetadata {
|
|
9
|
+
export interface DatabaseIndexColumnMetadata {
|
|
12
10
|
/**
|
|
13
11
|
* Whether the index covers the complete column value rather than a prefix.
|
|
14
12
|
*/
|
|
@@ -19,7 +17,7 @@ interface DatabaseIndexColumnMetadata {
|
|
|
19
17
|
/**
|
|
20
18
|
* Database-agnostic metadata for an index.
|
|
21
19
|
*/
|
|
22
|
-
interface DatabaseIndexMetadata {
|
|
20
|
+
export interface DatabaseIndexMetadata {
|
|
23
21
|
readonly columns: readonly DatabaseIndexColumnMetadata[];
|
|
24
22
|
readonly name: string;
|
|
25
23
|
readonly partial: boolean;
|
|
@@ -33,11 +31,9 @@ interface DatabaseIndexMetadata {
|
|
|
33
31
|
/**
|
|
34
32
|
* Reads normalized index metadata for the provided database tables.
|
|
35
33
|
*/
|
|
36
|
-
type DatabaseIndexIntrospector = (tableNames: readonly string[]) => Promise<readonly DatabaseIndexMetadata[]>;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
declare function getKyselyDatabaseType(db: BetterAuthOptions["database"]): KyselyDatabaseType | null;
|
|
40
|
-
declare const createKyselyAdapter: (config: BetterAuthOptions) => Promise<{
|
|
34
|
+
export type DatabaseIndexIntrospector = (tableNames: readonly string[]) => Promise<readonly DatabaseIndexMetadata[]>;
|
|
35
|
+
export declare function getKyselyDatabaseType(db: BetterAuthOptions["database"]): KyselyDatabaseType | null;
|
|
36
|
+
export declare const createKyselyAdapter: (config: BetterAuthOptions) => Promise<{
|
|
41
37
|
kysely: Kysely<any>;
|
|
42
38
|
databaseType: "postgres" | "mysql" | "sqlite" | "mssql";
|
|
43
39
|
introspectIndexes: undefined;
|
|
@@ -50,8 +46,6 @@ declare const createKyselyAdapter: (config: BetterAuthOptions) => Promise<{
|
|
|
50
46
|
schemaName: undefined;
|
|
51
47
|
transaction: boolean | undefined;
|
|
52
48
|
}>;
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/kysely-adapter.d.ts
|
|
55
49
|
interface KyselyAdapterConfig {
|
|
56
50
|
/**
|
|
57
51
|
* Database type.
|
|
@@ -91,26 +85,32 @@ interface KyselyAdapterConfig {
|
|
|
91
85
|
*/
|
|
92
86
|
transaction?: boolean | undefined;
|
|
93
87
|
}
|
|
94
|
-
declare const kyselyAdapter: (db: Kysely<any>, config?: KyselyAdapterConfig | undefined) => (options: BetterAuthOptions) => DBAdapter<BetterAuthOptions>;
|
|
95
|
-
//#endregion
|
|
96
|
-
//#region src/schema-check.d.ts
|
|
88
|
+
export declare const kyselyAdapter: (db: Kysely<any>, config?: KyselyAdapterConfig | undefined) => (options: BetterAuthOptions) => DBAdapter<BetterAuthOptions>;
|
|
97
89
|
/**
|
|
98
90
|
* Converts Kysely table metadata into the shape `diffSchema` compares.
|
|
99
91
|
*/
|
|
100
|
-
declare function toIntrospectedTables(tables: readonly TableMetadata[]): IntrospectedTable[];
|
|
92
|
+
export declare function toIntrospectedTables(tables: readonly TableMetadata[]): IntrospectedTable[];
|
|
101
93
|
/**
|
|
102
94
|
* The expected schema in the identifiers the connection sends. A plugin that
|
|
103
95
|
* renames identifiers, such as `CamelCasePlugin`, does so in `transformQuery`,
|
|
104
96
|
* so compiling one select per table through the connection yields the names
|
|
105
97
|
* the database is asked for. Without such a plugin the schema is unchanged.
|
|
106
98
|
*/
|
|
107
|
-
declare function toPhysicalSchema(db: Kysely<unknown>, expected: ExpectedSchema): ExpectedSchema;
|
|
99
|
+
export declare function toPhysicalSchema(db: Kysely<unknown>, expected: ExpectedSchema): ExpectedSchema;
|
|
108
100
|
/**
|
|
109
101
|
* The default schema for migration tooling. Let PostgreSQL resolve role
|
|
110
102
|
* names and privileges, retaining the legacy public fallback when none exists.
|
|
111
103
|
* Runtime validation uses the effective search path instead of this fallback.
|
|
112
104
|
*/
|
|
113
|
-
declare function getPostgresSchema(db: Kysely<unknown>): Promise<string>;
|
|
114
|
-
declare function getMssqlSchema(db: Kysely<unknown>): Promise<string>;
|
|
115
|
-
|
|
116
|
-
|
|
105
|
+
export declare function getPostgresSchema(db: Kysely<unknown>): Promise<string>;
|
|
106
|
+
export declare function getMssqlSchema(db: Kysely<unknown>): Promise<string>;
|
|
107
|
+
/**
|
|
108
|
+
* Reads the tables in `schemas` with the metadata Kysely's PostgreSQL
|
|
109
|
+
* introspector reports. That introspector reads every schema and resolves
|
|
110
|
+
* each one by name, so a schema another connection drops during the read
|
|
111
|
+
* fails it with "schema does not exist" or "relation does not exist".
|
|
112
|
+
*/
|
|
113
|
+
export declare function introspectPostgresTables(db: Kysely<unknown>, schemas: readonly string[]): Promise<(TableMetadata & {
|
|
114
|
+
isForeign: boolean;
|
|
115
|
+
})[]>;
|
|
116
|
+
export {};
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { n as introspectSqliteTables } from "./sqlite-introspector-
|
|
1
|
+
import { n as introspectSqliteTables } from "./sqlite-introspector-DeY-XxNH.mjs";
|
|
2
2
|
import { BetterAuthError } from "@better-auth/core/error";
|
|
3
3
|
import { ColumnNode, Kysely, MssqlDialect, MysqlDialect, PostgresDialect, ReferenceNode, SelectQueryNode, SqliteDialect, TableNode, sql } from "kysely";
|
|
4
4
|
import { createAdapterFactory } from "@better-auth/core/db/adapter";
|
|
5
5
|
import { checksSchema, createSchemaCheck, diffSchema, getExpectedSchema, registerSchemaCheck } from "@better-auth/core/db/internal";
|
|
6
6
|
import { logger } from "@better-auth/core/env";
|
|
7
7
|
import { capitalizeFirstLetter } from "@better-auth/core/utils/string";
|
|
8
|
-
|
|
8
|
+
// src/dialect.ts
|
|
9
9
|
function getKyselyDatabaseType(db) {
|
|
10
10
|
if (!db) return null;
|
|
11
11
|
if ("dialect" in db) return getKyselyDatabaseType(db.dialect);
|
|
@@ -78,7 +78,7 @@ const createKyselyAdapter = async (config) => {
|
|
|
78
78
|
transaction = true;
|
|
79
79
|
}
|
|
80
80
|
if ("fileControl" in db) {
|
|
81
|
-
const { BunSqliteDialect } = await import("./bun-sqlite-dialect-
|
|
81
|
+
const { BunSqliteDialect } = await import("./bun-sqlite-dialect-C1xgdqho.mjs");
|
|
82
82
|
dialect = new BunSqliteDialect({ database: db });
|
|
83
83
|
transaction = true;
|
|
84
84
|
}
|
|
@@ -101,7 +101,7 @@ const createKyselyAdapter = async (config) => {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
if ("batch" in db && "exec" in db && "prepare" in db) {
|
|
104
|
-
const { createD1IndexIntrospector, D1SqliteDialect } = await import("./d1-sqlite-dialect-
|
|
104
|
+
const { createD1IndexIntrospector, D1SqliteDialect } = await import("./d1-sqlite-dialect-CFQyWgtB.mjs");
|
|
105
105
|
dialect = new D1SqliteDialect({ database: db });
|
|
106
106
|
introspectIndexes = createD1IndexIntrospector(db);
|
|
107
107
|
transaction = false;
|
|
@@ -114,8 +114,7 @@ const createKyselyAdapter = async (config) => {
|
|
|
114
114
|
transaction
|
|
115
115
|
};
|
|
116
116
|
};
|
|
117
|
-
|
|
118
|
-
//#region src/query-builders.ts
|
|
117
|
+
// src/query-builders.ts
|
|
119
118
|
/**
|
|
120
119
|
* Case-insensitive ILIKE/LIKE for pattern matching.
|
|
121
120
|
* Uses ILIKE on PostgreSQL, LOWER()+LIKE on MySQL/SQLite/MSSQL.
|
|
@@ -161,8 +160,7 @@ function insensitiveNe(columnRef, value) {
|
|
|
161
160
|
value: value.toLowerCase()
|
|
162
161
|
};
|
|
163
162
|
}
|
|
164
|
-
|
|
165
|
-
//#region src/schema-check.ts
|
|
163
|
+
// src/schema-check.ts
|
|
166
164
|
/**
|
|
167
165
|
* Converts Kysely table metadata into the shape `diffSchema` compares.
|
|
168
166
|
*/
|
|
@@ -236,6 +234,60 @@ async function getMssqlSchema(db) {
|
|
|
236
234
|
SELECT SCHEMA_NAME() AS "schemaName"
|
|
237
235
|
`.execute(db.withoutPlugins())).rows[0]?.schemaName || "dbo";
|
|
238
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Reads the tables in `schemas` with the metadata Kysely's PostgreSQL
|
|
239
|
+
* introspector reports. That introspector reads every schema and resolves
|
|
240
|
+
* each one by name, so a schema another connection drops during the read
|
|
241
|
+
* fails it with "schema does not exist" or "relation does not exist".
|
|
242
|
+
*/
|
|
243
|
+
async function introspectPostgresTables(db, schemas) {
|
|
244
|
+
if (schemas.length === 0) return [];
|
|
245
|
+
const { rows } = await sql`
|
|
246
|
+
SELECT
|
|
247
|
+
ns.nspname AS "schema",
|
|
248
|
+
c.relname AS "table",
|
|
249
|
+
c.relkind = 'v' AS "isView",
|
|
250
|
+
c.relkind = 'f' AS "isForeign",
|
|
251
|
+
a.attname AS "column",
|
|
252
|
+
typ.typname AS "dataType",
|
|
253
|
+
NOT a.attnotnull AS "isNullable",
|
|
254
|
+
a.atthasdef AS "hasDefaultValue",
|
|
255
|
+
pg_catalog.pg_get_serial_sequence(
|
|
256
|
+
pg_catalog.quote_ident(ns.nspname) || '.' || pg_catalog.quote_ident(c.relname),
|
|
257
|
+
a.attname
|
|
258
|
+
) IS NOT NULL AS "isAutoIncrementing"
|
|
259
|
+
FROM pg_catalog.pg_attribute AS a
|
|
260
|
+
INNER JOIN pg_catalog.pg_class AS c ON c.oid = a.attrelid
|
|
261
|
+
INNER JOIN pg_catalog.pg_namespace AS ns ON ns.oid = c.relnamespace
|
|
262
|
+
INNER JOIN pg_catalog.pg_type AS typ ON typ.oid = a.atttypid
|
|
263
|
+
WHERE ns.nspname IN (${sql.join(schemas)})
|
|
264
|
+
AND ns.nspname !~ '^pg_'
|
|
265
|
+
AND pg_catalog.has_schema_privilege(ns.oid, 'USAGE')
|
|
266
|
+
AND c.relkind IN ('r', 'v', 'p', 'f')
|
|
267
|
+
AND a.attnum >= 0
|
|
268
|
+
AND NOT a.attisdropped
|
|
269
|
+
ORDER BY ns.nspname, c.relname, a.attnum
|
|
270
|
+
`.execute(db.withoutPlugins());
|
|
271
|
+
const tables = [];
|
|
272
|
+
let current;
|
|
273
|
+
for (const { schema, table, isView, isForeign, column, ...metadata } of rows) {
|
|
274
|
+
if (current?.schema !== schema || current.name !== table) {
|
|
275
|
+
current = {
|
|
276
|
+
name: table,
|
|
277
|
+
schema,
|
|
278
|
+
isView,
|
|
279
|
+
isForeign,
|
|
280
|
+
columns: []
|
|
281
|
+
};
|
|
282
|
+
tables.push(current);
|
|
283
|
+
}
|
|
284
|
+
current.columns.push({
|
|
285
|
+
name: column,
|
|
286
|
+
...metadata
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
return tables;
|
|
290
|
+
}
|
|
239
291
|
async function schemaSearchPath(db, dbType) {
|
|
240
292
|
if (dbType === "postgres") return (await sql`
|
|
241
293
|
SELECT pg_catalog.current_schemas(true)::text[] AS schemas
|
|
@@ -250,10 +302,14 @@ async function schemaSearchPath(db, dbType) {
|
|
|
250
302
|
*/
|
|
251
303
|
async function findSchemaProblems(db, dbType, expected) {
|
|
252
304
|
const physical = toPhysicalSchema(db, expected);
|
|
253
|
-
if (dbType === "sqlite")
|
|
305
|
+
if (dbType === "sqlite") {
|
|
306
|
+
const tableNames = Object.entries(physical).flatMap(([name, table]) => table.disableMigrations ? [] : [name]);
|
|
307
|
+
const tables = await introspectSqliteTables(db, tableNames);
|
|
308
|
+
return diffSchema(physical, toIntrospectedTables(tables));
|
|
309
|
+
}
|
|
254
310
|
return db.connection().execute(async (connection) => {
|
|
255
311
|
const searchPath = await schemaSearchPath(connection, dbType);
|
|
256
|
-
const tables = toIntrospectedTables(await connection.introspection.getTables());
|
|
312
|
+
const tables = toIntrospectedTables(dbType === "postgres" ? await introspectPostgresTables(connection, [...searchPath ?? [], ...Object.values(physical).flatMap(({ schema }) => schema ?? [])]) : await connection.introspection.getTables());
|
|
257
313
|
for (const [name, table] of Object.entries(physical)) {
|
|
258
314
|
if (table.schema !== void 0 || !searchPath) continue;
|
|
259
315
|
table.schema = searchPath.find((schema) => tables.some((candidate) => candidate.name === name && candidate.schema === schema)) ?? "";
|
|
@@ -261,8 +317,7 @@ async function findSchemaProblems(db, dbType, expected) {
|
|
|
261
317
|
return diffSchema(physical, tables);
|
|
262
318
|
});
|
|
263
319
|
}
|
|
264
|
-
|
|
265
|
-
//#region src/kysely-adapter.ts
|
|
320
|
+
// src/kysely-adapter.ts
|
|
266
321
|
const kyselyAdapter = (db, config) => {
|
|
267
322
|
let lazyOptions = null;
|
|
268
323
|
let mysqlNoIdWarned = false;
|
|
@@ -294,6 +349,23 @@ const kyselyAdapter = (db, config) => {
|
|
|
294
349
|
allSelects
|
|
295
350
|
};
|
|
296
351
|
};
|
|
352
|
+
const encodeJSONArrays = (modelKey, values) => {
|
|
353
|
+
if (config?.type !== "postgres") return values;
|
|
354
|
+
const fields = schema[getDefaultModelName(modelKey)]?.fields;
|
|
355
|
+
if (!fields) return values;
|
|
356
|
+
let encoded;
|
|
357
|
+
for (const [field, attributes] of Object.entries(fields)) {
|
|
358
|
+
if (attributes.type !== "json") continue;
|
|
359
|
+
const column = getFieldName({
|
|
360
|
+
model: modelKey,
|
|
361
|
+
field
|
|
362
|
+
});
|
|
363
|
+
if (!Array.isArray(values[column])) continue;
|
|
364
|
+
encoded ??= { ...values };
|
|
365
|
+
encoded[column] = JSON.stringify(values[column]);
|
|
366
|
+
}
|
|
367
|
+
return encoded ?? values;
|
|
368
|
+
};
|
|
297
369
|
const withReturning = async (values, builder, model, modelKey, where) => {
|
|
298
370
|
if (config?.type === "mysql") {
|
|
299
371
|
if (where.length > 0) {
|
|
@@ -317,18 +389,18 @@ const kyselyAdapter = (db, config) => {
|
|
|
317
389
|
field: reselectField
|
|
318
390
|
}), reselectValue === null ? "is" : "=", reselectValue).limit(1).executeTakeFirst();
|
|
319
391
|
}
|
|
320
|
-
await builder.execute();
|
|
321
392
|
const fetchInserted = async (trx) => {
|
|
393
|
+
const insertId = (await trx.executeQuery(builder)).insertId;
|
|
322
394
|
if (values.id) return await trx.selectFrom(model).selectAll().where(getFieldName({
|
|
323
395
|
model: modelKey,
|
|
324
396
|
field: "id"
|
|
325
397
|
}), "=", values.id).limit(1).executeTakeFirst();
|
|
326
398
|
if (options.advanced?.database?.generateId === "serial") {
|
|
327
|
-
|
|
328
|
-
|
|
399
|
+
if (insertId === void 0) throw new BetterAuthError(`[Kysely Adapter] MySQL did not report an auto-increment id for the inserted "${model}" row. With generateId: "serial" the "id" column must be AUTO_INCREMENT.`);
|
|
400
|
+
return await trx.selectFrom(model).selectAll().where(getFieldName({
|
|
329
401
|
model: modelKey,
|
|
330
402
|
field: "id"
|
|
331
|
-
}), "=",
|
|
403
|
+
}), "=", insertId <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(insertId) : insertId.toString()).limit(1).executeTakeFirst();
|
|
332
404
|
}
|
|
333
405
|
const modelSchema = schema[modelKey]?.fields;
|
|
334
406
|
if (modelSchema) for (const [fieldKey, fieldAttr] of Object.entries(modelSchema)) {
|
|
@@ -498,7 +570,8 @@ const kyselyAdapter = (db, config) => {
|
|
|
498
570
|
}
|
|
499
571
|
return {
|
|
500
572
|
async create({ data, model, modelKey = model }) {
|
|
501
|
-
|
|
573
|
+
const builder = db.insertInto(model).values(encodeJSONArrays(modelKey, data));
|
|
574
|
+
return await withReturning(data, builder, model, modelKey, []);
|
|
502
575
|
},
|
|
503
576
|
async findOne({ model, modelKey = model, where, select, join }) {
|
|
504
577
|
const { and, or } = convertWhereClause(model, modelKey, where);
|
|
@@ -572,14 +645,14 @@ const kyselyAdapter = (db, config) => {
|
|
|
572
645
|
async update({ model, modelKey = model, where, update: values }) {
|
|
573
646
|
if (where.length === 0) return null;
|
|
574
647
|
const { and, or } = convertWhereClause(model, modelKey, where);
|
|
575
|
-
let query = db.updateTable(model).set(values);
|
|
648
|
+
let query = db.updateTable(model).set(encodeJSONArrays(modelKey, values));
|
|
576
649
|
if (and) query = query.where((eb) => eb.and(and.map((expr) => expr(eb))));
|
|
577
650
|
if (or) query = query.where((eb) => eb.or(or.map((expr) => expr(eb))));
|
|
578
651
|
return await withReturning(values, query, model, modelKey, where);
|
|
579
652
|
},
|
|
580
653
|
async updateMany({ model, modelKey = model, where, update: values }) {
|
|
581
654
|
const { and, or } = convertWhereClause(model, modelKey, where);
|
|
582
|
-
let query = db.updateTable(model).set(values);
|
|
655
|
+
let query = db.updateTable(model).set(encodeJSONArrays(modelKey, values));
|
|
583
656
|
if (and) query = query.where((eb) => eb.and(and.map((expr) => expr(eb))));
|
|
584
657
|
if (or) query = query.where((eb) => eb.or(or.map((expr) => expr(eb))));
|
|
585
658
|
const res = (await query.executeTakeFirst()).numUpdatedRows;
|
|
@@ -655,7 +728,7 @@ const kyselyAdapter = (db, config) => {
|
|
|
655
728
|
if (or) query = query.where((eb) => eb.or(or.map((expr) => expr(eb))));
|
|
656
729
|
return query;
|
|
657
730
|
};
|
|
658
|
-
const assignments = { ...set ?? {} };
|
|
731
|
+
const assignments = { ...encodeJSONArrays(modelKey, set ?? {}) };
|
|
659
732
|
for (const [field, delta] of Object.entries(increment)) assignments[field] = sql`${sql.ref(field)} + ${delta}`;
|
|
660
733
|
const idField = getFieldName({
|
|
661
734
|
model: modelKey,
|
|
@@ -711,9 +784,9 @@ const kyselyAdapter = (db, config) => {
|
|
|
711
784
|
return (options) => {
|
|
712
785
|
lazyOptions = options;
|
|
713
786
|
const instance = adapter(options);
|
|
714
|
-
|
|
787
|
+
const schemaCheck = createSchemaCheck(() => findSchemaProblems(db, config?.type, getExpectedSchema(options, { usePlural: config?.usePlural })), "database", options.database);
|
|
788
|
+
registerSchemaCheck(instance, schemaCheck, { runtimeEnabled: checksSchema(options) });
|
|
715
789
|
return instance;
|
|
716
790
|
};
|
|
717
791
|
};
|
|
718
|
-
|
|
719
|
-
export { createKyselyAdapter, getKyselyDatabaseType, getMssqlSchema, getPostgresSchema, kyselyAdapter, toIntrospectedTables, toPhysicalSchema };
|
|
792
|
+
export { createKyselyAdapter, getKyselyDatabaseType, getMssqlSchema, getPostgresSchema, introspectPostgresTables, kyselyAdapter, toIntrospectedTables, toPhysicalSchema };
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { DatabaseConnection, DatabaseIntrospector, Dialect, DialectAdapter, Driver, Kysely, QueryCompiler } from "kysely";
|
|
2
2
|
import { DatabaseSync } from "node:sqlite";
|
|
3
|
-
|
|
4
|
-
//#region src/node-sqlite-dialect.d.ts
|
|
5
3
|
/**
|
|
6
4
|
* Config for the SQLite dialect.
|
|
7
5
|
*/
|
|
8
|
-
interface NodeSqliteDialectConfig {
|
|
6
|
+
export interface NodeSqliteDialectConfig {
|
|
9
7
|
/**
|
|
10
8
|
* A sqlite DatabaseSync instance or a function that returns one.
|
|
11
9
|
*/
|
|
@@ -15,13 +13,11 @@ interface NodeSqliteDialectConfig {
|
|
|
15
13
|
*/
|
|
16
14
|
onCreateConnection?: ((connection: DatabaseConnection) => Promise<void>) | undefined;
|
|
17
15
|
}
|
|
18
|
-
declare class NodeSqliteDialect implements Dialect {
|
|
16
|
+
export declare class NodeSqliteDialect implements Dialect {
|
|
19
17
|
#private;
|
|
20
18
|
constructor(config: NodeSqliteDialectConfig);
|
|
21
19
|
createDriver(): Driver;
|
|
22
20
|
createQueryCompiler(): QueryCompiler;
|
|
23
21
|
createAdapter(): DialectAdapter;
|
|
24
22
|
createIntrospector(db: Kysely<any>): DatabaseIntrospector;
|
|
25
|
-
}
|
|
26
|
-
//#endregion
|
|
27
|
-
export { NodeSqliteDialect, NodeSqliteDialectConfig };
|
|
23
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as createSqliteIntrospector } from "./sqlite-introspector-
|
|
1
|
+
import { t as createSqliteIntrospector } from "./sqlite-introspector-DeY-XxNH.mjs";
|
|
2
2
|
import { CompiledQuery, DefaultQueryCompiler } from "kysely";
|
|
3
|
-
|
|
3
|
+
// src/node-sqlite-dialect.ts
|
|
4
4
|
var NodeSqliteAdapter = class {
|
|
5
5
|
get supportsCreateIfNotExists() {
|
|
6
6
|
return true;
|
|
@@ -119,5 +119,4 @@ var NodeSqliteDialect = class {
|
|
|
119
119
|
return createSqliteIntrospector(db);
|
|
120
120
|
}
|
|
121
121
|
};
|
|
122
|
-
//#endregion
|
|
123
122
|
export { NodeSqliteDialect };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { sql } from "kysely";
|
|
2
|
-
|
|
2
|
+
// src/kysely-migration-tables.ts
|
|
3
3
|
/**
|
|
4
4
|
* Kysely's internal migration table names, mirrored as local constants.
|
|
5
5
|
*
|
|
@@ -14,8 +14,7 @@ import { sql } from "kysely";
|
|
|
14
14
|
*/
|
|
15
15
|
const DEFAULT_MIGRATION_TABLE = "kysely_migration";
|
|
16
16
|
const DEFAULT_MIGRATION_LOCK_TABLE = "kysely_migration_lock";
|
|
17
|
-
|
|
18
|
-
//#region src/sqlite-introspector.ts
|
|
17
|
+
// src/sqlite-introspector.ts
|
|
19
18
|
function sqliteIntegerPrimaryKeyColumn(columns) {
|
|
20
19
|
const primaryKeys = columns.filter((column) => column.pk > 0);
|
|
21
20
|
const primaryKey = primaryKeys.length === 1 ? primaryKeys[0] : void 0;
|
|
@@ -86,5 +85,4 @@ function createSqliteIntrospector(db) {
|
|
|
86
85
|
getMetadata: async (options) => ({ tables: await getTables(options) })
|
|
87
86
|
};
|
|
88
87
|
}
|
|
89
|
-
//#endregion
|
|
90
88
|
export { DEFAULT_MIGRATION_LOCK_TABLE as a, toSqliteTableMetadata as i, introspectSqliteTables as n, DEFAULT_MIGRATION_TABLE as o, sqliteIntegerPrimaryKeyColumn as r, createSqliteIntrospector as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/kysely-adapter",
|
|
3
|
-
"version": "1.8.0-beta.
|
|
3
|
+
"version": "1.8.0-beta.11",
|
|
4
4
|
"description": "Kysely adapter for Better Auth",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
+
"@better-auth/core": "^1.8.0-beta.11",
|
|
43
44
|
"@better-auth/utils": "^0.4.2 || ^0.5.0",
|
|
44
|
-
"kysely": "^0.28.17 || ^0.29.0"
|
|
45
|
-
"@better-auth/core": "^1.8.0-beta.1"
|
|
45
|
+
"kysely": "^0.28.17 || ^0.29.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependenciesMeta": {
|
|
48
48
|
"kysely": {
|
|
@@ -50,14 +50,14 @@
|
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@better-auth/
|
|
53
|
+
"@better-auth/core": "1.8.0-beta.11",
|
|
54
|
+
"@better-auth/utils": "0.5.1",
|
|
54
55
|
"@cloudflare/workers-types": "^4.20250121.0",
|
|
55
56
|
"@types/pg": "^8.20.0",
|
|
56
57
|
"kysely": "^0.28.17 || ^0.29.0",
|
|
57
58
|
"pg": "^8.0.0",
|
|
58
|
-
"tsdown": "0.
|
|
59
|
-
"typescript": "^6.0.3"
|
|
60
|
-
"@better-auth/core": "1.8.0-beta.1"
|
|
59
|
+
"tsdown": "0.23.1",
|
|
60
|
+
"typescript": "^6.0.3"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "tsdown",
|