Denobase is a database written in TypeScript for Deno.
For this tutorial, we will use 'db' as the Database.
import { Database, Get } from "https://deno.land/x/[email protected]/mod.ts"
let db = new Database("dataStore")
'Get' is the return type for '.get()' method.
let set: boolean = db.set("test", "Hello Deno!") // true
let get: Get = db.get("test") // "Hello Deno!"
let has: boolean = db.has("test") // true
let falsehas: boolean = db.has("testt") // false
let testSet: boolean = db.set("testDelete", "Hello World!") //true
let testDelete: boolean = db.delete("testDelete") // true
let testHas: boolean = db.has("testDelete") // false
let all: object = db.all() // { test: "Hello Deno!" }
let clear: boolean = db.clear() // true
let testAll = db.all() // {}
This method will write all the data to a .json file. The file name will be the same as the database name.
db.set("set", "Hello!")
db.write()
dataStore.json
{ "set": "Hello!" }
Denobase use Map for the database.
If you don't use 'read', denobase will create an empty Map.
Use 'read' to read json data from the json file that is created using 'write'.
main.ts
import { Database } from "https://deno.land/x/[email protected]/mod.ts"
let db = new Database("denobase")
db.set("color", "Red")
db.write()
It will create a new json file
denobase.json
{ "color": "Red" }
If you try to log all value in the database, it will return an empty object because it create a new Map.
import { Database } from "https://deno.land/x/[email protected]/mod.ts"
let db = new Database("denobase")
db.all() // {}
If you use 'read'
import { Database } from "https://deno.land/x/[email protected]/mod.ts"
let db = new Database("denobase")
await db.read()
db.all() // { color: "Red" }
Note:
- Always use 'await' and put it after creating new database.
- Always make sure the database name is the same