
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
modli-mysql
Advanced tools
This module provides adapter for the MySQL datasource for integration with Modli.
npm install modli-mysql --save
When defining a property which will utilize the adapter it is required that a
tableName be supplied:
import { model, adapter, Joi, use } from 'modli';
import mysql from 'modli-mysql';
model.add({
name: 'foo',
version: 1,
tableName: 'tblFoo'
schema: {
id: Joi.number().integer(),
fname: Joi.string().min(3).max(30),
lname: Joi.string().min(3).max(30),
email: Joi.string().email().min(3).max(254).required()
}
});
Then add the adapter as per usual with the following config object structure:
adapter.add({
name: 'mysqlFoo',
source: mysql
config: {
host: {HOST_IP},
username: {USERNAME},
password: {PASSWORD},
database: {DATABASE}
}
});
You can then use the adapter with a model via:
// Use(MODEL, ADAPTER)
const mysqlTest = use('foo', 'mysqlFoo');
The following methods exist natively on the MySQL adapter:
queryAllows for passing standard MySQL queries:
mysqlTest.query('SELECT * FROM tblFoo')
.then(/*...*/)
.catch(/*...*/);
createTableCreates (IF NOT EXISTS) a table based on params:
mysqlTest.createTable({
'id': [ 'INT', 'NOT NULL', 'AUTO_INCREMENT', 'PRIMARY KEY'],
'fname': [ 'VARCHAR(255)' ],
'lname': [ 'VARCHAR(255)' ],
'email': [ 'VARCHAR(255)' ]
})
.then(/*...*/)
.catch(/*...*/);
createCreates a new record based on object passed:
mysqlTest.create({
fname: 'John',
lname: 'Smith',
email: 'jsmith@gmail.com'
})
.then(/*...*/)
.catch(/*...*/);
readRuns a SELECT with optional WHERE:
mysqlTest.read('fname="John"')
.then(/*...*/)
.catch(/*...*/);
updateUpdates record(s) based on query and body:
mysqlTest.update('fname="John"', {
fname: 'Bob',
email: 'bsmith@gmail.com'
})
.then(/*...*/)
.catch(/*...*/);
patchPatches (partial update) based on query and body:
mysqlTest.patch('fname="John"', {
fname: 'Bob',
})
.then(/*...*/)
.catch(/*...*/);
deleteDeletes record(s) based on query:
mysqlTest.delete('fname="Bob"')
.then(/*...*/)
.catch(/*...*/);
extendExtends the adapter to allow for custom methods:
mysqlTest.extend('myMethod', () => {
/*...*/
});
The MySQL adapter requires the following enviroment variables to be set for running the tests. These should be associated with the MySQL instance running locally.
MODLI_MYSQL_HOST,
MODLI_MYSQL_USERNAME,
MODLI_MYSQL_PASSWORD,
MODLI_MYSQL_DATABASE
This repository includes a base container config for running locally which is located in the /docker directory.
A Makefile is included for managing build and install tasks. The commands are
then referenced in the package.json scripts if that is the preferred
task method:
all (default) will run all build tasksstart will run the main scriptclean will remove the /node_modules directoriesbuild will transpile ES2015 code in /src to /buildtest will run all spec files in /test/srctest-cover will run code coverage on all testslint will lint all files in /srcRunning make test will run the full test suite. Since adapters require a data
source if one is not configured the tests will fail. To counter this tests are
able to be broken up.
Test Inidividual File
An individual spec can be run by specifying the FILE:
make test FILE=some.spec.js
The FILE is relative to the test/src/ directory.
Deploys
For deploying releases, the deploy TAG={VERSION} can be used where VERSION can be:
<newversion> | major | minor | patch | premajor
Both make {COMMAND} and npm run {COMMAND} work for any of the above commands.
Modli-MySQL is licensed under the MIT license. Please see LICENSE.txt for full details.
Modli-MySQL was designed and created at TechnologyAdvice.
FAQs
Modli adapter for MySQL
The npm package modli-mysql receives a total of 4 weekly downloads. As such, modli-mysql popularity was classified as not popular.
We found that modli-mysql demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.