1.0.1 • Published 2 years ago
static.db.test v1.0.1
static.db
Static sqlite database management with functions
Features
- Custom database file
- Error handling
- Lot of methods
- Based on quick.db
- Very easy usage
- Executable SQL query
Getting Started
Installation
$ npm install static.db
Update
$ npm install static.db@latest
Import
const { Database } = require('static.db')
Examples
Basic Examples
// DEFAULT USAGE
const database = require('static.db').static()
database.set('hello', 'world') // set string
database.add('score', 1) // add number
console.log(database.get('hello'))
console.log(database.get('score'))
// CUSTOM USAGE
const database = require('static.db').static('./mydatabase.sqlite')
// code here...
Default Examples
// DEFAULT USAGE
const { Database } = require('static.db')
const database = new Database() // create database
database.set('hello', 'world') // set string
database.add('score', 1) // add number
console.log(database.get('hello'))
console.log(database.get('score'))
// CUSTOM USAGE
const { Database } = require('static.db')
const database = new Database('./database/mydatabase.sqlite', {
path: './database',
tableName: 'MYTABLE',
useWalMode: true // Write-Ahead Logging
}) // create database with custom name, path and options
// code here...
// CUSTOM TABLES
const { Database } = require('static.db')
const database = new Database()
const db = database.createTable('MYTABLE')
// using definied
db.set('hello', 'world') // set string
db.add('score', 1) // add number
console.log(db.get('hello'))
console.log(db.get('score'))
// using default database
database.set('foo', 'bar', { table: 'MYTABLE' }) // set string
database.add('loses', 1, { table: 'MYTABLE' }) // add number
console.log(database.get('foo', { table: 'MYTABLE' }))
console.log(database.get('loses', { table: 'MYTABLE' }))
Documentation
API
// Adds number to data
.add(key: string, value: number, options?: object)
.add('foo', 1)
.add('foo', 1, {
table: 'table_name'
})
// Returns all data in this database
.all(options?: object)
.all()
.all({
table: 'table_name',
length: 10
})
// Deletes a data of the specified key
.delete(key: string, options?: object)
.delete('foo')
.delete('foo', {
table: 'table_name'
})
// Fetches data from this database
.fetch(key: string, options?: object)
.fetch('foo')
.fetch('foo', {
table: 'table_name'
})
// Fetches all data in this database
.fetchAll(options?: object)
.fetchAll()
.fetchAll({
table: 'table_name',
length: 10
})
// Returns data from this database
.get(key: string, options?: object)
.get('foo')
.get('foo', {
table: 'table_name'
})
// Checks if there is any matching entry with provided key
.has(key: string, options?: object)
.has('foo')
.has('foo', {
table: 'table_name'
})
// Pushes data into this database
.push(key: string, value: any | any[], options?: object)
.push('foo', 'bar')
.push('foo', ['bar','baz'])
.push('foo', 'bar', {
table: 'table_name'
})
// Sets or overwrites data in this database
.set(key: string, value: any, options?: object)
.set('foo', 'bar')
.set('foo', ['bar','baz'])
.set('foo', { bar: 'bar' })
.set('foo', 0)
.set('foo', true)
.set('foo', 'bar', {
table: 'table_name'
})
// Subtracts number from data
.subtract(key: string, value: number, options?: object)
.subtract('foo', 1)
.subtract('foo', 1, {
table: 'table_name'
})
// Returns data type of fetched data
.type(key: string, options?: object)
.type('foo')
.type('foo', {
table: 'table_name'
})