A promise-based Node ORM/ActiveRecord library that can connect to MySQL, Postgres, and SQLite3. Allows chainable, raw or queueable queries.
### new GCR(connection, [table], [options])
var GCR = require('grand-central-records');
var Model = new GCR({
adapter: "mysql",
host: "localhost",
database: "test",
username: "admin",
password: "admin"
}, "users");
Model.find(8).then(function(users) {
console.log(users[0].name);
}).catch(console.error);
Model.select(["name","address"]).where({admin: true})
.then(function(result) {
result.forEach(function(user) { ... });
});
Creating a new instance of the GCR object creates a connection to a new database.
### model(table, [options])
- table
string
— The name of the table the model is associated with. - options
json
— See above.
Multiple models can also be created from the same database.
var GCR = require('grand-central-records');
var db = new GCR({
adapter: "mysql",
host: "localhost",
database: "test",
username: "admin",
password: "admin"
}, { verbose: true });
var User = db.model("users"),
Project = db.model("projects");
Documentation
Getting started