You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sql.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 returned
sql.oneOrNone() - throw if more than one record is returned and return single record or null (not an array)
others...
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.
constoneAtom=awaitsql`SELECT * FROM atoms WHERE id=${id}`;// oneAtom is actually an array (with one atom object, but this isn't enforced)
constoneAtom=awaitsql.one`SELECT * FROM atoms WHERE id=${id}`;// oneAtom is the actual atom object. only one is returned else `sql.one` throws
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.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
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