Grand Central Records
A basic ORM/ActiveRecord library for use in smaller Node projects or frameworks. Work in progress.
TODO
- Finish tests
- Create object for Model.new() & .save()
- MySQL Pool Connections
- GCE Error Handling
- Model validations
- Model relationships (hasMany, hasOne, belongsTo)
- Migration / synchronization
- query/queue/run
- MongoDB integration
Custom ORM
- Connects with
- Chainable queries
- Other functions/aliases
- .findByIdAndUpdate()
- .findByIdAndRemove()
- .create()
- .getColumns()
- Query & queue
- .query() (on SQL databases) -- executes the given query
- .queue(query string or chain) (accepts array, string, object)
- .run() -- executes all queries in the queue
Inspiration
Documentation
Samples:
var GCR = require('grand-central-records');
var Model = new GCR({
adapter: "mysql",
host: "localhost",
database: "test",
username: "admin",
password: "admin"
}, "users");
Model.find(8, function(err, user){
if (err) throw err;
console.log(user.name);
});
Model.select(["name","address"]).where({admin: true}, function(err, result) {
if (err) throw err;
result.forEach(function(user) {
...
});
});
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");
Query Methods:
.all()
.find()
.where()
.select()
.order()
.limit()
.offset()
.insert()
.update()
.remove()