Query return types and syntax #4899
ravinggenius
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Query syntax
Inspired by
pg-promise
(https://vitaly-t.github.io/pg-promise/Database.html).sql()
orsql.any()
- current behaviorsql.none()
- throw if records are returnedsql.one()
- ensure one and only one record is returned by the query and return it (not an array)sql.many()
- ensure at least one record is returnedsql.oneOrNone()
- throw if more than one record is returned and return single record ornull
(not an array)Tagged template literals
For the above helpers too. I've seen several libraries do this, but the basic idea is that the dynamic portions of the query template are properly escaped.
Query files
Some queries are bound to be big. It would be nice if the above functions would support loading queries from external files. This again is borrowed from
pg-promise
(https://vitaly-t.github.io/pg-promise/QueryFile.html).I think these additions would go a long way towards creating an accessible library for practical everyday use. Personally I'd love to see these features added to what you already have. I haven't found a library that does all of these.
Beta Was this translation helpful? Give feedback.
All reactions