exframe-sql
v1.3.3
Published
Framework module for SQL connections
Downloads
33
Readme
exframe SQL Module
A wrapper around sequelize/potentially other sql connectors to provide sql database connection for the Harmony Framework.
By default calling the base init
method will currently return an instance of a Sequelize connector/driver.
Features
- Multi-driver supported sql connection
- Exframe-Service Graceful Shutdown
Use
const db = require('exframe-sql')
Full Example
const db = require('exframe-sql')
const logger = require('exframe-logger').create(process.env.LOGSENE_TOKEN || 'token');
const { connection } = db.init({
logger,
name: 'test',
username: 'username',
password: 'password',
port: 1533,
host: 'localhost',
});
await connection.query('SELECT 1+1');
Properties
- Drivers List of available drivers
- SqlConnector SqlConnector class for customization
- Sequelize Core Sequelize Library export
Methods
init()
Syntax
db.init({ logger, username: 'test' });
Parameter Values
logger Required. logger object.
name Database Name
options Sequelize Options - See Sequelize Docs for information and dialect/connection specific languages
Returns
SqlConnector instance
connector.check()
const {status, message} = await connection.check()
Simple health check method to check the status of the database connection
connector.connect()
await connector.connect()
connector.close()
await connector.close()
Connector Properties
|Property|Type|Can be null?|Details| | |---|---|---|---|---| |connection|object|yes|The underlying driver connection instance (e.g. a sequelize connection)| | |name|string|no|connection instance name| | |order|string|no|exframe service order|
Tests
npm run test