-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
40 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,47 @@ | ||
import { createDatabase } from "db0"; | ||
import libSql from "db0/connectors/libsql/node"; | ||
import pglite from "db0/connectors/pglite"; | ||
import { afterAll, describe, expect } from "vitest"; | ||
import { createDatabase } from "db0"; | ||
import db0Driver from "../../src/drivers/db0"; | ||
import { testDriver } from "./utils"; | ||
|
||
describe("drivers: db0 - LibSQL", () => { | ||
const db = createDatabase( | ||
libSql({ | ||
url: ":memory:", | ||
}) | ||
); | ||
|
||
afterAll(async () => { | ||
await db.sql`DROP TABLE IF EXISTS unstorage`; | ||
}); | ||
|
||
testDriver({ | ||
driver: db0Driver({ database: db }), | ||
additionalTests: async (ctx) => { | ||
await ctx.storage.setItem("meta:test", "test_data"); | ||
|
||
expect(await ctx.storage.getMeta("meta:test")).toMatchObject({ | ||
birthtime: expect.any(Date), | ||
mtime: expect.any(Date), | ||
}); | ||
const drivers = [ | ||
{ | ||
name: "libsql", | ||
async getDB() { | ||
const libSQL = await import("db0/connectors/libsql/node").then( | ||
(m) => m.default | ||
); | ||
return createDatabase(libSQL({ url: ":memory:" })); | ||
}, | ||
}); | ||
}); | ||
|
||
describe("drivers: db0 - PGlite", async () => { | ||
const db = createDatabase(pglite()); | ||
|
||
afterAll(async () => { | ||
await db.sql`DROP TABLE IF EXISTS custom_unstorage_table`; | ||
}); | ||
|
||
testDriver({ | ||
driver: db0Driver({ | ||
database: db, | ||
table: "custom_unstorage_table", | ||
}), | ||
additionalTests: async (ctx) => { | ||
await ctx.storage.setItem("meta:test", "test_data"); | ||
|
||
expect(await ctx.storage.getMeta("meta:test")).toMatchObject({ | ||
birthtime: expect.any(Date), | ||
mtime: expect.any(Date), | ||
}); | ||
}, | ||
{ | ||
name: "pglite", | ||
async getDB() { | ||
const pglite = await import("db0/connectors/pglite").then( | ||
(m) => m.default | ||
); | ||
return createDatabase(pglite()); | ||
}, | ||
}, | ||
]; | ||
|
||
for (const driver of drivers) { | ||
describe(`drivers: db0 - ${driver.name}`, async () => { | ||
const db = await driver.getDB(); | ||
|
||
afterAll(async () => { | ||
await db.sql`DROP TABLE IF EXISTS unstorage`; | ||
}); | ||
|
||
testDriver({ | ||
driver: db0Driver({ database: db }), | ||
additionalTests: async (ctx) => { | ||
await ctx.storage.setItem("meta:test", "test_data"); | ||
|
||
expect(await ctx.storage.getMeta("meta:test")).toMatchObject({ | ||
birthtime: expect.any(Date), | ||
mtime: expect.any(Date), | ||
}); | ||
}, | ||
}); | ||
}); | ||
}); | ||
} |