danych
v0.1.1
Published
a 1kb lightweight database in the browser built on top of localStorage and sessionStorage.
Downloads
24
Maintainers
Readme
Danych
Danych is a 1kb lightweight database in the browser. Danych is simply a Browser Storage built on top of localStorage and sessionStorage.
Installation
npm i danychimport useDanych from "danych"
interface Todo {
id: number
text: string
}
//Starting with full config
const db = useDanych.init<Todo>({
key: "my-app-data",
type: "session"
})
//OR, start localStorage with just the key
const db = useDanych.db("my-database-key")
//OR, start sessionStorage with just the key
const db = useDanych.state("my-database-key")call init() to start Danych with either full config object.
call db() to start Danych with localStorage with just Db Key.
call state() to start Danych with sessionStorage with just Db Key.
Danych treats all the datas like a collection which makes the DefaultData an Array by Default.
Usage
Storing Data
store new data using Danych.
//set new data
db.set({ id: 1, text: "some data" })
//set data with id
db.set({ id: 1, text: "some data" }, 0)Getting Data
get all the datas or get data with id.
//get all the store datas
const datas = db.get()
//get data with id
const datas = db.get(1)Updating Data
//update data with id
db.update({ id: 64, text: "new data value" }, 1)Removing Data
//remove data with id
db.remove(0)
//remove last stored data
db.remove()Properties
- datas - return all store datas.
###Danych is 750 Bytes, Fast, Fully Typed and Lightweight 🚀💨
License
MIT ©
