mirror of
https://github.com/bknd-io/bknd/
synced 2026-08-02 08:06:00 +00:00
36e61cab3f
Updated the Bun and Node SQLite connection implementations to support additional configuration options, including `onCreateConnection`. Introduced tests for connection creation to validate database instance types and ensure proper callback execution. Improved type exports for better integration with existing code.
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { nodeSqlite } from "./NodeSqliteConnection";
|
|
import { DatabaseSync } from "node:sqlite";
|
|
import { connectionTestSuite } from "data/connection/connection-test-suite";
|
|
import { describe, beforeAll, afterAll, test, expect, vi } from "vitest";
|
|
import { viTestRunner } from "../vitest";
|
|
import { disableConsoleLog, enableConsoleLog } from "core/utils/test";
|
|
import { GenericSqliteConnection } from "data/connection/sqlite/GenericSqliteConnection";
|
|
|
|
beforeAll(() => disableConsoleLog());
|
|
afterAll(() => enableConsoleLog());
|
|
|
|
describe("NodeSqliteConnection", () => {
|
|
connectionTestSuite(viTestRunner, {
|
|
makeConnection: () => ({
|
|
connection: nodeSqlite({ database: new DatabaseSync(":memory:") }),
|
|
dispose: async () => {},
|
|
}),
|
|
rawDialectDetails: [],
|
|
});
|
|
|
|
test("onCreateConnection", async () => {
|
|
const called = vi.fn(() => null);
|
|
|
|
const conn = nodeSqlite({
|
|
onCreateConnection: (db) => {
|
|
expect(db).toBeInstanceOf(DatabaseSync);
|
|
called();
|
|
},
|
|
});
|
|
await conn.ping();
|
|
|
|
expect(conn).toBeInstanceOf(GenericSqliteConnection);
|
|
expect(conn.db).toBeInstanceOf(DatabaseSync);
|
|
expect(called).toHaveBeenCalledOnce();
|
|
});
|
|
});
|