mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-22 20:46:38 +08:00
feat(core): init organize (#7456)
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { Doc as YDoc } from 'yjs';
|
||||
|
||||
import { Service } from '../../../framework';
|
||||
import { createORMClient, type TableMap, YjsDBAdapter } from '../../../orm';
|
||||
import type { WorkspaceService } from '../../workspace';
|
||||
import { AFFiNE_DB_SCHEMA } from '../schema';
|
||||
|
||||
export class DBService extends Service {
|
||||
db: TableMap<AFFiNE_DB_SCHEMA>;
|
||||
|
||||
constructor(private readonly workspaceService: WorkspaceService) {
|
||||
super();
|
||||
const Client = createORMClient(AFFiNE_DB_SCHEMA);
|
||||
this.db = new Client(
|
||||
new YjsDBAdapter(AFFiNE_DB_SCHEMA, {
|
||||
getDoc: guid => {
|
||||
const ydoc = new YDoc({
|
||||
// guid format: db${workspaceId}${guid}
|
||||
guid: `db$${this.workspaceService.workspace.id}$${guid}`,
|
||||
});
|
||||
this.workspaceService.workspace.engine.doc.addDoc(ydoc, false);
|
||||
this.workspaceService.workspace.engine.doc.setPriority(ydoc.guid, 50);
|
||||
return ydoc;
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
static isDBDocId(docId: string) {
|
||||
return docId.startsWith('db$');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user