New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@iannisz/database-json

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@iannisz/database-json

Simple JSON database

  • 1.0.38
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 21 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc