A promise based ORM for node.js and mysql databases. A work in progress.
- Install dependencies:
$ npm install
- Set development environment environment variables (without brackets)
$ export ENV=[environment]
$ export DB_USER=[username]
$ export DB_PASS=[password]
- Run Tests:
$ npm run test
This is a simple example of how the models are used.
- Define a Model
class Country extends Model {
constructor(code='') {
super();
this._table= 'country';
this._pk = 'code';
this._model = {
code: code,
name: '',
continent: '',
...
};
this._rel = {
cities: [],
languages: []
};
}
}
- Initialize Database
const config = { host: 'localhost', database: 'world', user: process.env.DB_USER, password: process.env.DB_PASS };
Database.init(config);
- Execute a query
const id = 'ARM';
country = new Country(id);
country.load().then((country) => {
// country.model ==> { code: 'ARM', name: 'Armenia', continent: 'Asia' .. }
}).catch((err) => {
console.log(err);
});