-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
75 lines (62 loc) · 1.96 KB
/
test.js
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
const fs = require('fs');
const Database = require('./database')
async function del(file){
return new Promise(ya=>{
fs.unlink(file, (err)=>{
ya()
})
})
}
async function test(){
console.log(Database.drivers.online)
await del("database.json")
await del("data2.json")
await del("noAwaits.json")
//No args
const db1 = new Database()
await db1.set("name", true)
await db1.set("age", 20)
await db1.add("age", 20)
await db1.toggleBoolean("name")
//Using a dif file
const db2 = new Database({filename: "data2.json"})
await db2.set("name", true)
await db2.set("age", 20)
await db2.add("age", 20)
await db2.toggleBoolean("name")
//Using no awaits
const db3 = new Database({ manual: true, filename: "noAwaits.json" })
db3.set("name", true)
db3.set("age", 20)
db3.add("age", 20)
db3.toggleBoolean("name")
if (!db3.saved) await db3.save()
//you can also get the raw data
db3.driver.data.name = "Bob"
}
async function serverTest(){
const server = new Database.server(null, {
databases: [
{ name: "exampleDatabase", allowedUsers: ["user1", "user2"] }
],
users: [
{ user: "user1", password: "pass", authLevel: 1 },
{ user: "user2", password: "pass", authLevel: 2 }
],
allowCreationOfDatabases: true, // allows clients to make databases
loginRequired: false
})
await server.start()
console.log("Server started")
const client = new Database({
driver: new Database.drivers.online({
url: "WS://127.0.0.1:3000",
auth: { user: "user2", password: "pass" },
database: "exampleDatabase"
})
})
await client.load()
console.log("Client loaded!")
await client.set("abc", {hello:"eeee"}).catch(e=>{console.log("ERROR", e)})
await client.set("abc.test", {no: false}).catch(e=>{console.log("ERROR", e)})
}