mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-19 05:46:04 +00:00
various fixes: refactored imports, introduced fromDriver/toDriver to improve compat
This commit is contained in:
@@ -20,6 +20,7 @@ import {
|
||||
import type { BaseIntrospector, BaseIntrospectorConfig } from "./BaseIntrospector";
|
||||
import type { Constructor, DB } from "core";
|
||||
import { KyselyPluginRunner } from "data/plugins/KyselyPluginRunner";
|
||||
import type { Field } from "data/fields/Field";
|
||||
|
||||
export type QB = SelectQueryBuilder<any, any, any>;
|
||||
|
||||
@@ -200,6 +201,14 @@ export abstract class Connection<Client = unknown> {
|
||||
|
||||
abstract getFieldSchema(spec: FieldSpec, strict?: boolean): SchemaResponse;
|
||||
|
||||
toDriver(value: unknown, field: Field): unknown {
|
||||
return value;
|
||||
}
|
||||
|
||||
fromDriver(value: any, field: Field): unknown {
|
||||
return value;
|
||||
}
|
||||
|
||||
async close(): Promise<void> {
|
||||
// no-op by default
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { TestRunner } from "core/test";
|
||||
import { Connection, type FieldSpec } from "./Connection";
|
||||
|
||||
// @todo: add various datatypes: string, number, boolean, object, array, null, undefined, date, etc.
|
||||
|
||||
export function connectionTestSuite(
|
||||
testRunner: TestRunner,
|
||||
{
|
||||
|
||||
@@ -57,6 +57,6 @@ export class LibsqlConnection extends SqliteConnection<Client> {
|
||||
}
|
||||
}
|
||||
|
||||
export function libsql(credentials: LibSqlCredentials): LibsqlConnection {
|
||||
export function libsql(credentials: Client | LibSqlCredentials): LibsqlConnection {
|
||||
return new LibsqlConnection(credentials);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,9 @@ import { Connection, type DbFunctions, type FieldSpec, type SchemaResponse } fro
|
||||
import type { Constructor } from "core";
|
||||
import { customIntrospector } from "../Connection";
|
||||
import { SqliteIntrospector } from "./SqliteIntrospector";
|
||||
import type { Field } from "data/fields/Field";
|
||||
|
||||
// @todo: add pragmas
|
||||
export type SqliteConnectionConfig<
|
||||
CustomDialect extends Constructor<Dialect> = Constructor<Dialect>,
|
||||
> = {
|
||||
@@ -80,4 +82,24 @@ export abstract class SqliteConnection<Client = unknown> extends Connection<Clie
|
||||
},
|
||||
] as const;
|
||||
}
|
||||
|
||||
override toDriver(value: unknown, field: Field): unknown {
|
||||
if (field.type === "boolean") {
|
||||
return value ? 1 : 0;
|
||||
}
|
||||
if (typeof value === "undefined") {
|
||||
return null;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
override fromDriver(value: any, field: Field): unknown {
|
||||
if (field.type === "boolean" && typeof value === "number") {
|
||||
return value === 1;
|
||||
}
|
||||
if (value === null) {
|
||||
return undefined;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user