Gathering detailed insights and metrics for sql-easy-lib
Gathering detailed insights and metrics for sql-easy-lib
Gathering detailed insights and metrics for sql-easy-lib
Gathering detailed insights and metrics for sql-easy-lib
npm install sql-easy-lib
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
This library was written from simple work with databases. In current version supported next famous databases: sqlite3 and MySQL. In future, list with supported databases will be replenishing.
Before you use this module you must install it.
1npm install sql-easy-lib --save
and you can include it!
1const SQLEasy = require('sql-easy-lib');
Before work, you must know about twice main tools: get_from_key and Request.
1const SQLEasy = require('sql-easy-lib'); 2 3var req = new SQLEasy.Request([{id: 1, value: 12}, {name: 'CirillaGif'}]); 4/* This is boolean operation: "(id=1 AND value=12) OR (name=`CirillaGif`)" */ 5var get_from_key = SQLEasy.tools.get_from_key; 6/* get_from_key function, about him in down. */
Request use from create logic expression example:
1// ... 2new SQLEasy.Request([{id: 1, value: 12}, {name: 'CirillaGif'}]);
1(id=1 AND value=12) OR (name=`CirillaGif`)
get_from_key use for more efficient queries from buffer variables. example:
1// Without use get_from_key 2const SQLEasy = require('sql-easy-lib'); 3var database = new SQLEasy.SQLite3_database('/path/to/database.db'); 4var rolesData = database.get('users').map(i => { 5 return { 6 user: i, 7 role_data: database.get('role', new SQLEasy.Request([{id: i.role}])) 8 } 9});
1// With use get_from_key
2const SQLEasy = require('sql-easy-lib');
3var database = new SQLEasy.SQLite3_database('/path/to/database.db');
4var roleData = database.get('role', new SQLEasy.Request([{id: i.role}]));
5var rolesData = database.get('users').map(i => {
6 return {
7 user: i,
8 role_data: SQLEasy.tools.get_from_key(roleData, new SQLEasy.Request([{id: i.role}]))
9 }
10});
In all databases methods is equally (except for the connection).
1const SQLEasy = require('sql-easy-lib'); 2/* Method for connection sqlite3 database */ 3var sqlite3 = new SQLEasy.SQLite3_database('/path/to/database.db'); 4/* Method for connection MySQL database */ 5var mysql = new SQLEasy.MySQL_database({ 6 host: "mysql.example.org", 7 user: "username", 8 password: "password" 9}); 10mysql.set_db("Example_db"); // setting database in server
(for example, we use abstract database object): database
1const SQLEasy = require('sql-easy-lib'); 2 3var database = new SQLEasy.AnyDatabase(args);
This is getting items from table:
1SELECT
syntax:
1database.get( 2 'table_name', 3 new SQLEasy.Request([{param: 'value'}]), // Not required: ...WHERE (CONDITION) in request 4 '*' // Not required: Items in table 5);
1SELECT * FROM table_name WHERE (param=`value`)
This is set values in items in table:
1UPDATE .. SET
syntax:
1database.set( 2 'table_name', 3 new SQLEasy.Request([{param: 'value_require_edit'}]), // Required: ...WHERE (CONDITION) in request 4 {param: 'value'} // Required: Items in table 5);
1UPDATE table_name SET param=`value` WHERE (param=`value_require_edit`)
This method for remove items into database.
1DELETE
syntax:
1database.remove( 2 'table_name', 3 new SQLEasy.Request([{param: 'value'}]) // Required: ...WHERE (CONDITION) in request 4);
1DELETE FROM table_name WHERE (param=`value_require_edit`)
Method for add items into database.
1INSERT
syntax:
1database.add( 2 'table_name', 3 [{param: 'value'}] // Required: ... Rows what you add in table. 4);
1INSERT INTO table_name (param) VALUES (`value`)
No vulnerabilities found.
No security vulnerabilities found.