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

should dup behavior be reverted?

cyjake opened this issue · comments

The design of dup is mostly to solve confusing usages like below:

const query = Post.where({ published: true });
// SELECT * FROM posts WHERE published = 1 LIMIT 0,20;
const posts = await query.limit(pageSize).offset((page - 1) * pageSize);
// SELECT COUNT(*) FROM posts WHERE published = 1;
const count = await query.count();

the bad part of this design is if user wants to construct query conditionally, they'd have to define the query as mutable, such as:

let query = Post.where({ published: true });
query = query.where('commentCount > ?', commentCount);