mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
finalized sqlocal, added BkndBrowserApp, updated react example
This commit is contained in:
@@ -6,15 +6,12 @@ import {
|
||||
type CompiledQuery,
|
||||
type DatabaseIntrospector,
|
||||
type Dialect,
|
||||
type Expression,
|
||||
type Kysely,
|
||||
type KyselyPlugin,
|
||||
type OnModifyForeignAction,
|
||||
type QueryResult,
|
||||
type RawBuilder,
|
||||
type SelectQueryBuilder,
|
||||
type SelectQueryNode,
|
||||
type Simplify,
|
||||
sql,
|
||||
} from "kysely";
|
||||
import type { jsonArrayFrom, jsonBuildObject, jsonObjectFrom } from "kysely/helpers/sqlite";
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
export { pg, PgPostgresConnection, type PgPostgresConnectionConfig } from "./PgPostgresConnection";
|
||||
export { PostgresIntrospector } from "./PostgresIntrospector";
|
||||
export { PostgresConnection, type QB, plugins } from "./PostgresConnection";
|
||||
export { postgresJs, PostgresJsConnection, type PostgresJsConfig } from "./PostgresJsConnection";
|
||||
export { createCustomPostgresConnection } from "./custom";
|
||||
48
app/src/data/connection/sqlite/sqlocal/SQLocalConnection.ts
Normal file
48
app/src/data/connection/sqlite/sqlocal/SQLocalConnection.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { Kysely, ParseJSONResultsPlugin } from "kysely";
|
||||
import { SqliteConnection, SqliteIntrospector, type DB } from "bknd";
|
||||
import type { SQLocalKysely } from "sqlocal/kysely";
|
||||
|
||||
const plugins = [new ParseJSONResultsPlugin()];
|
||||
|
||||
export class SQLocalConnection extends SqliteConnection<SQLocalKysely> {
|
||||
private connected: boolean = false;
|
||||
|
||||
constructor(client: SQLocalKysely) {
|
||||
// @ts-expect-error - config is protected
|
||||
client.config.onConnect = () => {
|
||||
// we need to listen for the connection, it will be awaited in init()
|
||||
this.connected = true;
|
||||
};
|
||||
super({
|
||||
kysely: new Kysely<any>({
|
||||
dialect: {
|
||||
...client.dialect,
|
||||
createIntrospector: (db: Kysely<DB>) => {
|
||||
return new SqliteIntrospector(db as any, {
|
||||
plugins,
|
||||
});
|
||||
},
|
||||
},
|
||||
plugins,
|
||||
}) as any,
|
||||
});
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
override async init() {
|
||||
if (this.initialized) return;
|
||||
let tries = 0;
|
||||
while (!this.connected && tries < 100) {
|
||||
tries++;
|
||||
await new Promise((resolve) => setTimeout(resolve, 5));
|
||||
}
|
||||
if (!this.connected) {
|
||||
throw new Error("Failed to connect to SQLite database");
|
||||
}
|
||||
this.initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
export function sqlocal(instance: InstanceType<typeof SQLocalKysely>): SQLocalConnection {
|
||||
return new SQLocalConnection(instance);
|
||||
}
|
||||
Reference in New Issue
Block a user