various fixes: refactored imports, introduced fromDriver/toDriver to improve compat

This commit is contained in:
dswbx
2025-06-13 21:15:29 +02:00
parent cc038a0a9a
commit 2ada4e9f20
15 changed files with 100 additions and 35 deletions

View File

@@ -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;
}
}