Giter Site home page Giter Site logo

denobase's Introduction

Denobase

Denobase is a database written in TypeScript for Deno.

Usage

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.

Set (key: string, value: string | number): boolean

let set: boolean = db.set("test", "Hello Deno!") // true

Get (key: string): string | number | undefined

let get: Get = db.get("test") // "Hello Deno!"

Has (key: string): boolean

let has: boolean = db.has("test") // true
let falsehas: boolean = db.has("testt") // false

Delete (key: string): boolean

let testSet: boolean = db.set("testDelete", "Hello World!") //true
let testDelete: boolean = db.delete("testDelete") // true
let testHas: boolean = db.has("testDelete") // false

All (): object

let all: object = db.all() // { test: "Hello Deno!" }

Clear (): boolean

let clear: boolean = db.clear() // true
let testAll = db.all() // {}

Write (): boolean

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!" }

Read (): Promise<boolean>

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'.

Example

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

denobase's People

Contributors

mora2407 avatar moncefplastin07 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.