0.3.7 • Published 3 years ago

derpydb v0.3.7

Weekly downloads
6
License
MIT
Repository
github
Last release
3 years ago

DerpyDB

Basic code

const Database = require('derpydb');
// SQlite
const db = new Database({ uri: 'sqlite://db.sqlite' });
// MySQL
const db = new Database({ uri: 'mysql://user:pass@host/dbname' });

new Database(options)

  • options.uri: specific uri to connect (default: sqlite://db.sqlite).

Creates a new database connection.

const db = new Database({ uri: "sqlite://db.sqlite" });

.createTable(options)

Get the data from given id or id and target

  • options.table: specific table name to create (default: main).
db.createTable({ table: 'players' }); // true

.get(id, options)

Get the data from given id

  • options.table: specific table in the database (default: null).
  • options.target: specific a target to be get (default: null).
// without target
const data = db.get('derpy', { table: 'info' }); // { name: "Derpy", age: 19 }
// with target
const data = db.get('derpy', { table: 'info', target: 'age' }); // 18
const data = db.get('derpy.age', { table: 'players' }); // 18

.set(id, value, options)

set new data to given id

  • options.table: specific table in the database (default: null).
  • options.target: specific a target to be set (default: null).
db.set('derpy.age', 20, { table: 'info' }); // 20

.has(id, options)

find if the given id is exits

  • options.table: specific table in the database (default: null).
  • options.target: specific a target to find (default: null).
db.has('derpy.age', { table: 'info' }); // true

.type(id, options)

find the type of the given id

  • options.table: specific table in the database (default: null).
  • options.target: specific a target to find type (default: null).
db.type('derpy.age', { table: 'info' }); // number

.startsWith(string, options)

find the list datas that starts with the given string

  • options.table: specific table in the database (default: null).
db.startsWith('der', { table: 'info' }); // [{ id: 'derpy', value: { name: "Derpy", age: 19 }}]

.add(id, number, options)

add number value to the given id

  • options.table: specific table in the database (default: null).
  • options.target: specific a target to be added the number (default: null).
db.add('derpy.age', 1, { table: 'info' }); // 20

.remove(id, number, options)

remove number value from the given id

  • options.table: specific table in the database (default: null).
  • options.target: specific a target to be removed the number (default: null).
db.remove('derpy.age', 1, { table: 'info' }); // 18

.push(id, value, options)

push new item value to the given id

  • options.table: specific table in the database (default: null).
  • options.target: specific a target to be pushed in to (default: null).
db.get('derpy.list', { table: 'info' }); // ['banana', 'grape']
db.push('derpy.list', 'apple', { table: 'info' }); // ['banana', 'grape', 'apple']

.pull(id, value, options)

pull item value from the given id

  • options.table: specific table in the database (default: null).
  • options.target: specific a target to be pulled from it (default: null).
db.get('derpy.list', { table: 'info' }); // ['banana', 'grape', 'apple']
db.pull('derpy.list', 'grape', { table: 'info' }); // ['banana', 'apple']

.delete(id, options)

delete value from the given id

  • options.table: specific table in the database (default: null).
  • options.target: specific a target to be deleted from it (default: null).
db.delete('derpy', { table: 'info' }); // true

.all(options)

get list of databases in specific table

  • options.table: specific table in the database (default: null).
db.all({ table: 'info' }); // [{ id: 'derpy', value: { name: 'Derpy', age: 19 }}]

.deleteAll(options)

delete all the databases from specific table

  • options.table: specific table in the database (default: null).
db.deleteAll({ table: 'info' }); // []

.tables()

get the list of the tables you created

db.tables(); // ['info']

.deleteTable(options)

delete specific table

  • options.table: specific table in the database (default: null).
db.deleteTable({ table: 'info' }); // true

.getTable(options)

get specific table information

  • options.table: specific table in the database (default: null).
db.getTable({ table: 'info' }); // { table: 'info', id: 'TEXT', value: 'TEXT' }

.db

run code through sqlite

db.db.prepare('SELECT * FROM info WHERE id = (?)').get('derpy') 
0.3.7

3 years ago

0.3.0

3 years ago

0.3.6

3 years ago

0.2.7

3 years ago

0.3.5

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.10

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.0.12

4 years ago

0.1.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.0.10

4 years ago

0.0.11

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.3

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago