mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
connection: rewrote query execution, batching, added generic sqlite, added node/bun sqlite, aligned repo/mutator results
This commit is contained in:
@@ -1,16 +1,49 @@
|
||||
import type { ColumnDataType, ColumnDefinitionBuilder, Kysely, KyselyPlugin } from "kysely";
|
||||
import {
|
||||
ParseJSONResultsPlugin,
|
||||
type ColumnDataType,
|
||||
type ColumnDefinitionBuilder,
|
||||
type Dialect,
|
||||
Kysely,
|
||||
type KyselyPlugin,
|
||||
} from "kysely";
|
||||
import { jsonArrayFrom, jsonBuildObject, jsonObjectFrom } from "kysely/helpers/sqlite";
|
||||
import { Connection, type DbFunctions, type FieldSpec, type SchemaResponse } from "../Connection";
|
||||
import type { Constructor } from "core";
|
||||
import { customIntrospector } from "../Connection";
|
||||
import { SqliteIntrospector } from "./SqliteIntrospector";
|
||||
|
||||
export type SqliteConnectionConfig<
|
||||
CustomDialect extends Constructor<Dialect> = Constructor<Dialect>,
|
||||
> = {
|
||||
excludeTables?: string[];
|
||||
dialect: CustomDialect;
|
||||
dialectArgs?: ConstructorParameters<CustomDialect>;
|
||||
additionalPlugins?: KyselyPlugin[];
|
||||
customFn?: Partial<DbFunctions>;
|
||||
};
|
||||
|
||||
export abstract class SqliteConnection<Client = unknown> extends Connection<Client> {
|
||||
override name = "sqlite";
|
||||
|
||||
constructor(config: SqliteConnectionConfig) {
|
||||
const { excludeTables, dialect, dialectArgs = [], additionalPlugins } = config;
|
||||
const plugins = [new ParseJSONResultsPlugin(), ...(additionalPlugins ?? [])];
|
||||
|
||||
const kysely = new Kysely({
|
||||
dialect: customIntrospector(dialect, SqliteIntrospector, {
|
||||
excludeTables,
|
||||
plugins,
|
||||
}).create(...dialectArgs),
|
||||
plugins,
|
||||
});
|
||||
|
||||
export class SqliteConnection extends Connection {
|
||||
constructor(kysely: Kysely<any>, fn: Partial<DbFunctions> = {}, plugins: KyselyPlugin[] = []) {
|
||||
super(
|
||||
kysely,
|
||||
{
|
||||
...fn,
|
||||
jsonArrayFrom,
|
||||
jsonObjectFrom,
|
||||
jsonBuildObject,
|
||||
...(config.customFn ?? {}),
|
||||
},
|
||||
plugins,
|
||||
);
|
||||
@@ -43,7 +76,7 @@ export class SqliteConnection extends Connection {
|
||||
if (spec.onUpdate) relCol = relCol.onUpdate(spec.onUpdate);
|
||||
return relCol;
|
||||
}
|
||||
return spec.nullable ? col : col.notNull();
|
||||
return col;
|
||||
},
|
||||
] as const;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user