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
I see this as an opportunity to simplify how queries are executed (or any SQL statements) - making the whole process more abstract is one thing and simplifying some type classes is the other.
type classes like GenericQuery are there for two reasons:
to hide complicated constraints from the user, e.q. so that the type of the query consists of one constraint without any intermediate type parameters
overloading convenience
but the user should not be forced to use them
we should provide common query variations that could be used by current type classes and users directly. I've included examples that should illustrate my point
primGenericQuery∷∀sai.
GetColsi⇒String→-- query parameter placeholder, e.g. '$' for pg, and '?' for sqliteInt→-- first query parameter index, usually `1`-- both of these parameters determine how we generate query-- parameter names, e.g. '$1', '$2', ... for pg
(String→ArrayForeign→a) →FullQuerys { | i } →a
primGenericQuery ph i exec q = do-- transform Query AST `q` into a query string and query parameterslet { strQuery, params } = showM ph i $ showQuery q
-- execute the query with the parameters
exec strQuery params
pgPrimGenericQuery∷∀saim.
GetColsi⇒-- needed by query string generationMonadSeldaPGm⇒-- PG specific monad constraints
(ArrayForeign→ma) →-- generic decoder, errors are handled by monad `m`FullQuerys { | i } →-- query ASTm (Arraya) -- result rows of output records, record type `{ | o }` is determined by `i` via the type-function
pgPrimGenericQuery decodeRow = primGenericQuery "$"1 exec
where
exec strQuery params = do
conn ← ask
errOrResult ← liftAff $ PostgreSQL.unsafeQuery conn strQuery params
result ← either throwError pure errOrResult
traverse decodeRow result.rows
pgGenericQuery∷∀soim.
GetColsi⇒MapRUnCol_io⇒-- type-level function that maps over `{ | i }`-- and removes `Col s` from each record member-- thus `o` is now determined by the input `i`MonadSeldaPGm⇒
(ArrayForeign→m { | o }) →FullQuerys { | i } →m (Array { | o }) -- the additional constraint forces the-- appropriate result type
pgGenericQuery = pgPrimGenericQuery
The text was updated successfully, but these errors were encountered:
Copied from here:
The text was updated successfully, but these errors were encountered: