midb
Perfect tables-based database made for you! <3
Install:
npm i midb
Setup:
import { Database } from "midb";
const db = new Database({
path: './database',
tables: ['main']
})
db.on('ready', () => {
console.log('Database is connected.')
})
db.start()
Methods
Set
Add or re-set something to the database.
(async() => {
await db.set('foo', 'bar')
await db.set('collection.admin', 'Mid', 'Users')
})()
Get
Get something from the database.
(async() => {
db.get('foo').then(console.log)
db.get('collection', 'Users').then(console.log())
})()
Push
Add a new element to an array in the database.
(async() => {
await db.push('foods', 'apple')
await db.push('foods', 'banana')
db.get('foods').then(console.log)
})()
Remove
Remove an element from an array in the database.
(async() => {
db.get('foods').then(console.log)
await db.remove('foods', 'apple')
db.get('foods').then(console.log)
})()
Add
Add some amount to a number in the database.
(async() => {
await db.add('participants', 5, 'Polls')
db.get('participants', 'Polls').then(console.log)
await db.add('participants', 10, 'Polls')
db.get('participants', 'Polls').then(console.log)
})()
Sub
Sub some amount from a number in the database.
(async() => {
db.get('participants', 'Polls').then(console.log)
await db.sub('participants', 5, 'Polls')
db.get('participants', 'Polls').then(console.log)
})()
Has
Check if the database has a key value.
(async() => {
await db.set('myobject', { "a": 1, "b": 2 })
db.has('myobject.b').then(console.log)
db.has('myobject.c').then(console.log)
})()
Delete
Delete something from the database.
(async() => {
await db.set('test', { "foo" true, "bar": "sup" })
db.get('test').then(console.log)
await db.delete('test.bar')
db.get('test').then(console.log)
})()
Ping
Check the database latency (miliseconds).
(async() => {
let ping = await db.ping()
console.log(ping)
})()
Get table
Get a table object (like all).
(async() => {
let all = db.getTable('main')
console.log(all)
})()
Start
Starts the database (very important).
import { Database } from "midb";
const db = new Database()
db.start()