1.0.38 • Published 5 years ago
@iannisz/database-json v1.0.38
Installation
$ npm install --save @iannisz/database-json
Usage
Quick Tutorial:
const db = require('@iannisz/database-json')
// Create a database called 'myFirstDataBase'
db('myFirstDataBase').create()
// Create a table in 'myFirstDataBase', called table1 with an array of columns
db('myFirstDataBase').table('table1').create(['column1', 'col2', 'name', 'age'])
// Insert values into table
db('myFirstDataBase').table('table1').insert(['data1', 2, 'John Doe', 50])
db('myFirstDataBase').table('table1').insert(['data3', 4, 'Johnny Doe', 25])
// Select all data in table
db('myFirstDataBase').table('table1').select('*')
// Will return:
// [
// { "column1": "data1", "col2": 2, "name": "John Doe", "age": 50 },
// { "column1": "data3", "col2": 4, "name": "Johnny Doe", "age": 25 }
// ]
The db object:
db(dbName) = {
create: () => {...},
drop: () => {...},
backup: (backupName) => {...},
table(tableName): {
create: (columnArray) => {...},
drop: () => {...},
insert: (dataArray) => {...},
select: (columnArray, options) => {...}
}
}
// Create a database
db(dbName).create()
// Delete a database
db(dbName).drop()
// Backup a database
// Will create a copy of the selected database under a different name
db(dbName).backup(backupName)
// Create a table in a database
db(dbName).table(tableName).create([col1, col2, col3...])
// Delete a table in a database
db(dbName).table(tableName).drop()
// Insert data to a table
db(dbName).table(tableName).insert([data1, data2, data3...])
// Select rows from a table
db(dbName).table(tableName).select(columnArray, options)
// Examples:
// To select everything:
db('myFirstDataBase').table('table1').select('*')
// To select only certain columns
db('myFirstDataBase').table('table1').select(['name', 'age'])
// To select with certain options
db('myFirstDataBase').table('table1').select('*', { 'where': 'age==50' })
// To select and order
db('myFirstDataBase').table('table1').select('*', { 'order-by-asc': 'name' })
// Mixed
db('myFirstDataBase').table('table1').select(
['name', 'age'], { 'where': 'age<51', 'order-by-desc': 'age' }
)
License
ISC © Iannis de Zwart
1.0.38
5 years ago
1.0.37
5 years ago
1.0.36
5 years ago
1.0.35
5 years ago
1.0.34
5 years ago
1.0.33
5 years ago
1.0.32
5 years ago
1.0.31
5 years ago
1.0.30
5 years ago
1.0.29
5 years ago
1.0.28
5 years ago
1.0.27
5 years ago
1.0.26
5 years ago
1.0.25
5 years ago
1.0.24
5 years ago
1.0.23
5 years ago
1.0.22
5 years ago
1.0.21
5 years ago
1.0.20
5 years ago
1.0.19
5 years ago
1.0.18
5 years ago
1.0.17
5 years ago
1.0.16
5 years ago
1.0.15
5 years ago
1.0.14
5 years ago
1.0.13
5 years ago
1.0.12
5 years ago
1.0.11
5 years ago
1.0.10
5 years ago
1.0.9
5 years ago
1.0.8
5 years ago
1.0.7
5 years ago
1.0.6
5 years ago
1.0.5
5 years ago
1.0.4
5 years ago
1.0.3
5 years ago
1.0.2
5 years ago
1.0.1
5 years ago
1.0.0
5 years ago