grand-central-records

An activerecord-inspired ORM for Node.js

Usage no npm install needed!

<script type="module">
  import grandCentralRecords from 'https://cdn.skypack.dev/grand-central-records';
</script>

README

Grand Central Records (GCR)

Build Status NPM version

A promise-based Node ORM/ActiveRecord library that can connect to MySQL, Postgres, and SQLite3. Allows chainable, raw or queueable queries.


Getting started

### 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

Raw queries

Models

Other functions

Query methods

Postgres


Inspiration