selda-0.5.1.0: Multi-backend, high-level EDSL for interacting with SQL databases.

Safe HaskellNone
LanguageHaskell2010

Database.Selda.Unsafe

Description

Unsafe operations giving the user unchecked low-level control over the generated SQL.

Synopsis

Documentation

fun :: Text -> Col s a -> Col s b Source #

A unary operation. Note that the provided function name is spliced directly into the resulting SQL query. Thus, this function should ONLY be used to implement well-defined functions that are missing from Selda's standard library, and NOT in an ad hoc manner during queries.

fun2 :: Text -> Col s a -> Col s b -> Col s c Source #

Like fun, but with two arguments.

fun0 :: Text -> Col s a Source #

Like fun, but with zero arguments.

operator :: Text -> Col s a -> Col s b -> Col s c Source #

A custom operator. operator "~>" a b will compile down to a ~> b, with parentheses around a and b iff they are not atomic. This means that SQL operator precedence is disregarded, as all subexpressions are parenthesized. In the following example for instance, foo a b c will compile down to (a ~> b) ~> c.

(~>) = operator "~>"
infixl 5 ~>
foo a b c = a ~> b ~> c

aggr :: SqlType a => Text -> Col s a -> Aggr s b Source #

Create a named aggregate function. Like fun, this function is generally unsafe and should ONLY be used to implement missing backend-specific functionality.

cast :: forall s a b. SqlType b => Col s a -> Col s b Source #

Cast a column to another type, using whichever coercion semantics are used by the underlying SQL implementation.

castAggr :: forall s a b. SqlType b => Aggr s a -> Aggr s b Source #

Cast an aggregate to another type, using whichever coercion semantics are used by the underlying SQL implementation.

sink :: (f s a -> f s b) -> f (Inner s) a -> f (Inner s) b Source #

Sink the given function into an inner scope.

Be careful not to use this function with functions capturing rows or columns from an outer scope. For instance, the following usage will likely lead to disaster:

query $ do
  x <- #age `from` select person
  inner $ sink (\p -> x + (p ! #age)) <$> select person

Really, if you have to use this function, ONLY do so in the global scope.

sink2 :: (f s a -> f s b -> f s c) -> f (Inner s) a -> f (Inner s) b -> f (Inner s) c Source #

Like sink, but with two arguments.

unsafeSelector :: (SqlRow a, SqlType b) => Int -> Selector a b Source #

A selector indicating the nth (zero-based) column of a table.

Will cause errors in queries during compilation, execution, or both, unless handled with extreme care. You really shouldn't use it at all.

inj :: Col s a -> QueryFragment Source #

Create a raw SQL query fragment from the given column.

injLit :: SqlType a => a -> QueryFragment Source #

Create a raw SQL query fragment from the given value.

rawName :: SqlType a => ColName -> Col s a Source #

Create a column referring to a name of your choice. Use this to refer to variables not exposed by Selda.

rawExp :: SqlType a => Text -> Col s a Source #

Create an expression from the given text. The expression will be inserted verbatim into your query, so you should NEVER pass user-provided text to this function.

rawStm :: MonadSelda m => QueryFragment -> m () Source #

Execute a raw SQL statement.

rawQuery :: forall a s. SqlRow a => [ColName] -> QueryFragment -> Query s (Row s a) Source #

Execute a raw SQL statement, returning a row consisting of columns by the given names. Will fail if the number of names given does not match up with the type of the returned row. Will generate invalid SQL if the given names don't match up with the column names in the given query.

rawQuery1 :: SqlType a => ColName -> QueryFragment -> Query s (Col s a) Source #

As rawQuery, but returns only a single column. Same warnings still apply.