1.0.3 • Published 5 years ago

@thealmondtree/mysql v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
5 years ago

The Almond Tree's MySQL wrapper

Package built on top of NodeJS mysql2 package and Typescript.

Installation

npm i @thealmondtree/mysql

Exports

This package exports an object with two properties:

  • DB: The wrapper class which can be instantiated with new DB(config)
  • factory: function that if passed an appropiate config object returns an instantiated database object

Config Options

Property NameProperty TypeRequiredDefault
userstringyes
passwordstringno'' (Empty String)
databasestringyes
hoststringyes
Portnumberno3306
multipleStatementsbooleannofalse
connectionLimitnumberno10

Available methods

  • query: Standard NodeJS mysql2 query method with two arguments, a query string and an array with arguments to interpolate in order in the question marks placed in the sql query string. e.g: db.query('SELECT ?? FROM ?? WHERE lang = ?', ['column', 'table', 'value'])

  • select: Method that performs a select query. Needs a table name, a list of columns and an object containing the key value pairs that will represent the where statement, e.g:

    db.select('table', 'column1, column2', { id: 12 })

  • update: Method that performs an update query. The arguments are the table name, an object containing the key value pairs of the columnName -> value to be set and another similar object with the where -> value conditions. e.g:

    db.update('table', { value:'wat' }, { id: 1234 })

  • insert: Method that performs an insert query. It receives the table name in which the data has to be inserted and an object containing the key value pairs to be inserted. e.g:

    db.insert('table', { value1: 'hello', value2: 'world' })

  • sql: Method that performs a normal MySQL query but that you can call with the backticks string format. e.g:

    db.sql`SELECT test_value FROM ${table_name} WHERE wat = ${wat.value}`

  • stream: Method that performs a regular MySQL query but returns the response in a stream format. e.g:

    db.stream('SELECT * FROM DEVICES')

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago