mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-22 12:36:24 +08:00
39 lines
933 B
TypeScript
39 lines
933 B
TypeScript
import { share } from '../../connection';
|
|
import { type BlobRecord, BlobStorageBase } from '../../storage';
|
|
import { NativeDBConnection, type SqliteNativeDBOptions } from './db';
|
|
|
|
export class SqliteBlobStorage extends BlobStorageBase {
|
|
static readonly identifier = 'SqliteBlobStorage';
|
|
override readonly isReadonly = false;
|
|
|
|
override connection = share(new NativeDBConnection(this.options));
|
|
|
|
constructor(private readonly options: SqliteNativeDBOptions) {
|
|
super();
|
|
}
|
|
|
|
get db() {
|
|
return this.connection.apis;
|
|
}
|
|
|
|
override async get(key: string) {
|
|
return this.db.getBlob(key);
|
|
}
|
|
|
|
override async set(blob: BlobRecord) {
|
|
await this.db.setBlob(blob);
|
|
}
|
|
|
|
override async delete(key: string, permanently: boolean) {
|
|
await this.db.deleteBlob(key, permanently);
|
|
}
|
|
|
|
override async release() {
|
|
await this.db.releaseBlobs();
|
|
}
|
|
|
|
override async list() {
|
|
return this.db.listBlobs();
|
|
}
|
|
}
|