1.0.38 • Published 7 years ago
@iannisz/database-json v1.0.38
Installation
$ npm install --save @iannisz/database-jsonUsage
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
7 years ago
1.0.37
7 years ago
1.0.36
7 years ago
1.0.35
7 years ago
1.0.34
7 years ago
1.0.33
7 years ago
1.0.32
7 years ago
1.0.31
7 years ago
1.0.30
7 years ago
1.0.29
7 years ago
1.0.28
7 years ago
1.0.27
7 years ago
1.0.26
7 years ago
1.0.25
7 years ago
1.0.24
7 years ago
1.0.23
7 years ago
1.0.22
7 years ago
1.0.21
7 years ago
1.0.20
7 years ago
1.0.19
7 years ago
1.0.18
7 years ago
1.0.17
7 years ago
1.0.16
7 years ago
1.0.15
7 years ago
1.0.14
7 years ago
1.0.13
7 years ago
1.0.12
7 years ago
1.0.11
7 years ago
1.0.10
7 years ago
1.0.9
7 years ago
1.0.8
7 years ago
1.0.7
7 years ago
1.0.6
7 years ago
1.0.5
7 years ago
1.0.4
7 years ago
1.0.3
7 years ago
1.0.2
7 years ago
1.0.1
7 years ago
1.0.0
7 years ago