leoric icon indicating copy to clipboard operation
leoric copied to clipboard

should dup behavior be reverted?

Open cyjake opened this issue 3 years ago • 1 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();

cyjake avatar Sep 28 '22 07:09 cyjake

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);

cyjake avatar Sep 28 '22 07:09 cyjake