Skip to content


Subversion checkout URL

You can clone with
Download ZIP
ORM with an emphasis on the O, the R, and the M.
Branch: master
Failed to load latest commit information.
src Try to improve join aggregation
.gitignore Prepare for release
.npmignore add a basic readme
package.json Add create table support


The idea I'm kicking around is this...

Start by defining your schema with JSON structures:

Please note this is a MAJOR not finished not even released project.

var Relational = require('relational');
var schema = new Relational().schema;

  name: 'user',
  columns: [{
    name: 'id',
    type: 'serial',
    primaryKey: true
  }, {
    name: 'email',
    type: 'text',
    allowNull: false

  name: 'photo',
  columns: [{
    name: 'id',
    type: 'serial',
    primaryKey: true
  }, {
    name: 'description',
    type: 'text'
  }, {
    name: 'userId',
    type: 'int',
    foreignKey: {
      table: 'user',
      column: 'id'

The schema contains information about the relationships between the tables as well as the individual tables via the foreign key property on a column. What this will allow is something like this:

//continuing the last example...

// Find me users
//SELECT * FROM "user"

// Find me users, include photos, let relational figure out how to join
//SELECT "user"."id", "", "", "photo.userId",
//"photo.description" FROM "user" INNER JOIN "photo" ON "" EQUALS "photo.userId"

Basically...I really fancy query builder. Something kinda like AREL maybe for ruby.

I'm not sure where I will go after that, but this at least will be really for me. This uses [node-sql] internally so it should be portable between databases with little work.

Other ideas:

  1. migrations based on reflecting on the schema definition and comparing it to the current database schema
  2. ORM functionality like CREATE, UPDATE, DELETE on rows
  3. Lazy loading collections, bla bla
Something went wrong with that request. Please try again.