arel

rails/arel in javascript

View the Project on GitHub wangzuo/arel

Arel

npm Build Status codecov styled with prettier Greenkeeper badge

rails/arel in javascript

Installation

npm i arel --save

Usage

import * as Arel from 'arel'; // es6
// const Arel = require('arel');

const users = new Arel.Table('users');
const query = users.project(Arel.sql('*'));
query.toSql(); // => SELECT * FROM "users"

More examples

users.project(users.column('id'))
// => SELECT "users"."id" FROM "users"

users.where(users.column('name').eq('amy'))
// => SELECT FROM "users" WHERE "users"."name" = 'amy'

const photos = new Arel.Table('photos');
users.join(photos).on(users.column('id').eq(photos.column('user_id')))
// => SELECT FROM "users" INNER JOIN "photos" ON "users"."id" = "photos"."user_id"

License

MIT