mirror of
https://github.com/bknd-io/bknd.git
synced 2026-10-22 22:35:10 +00:00
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();
|
|
});
|
|
});
|