mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-25 02:13:00 +08:00
feat(core): user data db (#7930)
This commit is contained in:
@@ -57,16 +57,16 @@ test('can get a valid WorkspaceSQLiteDB', async () => {
|
||||
'@affine/electron/helper/db/ensure-db'
|
||||
);
|
||||
const workspaceId = v4();
|
||||
const db0 = await ensureSQLiteDB(workspaceId);
|
||||
const db0 = await ensureSQLiteDB('workspace', workspaceId);
|
||||
expect(db0).toBeDefined();
|
||||
expect(db0.workspaceId).toBe(workspaceId);
|
||||
|
||||
const db1 = await ensureSQLiteDB(v4());
|
||||
const db1 = await ensureSQLiteDB('workspace', v4());
|
||||
expect(db1).not.toBe(db0);
|
||||
expect(db1.workspaceId).not.toBe(db0.workspaceId);
|
||||
|
||||
// ensure that the db is cached
|
||||
expect(await ensureSQLiteDB(workspaceId)).toBe(db0);
|
||||
expect(await ensureSQLiteDB('workspace', workspaceId)).toBe(db0);
|
||||
});
|
||||
|
||||
test('db should be destroyed when app quits', async () => {
|
||||
@@ -74,8 +74,8 @@ test('db should be destroyed when app quits', async () => {
|
||||
'@affine/electron/helper/db/ensure-db'
|
||||
);
|
||||
const workspaceId = v4();
|
||||
const db0 = await ensureSQLiteDB(workspaceId);
|
||||
const db1 = await ensureSQLiteDB(v4());
|
||||
const db0 = await ensureSQLiteDB('workspace', workspaceId);
|
||||
const db1 = await ensureSQLiteDB('workspace', v4());
|
||||
|
||||
expect(db0.adapter).not.toBeNull();
|
||||
expect(db1.adapter).not.toBeNull();
|
||||
@@ -94,8 +94,8 @@ test('db should be removed in db$Map after destroyed', async () => {
|
||||
'@affine/electron/helper/db/ensure-db'
|
||||
);
|
||||
const workspaceId = v4();
|
||||
const db = await ensureSQLiteDB(workspaceId);
|
||||
const db = await ensureSQLiteDB('workspace', workspaceId);
|
||||
await db.destroy();
|
||||
await setTimeout(100);
|
||||
expect(db$Map.has(workspaceId)).toBe(false);
|
||||
expect(db$Map.has(`workspace:${workspaceId}`)).toBe(false);
|
||||
});
|
||||
|
||||
@@ -29,7 +29,7 @@ test('can create new db file if not exists', async () => {
|
||||
'@affine/electron/helper/db/workspace-db-adapter'
|
||||
);
|
||||
const workspaceId = v4();
|
||||
const db = await openWorkspaceDatabase(workspaceId);
|
||||
const db = await openWorkspaceDatabase('workspace', workspaceId);
|
||||
const dbPath = path.join(
|
||||
appDataPath,
|
||||
`workspaces/${workspaceId}`,
|
||||
@@ -44,7 +44,7 @@ test('on destroy, check if resources have been released', async () => {
|
||||
'@affine/electron/helper/db/workspace-db-adapter'
|
||||
);
|
||||
const workspaceId = v4();
|
||||
const db = await openWorkspaceDatabase(workspaceId);
|
||||
const db = await openWorkspaceDatabase('workspace', workspaceId);
|
||||
const updateSub = {
|
||||
complete: vi.fn(),
|
||||
next: vi.fn(),
|
||||
|
||||
Reference in New Issue
Block a user