-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
44 lines (32 loc) · 1.21 KB
/
example.js
File metadata and controls
44 lines (32 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
const DB = require("./");
// Define a custom database file path
const customDBPath = "db/mydatabase.sql";
// Create an instance of the DB class
const nodedb = new DB(customDBPath);
async function main() {
// Set data using setDB
await nodedb.setDB("users", "ajay", { name: "Ajay o s", age: 20 });
// Get data using getDB
const ajay = await nodedb.getDB("users", "ajay");
console.log("Retrieved Data:", ajay);
// Get all rows using getDB
const allUsers = await nodedb.getDB("users");
console.log("All Users:", allUsers);
// Delete a specific row using deleteDB
await nodedb.deleteDB("users", "ajay");
// Delete an entire table using deleteDB
await nodedb.deleteDB("users");
// Set data without JSON stringifying using setDATA
await nodedb.setDATA("metadata", "version", 1.2);
// Get data without JSON parsing using getDATA
const version = await nodedb.getDATA("metadata", "version");
console.log("Version:", version);
// Delete a specific row using deleteDATA
await nodedb.deleteDATA("metadata", "version");
// Delete an entire table using deleteDATA
await nodedb.deleteDATA("metadata");
}
// Run the main function
main().catch((error) => {
console.error("An error occurred:", error);
});