mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
30 lines
830 B
TypeScript
30 lines
830 B
TypeScript
import { assertExists } from '@blocksuite/global/utils';
|
|
import type { BlobStorage } from '@blocksuite/store';
|
|
|
|
export const createSQLiteStorage = (workspaceId: string): BlobStorage => {
|
|
const apis = window.apis;
|
|
assertExists(apis);
|
|
return {
|
|
crud: {
|
|
get: async (key: string) => {
|
|
const buffer = await apis.db.getBlob(workspaceId, key);
|
|
return buffer ? new Blob([buffer]) : null;
|
|
},
|
|
set: async (key: string, value: Blob) => {
|
|
await apis.db.addBlob(
|
|
workspaceId,
|
|
key,
|
|
new Uint8Array(await value.arrayBuffer())
|
|
);
|
|
return key;
|
|
},
|
|
delete: async (key: string) => {
|
|
return apis.db.deleteBlob(workspaceId, key);
|
|
},
|
|
list: async () => {
|
|
return apis.db.getBlobKeys(workspaceId);
|
|
},
|
|
},
|
|
};
|
|
};
|