@selenite/graph-editor
Version:
A graph editor for visual programming, based on rete and svelte.
50 lines (49 loc) • 1.28 kB
JavaScript
import Dexie, { liveQuery } from 'dexie';
/** Database instance to work with IndexedDB. */
export const db = new Dexie('selenite');
db.version(1).stores({
graphs: 'id,&[name+author.id],name,description,author.id,author.name,public,version,updatedAt,createdAt,favoriteOf,schemaVersion,tags'
});
export class IndexedDBSource {
deleteMacro(id) {
return db.graphs.delete(id);
}
clearGraphs() {
return db.graphs.clear();
}
clearMacroBlocks() {
return db.graphs.clear();
}
getGraphs() {
return db.graphs.toArray();
}
getMacroBlocks() {
return db.graphs.toArray();
}
getMacroBlock(id) {
return db.graphs.get(id);
}
getGraph(id) {
return db.graphs.get(id);
}
saveMacroBlock(graph) {
return db.graphs.put(graph);
}
saveGraph(graph) {
return db.graphs.put(graph);
}
saveMacroBlocks(graphs) {
return db.graphs.bulkPut(graphs);
}
saveGraphs(graphs) {
return db.graphs.bulkPut(graphs);
}
numGraphs = liveQuery(() => db.graphs.count());
get numMacroBlocks() {
return this.numGraphs;
}
graphs = liveQuery(() => db.graphs.toArray());
get macroblocks() {
return this.graphs;
}
}