-
Notifications
You must be signed in to change notification settings - Fork 380
Description
Thanks again for all the great work you're doing here! I just started using the new(ish) ExpressionBuilder API, and wanted to give a bit of feedback, which I hope will be helpful.
In general, I think the new design makes a lot of sense, and the new names apply better in the various contexts where expressions can be used than the old ones did. My only suggestion has to do with the abbreviated method names cmpr and bxp. Two things struck me about these:
-
Using abbreviations felt a bit out of place with the rest of the kysely API, which generally seems favors explicitness and readability over maximum concision (e.g.,
selectFromrather thanfrom, or something even shorter). To me, the three letters saved by usingcmpras opposed tocomparedoesn't seem worth it, given thatcmpris not an especially familiar abbreviation. -
However, if the expression builder API is going to use abbreviations — and I can see a case for that in this API — then I think it might be worth adding abbreviated methods for specific, common binary comparisons, like
eq,neq,gt,gte, etc. Having methods like that is, to me, both more intuitive (becauseeqis a much more common/familiar abbreviation thancmpr) and more concise (since the operator can be omitted).
So, I guess the above suggest three possible APIs:
-
qb.where(({ compare, and }) => and([ compare('first_name', '=', 'Jennifer'), compare('last_name', '!=', 'Tremblay'), compare('updated_at', '>', lastMonth) ])
-
qb.where(({ cmpr, and }) => and([ cmpr('first_name', '=', 'Jennifer'), cmpr('last_name', '!=', 'Tremblay'), cmpr('updated_at', '>', lastMonth) ])
-
qb.where(({ eq, neq, gt, and }) => and([ eq('first_name', 'Jennifer'), neq('last_name', 'Tremblay'), gt('updated_at', lastMonth) ])
Personally, I think I prefer (1), for maximum clarity without too much verbosity. But, if maximal concision is the goal, then (3) makes more sense to me than two.