-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
91 lines (80 loc) · 2.7 KB
/
index.html
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="https://unpkg.com/lodash@4/lodash.min.js"></script>
<script src="https://unpkg.com/lowdb@0.17/dist/low.min.js"></script>
<script src="https://unpkg.com/lowdb@0.17/dist/LocalStorage.min.js"></script>
</head>
<body>
<script type="module">
import { nanoid } from "https://cdn.jsdelivr.net/npm/nanoid/nanoid.js";
const adapter = new LocalStorage("db");
const db = low(adapter);
db.defaults({
topic: [],
author: [],
}).write();
/* ----------------------------- Create ----------------------------- */
db.get("author")
.push({
id: 1,
name: "Nayeon",
profile: "Aspiring back-end developer",
})
.write();
db.get("topic")
.push({
id: 1,
title: "lowdb",
description: "lowdb is a simple-to-use local JSON database.",
author: 1,
})
.write();
db.get("topic")
.push({
id: 2,
title: "MySQL",
description:
"MySQL is an open-source relational database management system.",
author: 1,
})
.write();
/* ------------------------------ Read ------------------------------ */
const lowdb = db.get("topic").find({ title: "lowdb", author: 1 }).value();
console.log(lowdb);
/* ----------------------------- Update ----------------------------- */
db.get("topic")
.find({ id: 2 })
.assign({
title: "MySQL & MariaDB",
description:
"MySQL is an open-source relational database management system. MariaDB is a community-developed, commercially supported fork of the MySQL relational database management system.",
})
.write();
/* ----------------------------- Delete ----------------------------- */
db.get("topic").remove({ id: 2 }).write();
/* --------------------------- Random ids --------------------------- */
const nanoId = nanoid();
db.get("author")
.push({
id: nanoId,
name: "Nayoni",
title: "Nayeon's clone",
})
.write();
db.get("topic")
.push({
id: nanoid(),
title: "PostgreSQL",
description:
"PostgreSQL is a free and open-source relational database management system emphasizing extensibility and SQL compliance.",
author: nanoId,
})
.write();
</script>
</body>
</html>