@fizz.js/node-model
v1.0.0-hotfix8
Published
node-model
Downloads
1
Readme
@fizz.js/node-model
This is a model library for express.
install
add dependencies
into package.json
and run yarn install
configuration
please set db
field into your config files.
{
"db": {
"development": {
"user": "test",
"username": "test",
"password": "Test_1234",
"database": "test_utf8",
"host": "127.0.0.1",
"port": "3306",
"dialect": "mysql",
"dialectOptions": {
"connectTimeout": 5000,
"bigNumberStrings": false,
"supportBigNumbers": true
},
"pool": {
"max": 100,
"min": 1,
"idle": 60000,
"acquire": 60000,
"evict": 90000,
"handleDisconnects": true
},
"timezone": "UTC",
"define": {
"underscored": false,
"timestamps": true,
"freezeTableName": true
},
"benchmark": true
},
"test": {
"user": "test",
"username": "test",
"password": "Test_1234",
"database": "test_utf8",
"host": "127.0.0.1",
"port": "3306",
"dialect": "mysql",
"dialectOptions": {
"connectTimeout": 5000,
"bigNumberStrings": false,
"supportBigNumbers": true
},
"pool": {
"max": 100,
"min": 1,
"idle": 60000,
"acquire": 60000,
"evict": 90000,
"handleDisconnects": true
},
"timezone": "UTC",
"define": {
"underscored": false,
"timestamps": true,
"freezeTableName": true
},
"benchmark": true
},
"production": {
"replication": {
"read": [
{
"host": "192.168.1.100",
"database": "test_utf8",
"port": "3306",
"user": "test",
"username": "test",
"password": "Test_1234"
},
{
"host": "192.168.1.101",
"database": "test_utf8",
"port": "3306",
"user": "test",
"username": "test",
"password": "Test_1234"
}
],
"write": {
"host": "127.0.0.1",
"database": "test_utf8",
"port": "3306",
"user": "test",
"username": "test",
"password": "Test_1234"
}
},
"dialect": "mysql",
"dialectOptions": {
"connectTimeout": 5000,
"bigNumberStrings": false,
"supportBigNumbers": true
},
"pool": {
"max": 100,
"min": 1,
"idle": 60000,
"acquire": 60000,
"evict": 90000,
"handleDisconnects": true
},
"timezone": "UTC",
"define": {
"underscored": false,
"timestamps": true,
"freezeTableName": true
},
"benchmark": true
}
}
}
test
yarn test
coverage
yarn cover
build
yarn build
docs
yarn docs
example
'use strict'
// @ts-check
const process = require('process')
const fs = require('fs')
const path = require('path')
const target = process.env.NODE_ENV === 'production' ? 'dist' : 'libs'
const Model = require(path.resolve(target, 'index.js'))
const Models = new Model(true)
const basename = path.basename(__filename)
const ext = '.js'
fs.readdirSync(__dirname)
.filter(file => file.indexOf('.') !== 0 && file !== basename && file.slice(-3) === ext)
.map(file => file.replace(ext, ''))
.map(file => Models.registerTable(file, require(`./${file}`)))
Models.associateTables()
Models.sync()
module.exports = Models