module Database.Selda
(
MonadIO (..), MonadSelda
, SeldaT, Table, Query, Col, Res, Result
, query, transaction, setLocalCache
, SqlType
, Text, Cols, Columns
, Order (..)
, (:*:)(..)
, select, selectValues
, restrict, limit, order
, ascending, descending
, (.==), (./=), (.>), (.<), (.>=), (.<=), like
, (.&&), (.||), not_
, literal, int, float, text, true, false, null_
, roundTo, length_, isNull
, round_, just, fromBool, fromInt, toString
, Aggr, Aggregates, OuterCols, JoinCols, Inner, MinMax
, leftJoin
, aggregate, groupBy
, count, avg, sum_, max_, min_
, Insert
, insert, insert_, insertWithPK, def
, update, update_
, deleteFrom, deleteFrom_
, ColSpec, TableName, ColName
, NonNull, IsNullable, Nullable, NotNullable
, table, (¤), required, optional
, primary, autoPrimary
, ComposeSpec, (:+++:), (+++)
, createTable, tryCreateTable
, dropTable, tryDropTable
, OnError (..)
, compile
, compileCreateTable, compileDropTable
, compileInsert, compileUpdate
, Tup, Head
, first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth
) where
import Data.Text (Text)
import Database.Selda.Backend
import Database.Selda.Column
import Database.Selda.Compile
import Database.Selda.Frontend
import Database.Selda.Inner
import Database.Selda.Query
import Database.Selda.Query.Type
import Database.Selda.SQL
import Database.Selda.SqlType
import Database.Selda.Table
import Database.Selda.Table.Compile
import Database.Selda.Types
import Database.Selda.Unsafe
import Control.Exception (throw)
class SqlType a => MinMax a
instance (SqlType a, Num a) => MinMax a
instance MinMax Text
instance MinMax a => MinMax (Maybe a)
(.==), (./=), (.>), (.<), (.>=), (.<=) :: SqlType a => Col s a -> Col s a -> Col s Bool
(.==) = liftC2 $ BinOp Eq
(./=) = liftC2 $ BinOp Neq
(.>) = liftC2 $ BinOp Gt
(.<) = liftC2 $ BinOp Lt
(.>=) = liftC2 $ BinOp Gte
(.<=) = liftC2 $ BinOp Lte
infixl 4 .==
infixl 4 .>
infixl 4 .<
infixl 4 .>=
infixl 4 .<=
isNull :: Col s (Maybe a) -> Col s Bool
isNull = liftC $ UnOp IsNull
(.&&), (.||) :: Col s Bool -> Col s Bool -> Col s Bool
(.&&) = liftC2 $ BinOp And
(.||) = liftC2 $ BinOp Or
infixr 3 .&&
infixr 2 .||
ascending, descending :: Order
ascending = Asc
descending = Desc
def :: SqlType a => a
def = throw DefaultValueException
just :: SqlType a => Col s a -> Col s (Maybe a)
just = cast
null_ :: SqlType a => Col s (Maybe a)
null_ = literal Nothing
int :: Int -> Col s Int
int = literal
float :: Double -> Col s Double
float = literal
text :: Text -> Col s Text
text = literal
true, false :: Col s Bool
true = literal True
false = literal False
like :: Col s Text -> Col s Text -> Col s Bool
like = liftC2 $ BinOp Like
infixl 4 `like`
count :: SqlType a => Col s a -> Aggr s Int
count = aggr "COUNT"
avg :: (SqlType a, Num a) => Col s a -> Aggr s a
avg = aggr "AVG"
max_ :: MinMax a => Col s a -> Aggr s a
max_ = aggr "MAX"
min_ :: MinMax a => Col s a -> Aggr s a
min_ = aggr "MIN"
sum_ :: (SqlType a, Num a) => Col s a -> Aggr s a
sum_ = aggr "SUM"
round_ :: Num a => Col s Double -> Col s a
round_ = fun "ROUND"
roundTo :: Col s Int -> Col s Double -> Col s Double
roundTo = flip $ fun2 "ROUND"
length_ :: Col s Text -> Col s Int
length_ = fun "LENGTH"
not_ :: Col s Bool -> Col s Bool
not_ = liftC $ UnOp Not
fromBool :: (SqlType a, Num a) => Col s Bool -> Col s a
fromBool = cast
fromInt :: (SqlType a, Num a) => Col s Int -> Col s a
fromInt = cast
toString :: Col s a -> Col s String
toString = cast