-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.html
45 lines (39 loc) · 2.02 KB
/
example.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
<script src="LocalDatabase.all.js" type="application/javascript"></script>
<script>
(async() => {
// Create the schema
const peopleTable = new LocalDatabase.Table("People",
new LocalDatabase.Column("id", {unique: true}),
[
new LocalDatabase.Column("firstName"),
new LocalDatabase.Column("lastName"),
new LocalDatabase.Column("age")
]
);
const dbSchema = new LocalDatabase.Database("MyDatabase", [peopleTable]);
// Initialise the database
await LocalDatabase.init(dbSchema);
// Insert some data
await LocalDatabase.add(peopleTable.name, {id: 1, firstName: "John", lastName: "Doe", age: 42});
await LocalDatabase.add("People", {id: 2, firstName: "Bob", lastName: "Smith", age: 35});
await LocalDatabase.multiAdd(peopleTable.name, [
{id: 4, firstName: "David", lastName: "Gray", age: 20},
{id: 6, firstName: "John", lastName: "Gilmore", age: 69},
{id: 5, firstName: "John", lastName: "Robson", age: 69},
{id: 3, firstName: "Harry", lastName: "Gardener", age: 66},
{id: 7, firstName: "Billy", lastName: "Jean", age: 19},
{id: 8, firstName: "Sarah", lastName: "Jones", age: 19},
{id: 9, firstName: "Karen", lastName: "Maker", age: 19},
{id: 10, firstName: "Al", lastName: "Young", age: 5},
]);
// Delete some data
await LocalDatabase.delete("People", {age: {$lt: 18}});
// Query the database
const allEntries = await LocalDatabase.select("People", {age: {$gt: 0}});
console.log("All Entries", allEntries);
const people20to60 = await LocalDatabase.select("People", {age: {$lt: 60, $gte: 20}});
console.log("People ages 20 to 60", people20to60);
const queryResult = await LocalDatabase.select("People", {firstName: "John", age: 69, lastName: {$ne: "Gilmore"}});
console.log("Query result:", queryResult);
})()
</script>