rails/arel in javascript
rails/arel in javascript
npm i arel --save
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"
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"
MIT