forked from findyourmagic/dber
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.js
More file actions
55 lines (49 loc) · 1.21 KB
/
db.js
File metadata and controls
55 lines (49 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* Creating a database called graphDB and creating a table called graphs. */
import Dexie from 'dexie';
import { Notification } from '@arco-design/web-react';
import { diffJson } from 'diff';
export const db = new Dexie('graphDB');
db.version(3).stores({
graphs: 'id',
meta: '++id, inited',
logs: '++id, graphId',
});
export const saveGraph = async ({
id,
name,
tableDict,
linkDict,
box,
}) => {
const now = new Date().valueOf();
try {
const data = await db.graphs.get(id);
await db.graphs.put({
id,
tableDict,
linkDict,
box,
name,
updatedAt: now,
});
const logJson = {
tableDict: data.tableDict,
linkDict: data.linkDict,
name: data.name,
};
if (diffJson({ tableDict, linkDict, name }, logJson).length > 1) {
db.logs.add({
graphId: id,
updatedAt: data.updatedAt,
...logJson,
});
}
Notification.success({
title: 'Save success',
});
} catch (e) {
Notification.error({
title: 'Save failed',
});
}
};