mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
feat: store local data to local db (#2037)
This commit is contained in:
25
packages/workspace/src/blob/sqlite-blob-storage.ts
Normal file
25
packages/workspace/src/blob/sqlite-blob-storage.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import type { BlobStorage } from '@blocksuite/store';
|
||||
|
||||
export const createSQLiteStorage = (workspaceId: string): BlobStorage => {
|
||||
return {
|
||||
crud: {
|
||||
get: async (key: string) => {
|
||||
const buffer = await window.apis.db.getBlob(workspaceId, key);
|
||||
return buffer ? new Blob([buffer]) : null;
|
||||
},
|
||||
set: async (key: string, value: Blob) => {
|
||||
return window.apis.db.addBlob(
|
||||
workspaceId,
|
||||
key,
|
||||
new Uint8Array(await value.arrayBuffer())
|
||||
);
|
||||
},
|
||||
delete: async (key: string) => {
|
||||
return window.apis.db.deleteBlob(workspaceId, key);
|
||||
},
|
||||
list: async () => {
|
||||
return window.apis.db.getPersistedBlobs(workspaceId);
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user