Open IlyaSemenov opened 3 months ago
This needs some thinking about what to add, how to add, what to depreciate and remove, I'd like to postpone this for later, since it's already doable just somewhat messy.
Ideally:
get
for a single value, throws when not found, and I'm still considering renaming it to getOrThrow
for explicitnesspluck
for a flat array of valuesexec
for no resulttransform
if you wish to transform the value in a callback. No problem to map the result, but the chained transform
may be a bit more declarative.type
to use a column type for both typing and parsing, so decimal is parsed in a way how it's configured (Decimal lib in your case).This all should be taken into account, ideally.
As a developer, sometimes I need to fetch a single value with raw SQL, such as the next value in sequence. Currently, the proposed way is:
This works, but is somewhat ugly.
Another approach is abusing
db.table.get
:This also works, and much simpler to read, however it's coupled to
db.user
(or some other table) for no reason at all. (Also, it needs at least one record in the respective table).I was thinking, what if there was not only
db.$query
but alsodb.$get
and possiblydb.$take
/db.$takeOptional
? Or perhaps some common raw SQL wrapper with "usual" ORM methods likedb.$raw.select/get/take/...(something else?)...
?