| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
IHP.TypedSql
Synopsis
- typedSql :: QuasiQuoter
- typedSqlStar :: QuasiQuoter
- data TypedQuery result = TypedQuery {
- tqSnippet :: !Snippet
- tqResultDecoder :: !(Row result)
- sqlQueryTyped :: (?modelContext :: ModelContext) => TypedQuery result -> IO [result]
- sqlExecTyped :: (?modelContext :: ModelContext) => TypedQuery result -> IO Int64
Documentation
typedSql :: QuasiQuoter Source #
QuasiQuoter entry point for typed SQL.
Disallows SELECT * and SELECT table.* by default to prevent production errors
when the schema changes. Use typedSqlStar to opt in to star selects.
typedSqlStar :: QuasiQuoter Source #
Like typedSql but allows SELECT * and SELECT table.* patterns.
Use this when you understand that star selects can break at runtime if the
schema changes between compilation and deployment.
data TypedQuery result Source #
Prepared query with a custom row parser. High-level: this is the runtime value produced by the typed SQL quasiquoter.
Constructors
| TypedQuery | |
Fields
| |
sqlQueryTyped :: (?modelContext :: ModelContext) => TypedQuery result -> IO [result] Source #
Run a typed SELECT query and return all result rows.
Also works with INSERT/UPDATE/DELETE ... RETURNING statements that return rows.
users <- sqlQueryTyped [typedSql| SELECT name FROM users |]
newIds <- sqlQueryTyped [typedSql| INSERT INTO items (name) VALUES (${name}) RETURNING id |]sqlExecTyped :: (?modelContext :: ModelContext) => TypedQuery result -> IO Int64 Source #
Run a typed statement (INSERT/UPDATE/DELETE) and return the affected row count.
Use sqlQueryTyped instead if your statement has a RETURNING clause.
rowsAffected <- sqlExecTyped [typedSql| DELETE FROM items WHERE id = ${itemId} |]