4.0.17 • Published 5 years ago

sa-mysql v4.0.17

Weekly downloads
38
License
ISC
Repository
gitlab
Last release
5 years ago

Soft-Artel Tools: MySQL Wrapper on async/await

Create Connection: let db = await SAMysql.connect( config );

Close Connection: await db.end();

Methods to make queries to DB:

db.dbStructure();

let res = await db.dbStructure( database = this.database )

Get DataBase Structure in json style;

db.select();

let res = await db.select( {object} )

Make select to DB:

{object} Can contain keys with use to create query:

  • sql : "", // Ready SQL
  • params : [] || {}, // Mysql.format ? params inject to SQL

    // Or build SQL by params some of them can be undefined:

  • table : "TableName", // Require param

  • fields : "", // Option, Fields in result*
  • where : "" || {}, // Where STRING or OBJ { field: value }
  • order : "" , // ORDER BY String
  • limit : 0 , // LIMIT, if == 1, result = {}

    // Also you can group results after select by value of field:

  • groupResultBy : "" , // Field with value uses to group result

  • groupResultArrays : "" , // If true, result = { ${groupResultBy}: }

Examples:

let users = await db.select( { sql: 'SELECT * FROM users;', groupResultBy:'ID' } );

Get all users in object { ID1: User1, ID2: User2, ... }

The same as:

let users = await db.select( { table: 'users', groupResultBy:'ID' } );

Get all users in object { ID1: User1, ID2: User2, ... }

if Limit set to 1 - result by Object = first row

let user = await db.select( { table: 'users', where:{ ID: 1 }, limit: 1 } );

user = User1

db.replace();

let res = await db.replace( table, data )

Make REPLACE query to DB:

  • table : "TableName", // Require param
  • data : {}, // Object data (keys mast by the same as fields in DB)

db.update();

let res = await db.update( table, data, where = null )

Make UPDATE query to DB:

  • table : "TableName", // Require param
  • data : {}, // Object data (keys mast by the same as fields in DB)
  • where : {}, // Where OBJ { field: value }

db.insert();

let res = await db.insert( table, data )

Make INSERT query to DB:

  • table : "TableName", // Require param
  • data : {}, // Object data (keys mast by the same as fields in DB)

db.delete();

let res = await db.delete( table, where, forceDelete = false)

Make DELETE query to DB:

  • table : "TableName", // Require param
  • where : {}, // Where OBJ { field: value }
  • forceDelete : {}, // if true where can be null, else - where require param
4.0.17

5 years ago

4.0.16

5 years ago

4.0.15

6 years ago

4.0.14

6 years ago

4.0.13

6 years ago

4.0.12

6 years ago

4.0.11

6 years ago

4.0.10

6 years ago

4.0.9

7 years ago

4.0.8

7 years ago

4.0.7

7 years ago

4.0.6

7 years ago

4.0.5

7 years ago

4.0.4

7 years ago

4.0.3

7 years ago

4.0.2

7 years ago

4.0.1

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.1.7

7 years ago

2.1.6

7 years ago

2.1.5

7 years ago

2.1.4

7 years ago

2.1.3

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.32

7 years ago

1.0.31

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

8 years ago

1.0.0

8 years ago