cyjake / leoric

👑 JavaScript ORM for MySQL, PostgreSQL, and SQLite.

Home Page:https://leoric.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[FEAT] support injecting raw SQL into query

JimmyDaddy opened this issue · comments

eg.

Post.order(Realm.raw("find_in_set(id, '1,2,3')"))
// SELECT * FROM `articles` WHERE `gmt_deleted` IS NULL ORDER BY find_in_set(id, '1,2,3')
User.order(Realm.raw('rand()'))
// SELECT * FROM `users` ORDER BY rand()
Post.where({
    author_id: Realm.raw('(SELECT id FROM `users` WHERE level > 10 ORDER BY rand() LIMIT 1)')
})
// SELECT * FROM `articles` WHERE `author_id` = (SELECT id FROM `users` WHERE level > 10 ORDER BY rand() LIMIT 1) AND `gmt_deleted` IS NULL
Post.where({
  author_id: {
    $in: Realm.raw('(SELECT id FROM `users` WHERE level > 10 ORDER BY rand())')
  }
})
// SELECT * FROM `articles` WHERE `author_id` IN (SELECT id FROM `users` WHERE level > 10 ORDER BY rand()) AND `gmt_deleted` IS NULL 
// upsert\delete and son on

equal to sequelize literal