Moduleselda-0.5.2.1Haskell2010
Database.Selda.Backend.Internal
Internal backend API. Using anything exported from this module may or may not invalidate any safety guarantees made by Selda; use at your own peril.
- 18 types
- 2 classes
- 14 values
- Packageselda-0.5.2.1
- Exports34
- LanguageHaskell2010
- LicenceMIT
- SourceInternal.hs
Uniquely identifies some particular backend.
When publishing a new backend, consider submitting a pull request with a
constructor for your backend instead of using the Other constructor.
Constructors
A function which executes a query and gives back a list of extensible tuples; one tuple per result row, and one tuple element per column.
A collection of functions making up a Selda backend.
Constructors
SeldaBackendrunStmt :: Text -> [Param] -> IO (Int, [[SqlValue]])Execute an SQL statement.
runStmtWithPK :: Text -> [Param] -> IO Int64Execute an SQL statement and return the last inserted primary key, where the primary key is auto-incrementing. Backends must take special care to make this thread-safe.
prepareStmt :: StmtID -> [SqlTypeRep] -> Text -> IO DynamicPrepare a statement using the given statement identifier.
runPrepared :: Dynamic -> [Param] -> IO (Int, [[SqlValue]])Execute a prepared statement.
getTableInfo :: TableName -> IO TableInfoGet a list of all columns in the given table, with the type and any modifiers for each column. Return an empty list if the given table does not exist.
ppConfig :: PPConfigSQL pretty-printer configuration.
closeConnection :: SeldaConnection b -> IO ()Close the currently open connection.
backendId :: BackendIDUnique identifier for this backend.
disableForeignKeys :: Bool -> IO ()Turn on or off foreign key checking, and initiate/commit a transaction.
When implementing this function, it is safe to assume that
disableForeignKeys Truewill always be called exactly once before eachdisableForeignKeys False.
Constructors
SeldaConnectionconnBackend :: !SeldaBackend bThe backend used by the current connection.
connDbId :: TextA string uniquely identifying the database used by this connection. This could be, for instance, a PostgreSQL connection string or the absolute path to an SQLite file.
connStmts :: !IORef (IntMap SeldaStmt)All statements prepared for this connection.
connClosed :: !IORef BoolIs the connection closed?
connLock :: !MVar ()Lock to prevent this connection from being used concurrently by multiple invocations of runSeldaT.
A prepared statement.
Constructors
SeldaStmtstmtHandle :: !DynamicBackend-specific handle to the prepared statement.
stmtText :: !TextThe SQL code for the statement.
stmtParams :: ![Either Int Param]All parameters to be passed to the prepared statement. Parameters that are unique to each invocation are specified as indices starting at 0. Backends implementing
runPreparedshould probably ignore this field.
Some monad with Selda SQL capabilitites.
Methods
withConnection :: (SeldaConnection (Backend m) -> m a) -> m aPass a Selda connection to the given computation and execute it. After the computation finishes,
withConnectionis free to do anything it likes to the connection, including closing it or giving it to another Selda computation. Thus, the computation must take care never to return or otherwise access the connection after returning.transact :: m a -> m aPerform the given computation as a transaction. Implementations must ensure that subsequent calls to withConnection within the same transaction always passes the same connection to its argument.
Instances1MonadSelda
(MonadIO m, MonadMask m) => MonadSelda (SeldaT b m)Defined in selda-0.5.2.1 · Database.Selda.Backend.Internal
Monad transformer adding Selda SQL capabilities.
Constructors
SunS :: ReaderT (SeldaConnection b) m a
Instances11MonadTrans, Monad, Functor, MonadFail, Applicative, MonadIO, …
MonadTrans (SeldaT b)Defined in selda-0.5.2.1 · Database.Selda.Backend.InternalMonad m => Monad (SeldaT b m)Defined in selda-0.5.2.1 · Database.Selda.Backend.InternalFunctor m => Functor (SeldaT b m)Defined in selda-0.5.2.1 · Database.Selda.Backend.InternalMonadFail m => MonadFail (SeldaT b m)Defined in selda-0.5.2.1 · Database.Selda.Backend.InternalApplicative m => Applicative (SeldaT b m)Defined in selda-0.5.2.1 · Database.Selda.Backend.InternalMonadIO m => MonadIO (SeldaT b m)Defined in selda-0.5.2.1 · Database.Selda.Backend.InternalMonadCatch m => MonadCatch (SeldaT b m)Defined in selda-0.5.2.1 · Database.Selda.Backend.InternalMonadMask m => MonadMask (SeldaT b m)Defined in selda-0.5.2.1 · Database.Selda.Backend.InternalMonadThrow m => MonadThrow (SeldaT b m)Defined in selda-0.5.2.1 · Database.Selda.Backend.Internal(MonadIO m, MonadMask m) => MonadSelda (SeldaT b m)Defined in selda-0.5.2.1 · Database.Selda.Backend.Internaltype Backend (SeldaT b m) = bDefined in selda-0.5.2.1 · Database.Selda.Backend.Internal
Thrown by any function in SeldaT if an error occurs.
Instances3Eq, Show, Exception
Eq SeldaErrorDefined in selda-0.5.2.1 · Database.Selda.Backend.InternalShow SeldaErrorDefined in selda-0.5.2.1 · Database.Selda.Backend.InternalException SeldaErrorDefined in selda-0.5.2.1 · Database.Selda.Backend.Internal
An SQL literal.
Constructors
LText :: !Text -> Lit TextLInt32 :: !Int32 -> Lit Int32LInt64 :: !Int64 -> Lit Int64LDouble :: !Double -> Lit DoubleLBool :: !Bool -> Lit BoolLDateTime :: !UTCTime -> Lit UTCTimeLDate :: !Day -> Lit DayLTime :: !TimeOfDay -> Lit TimeOfDayLJust :: SqlType a1 => !Lit a1 -> Lit (Maybe a1)LBlob :: !ByteString -> Lit ByteStringLNull :: SqlType a1 => Lit (Maybe a1)LCustom :: SqlTypeRep -> Lit a1 -> Lit aLUUID :: !UUID -> Lit UUID
Column attributes such as nullability, auto increment, etc. When adding elements, make sure that they are added in the order required by SQL syntax, as this list is only sorted before being pretty-printed.
Instances3Eq, Ord, Show
Eq AutoIncTypeDefined in selda-0.5.2.1 · Database.Selda.Table.TypeOrd AutoIncTypeDefined in selda-0.5.2.1 · Database.Selda.Table.TypeShow AutoIncTypeDefined in selda-0.5.2.1 · Database.Selda.Table.Type
Any datatype representable in (Selda's subset of) SQL.
Methods
mkLit :: a -> Lit aCreate a literal of this type.
sqlType :: Proxy a -> SqlTypeRepThe SQL representation for this type.
fromSql :: SqlValue -> aConvert an SqlValue into this type.
defaultValue :: Lit aDefault value when using
defat this type.
Instances19SqlType, …
SqlType ByteStringDefined in selda-0.5.2.1 · Database.Selda.SqlTypeSqlType ByteStringDefined in selda-0.5.2.1 · Database.Selda.SqlTypeSqlType Int32Defined in selda-0.5.2.1 · Database.Selda.SqlTypeSqlType Int64Defined in selda-0.5.2.1 · Database.Selda.SqlTypeSqlType BoolDefined in selda-0.5.2.1 · Database.Selda.SqlTypeSqlType DoubleDefined in selda-0.5.2.1 · Database.Selda.SqlTypeSqlType IntDefined in selda-0.5.2.1 · Database.Selda.SqlTypeSqlType OrderingDefined in selda-0.5.2.1 · Database.Selda.SqlTypeSqlType RowIDDefined in selda-0.5.2.1 · Database.Selda.SqlTypeSqlType TextDefined in selda-0.5.2.1 · Database.Selda.SqlTypeSqlType TextDefined in selda-0.5.2.1 · Database.Selda.SqlTypeSqlType DayDefined in selda-0.5.2.1 · Database.Selda.SqlTypeSqlType UTCTimeDefined in selda-0.5.2.1 · Database.Selda.SqlTypeSqlType TimeOfDayDefined in selda-0.5.2.1 · Database.Selda.SqlTypeSqlType UUIDDefined in selda-0.5.2.1 · Database.Selda.SqlTypedefaultValuefor UUIDs is the all-zero RFC4122 nil UUID.Typeable a => SqlType (ID a)Defined in selda-0.5.2.1 · Database.Selda.SqlTypeTypeable a => SqlType (UUID' a)Defined in selda-0.5.2.1 · Database.Selda.SqlTypedefaultValuefor UUIDs is the all-zero RFC4122 nil UUID.SqlType a => SqlType (Maybe a)Defined in selda-0.5.2.1 · Database.Selda.SqlType(TypeError ((('TextDefined in selda-0.5.2.1 · Database.Selda"'Only "
':<>: 'ShowType a) ':<>: 'Text"' is not a proper SQL type."
) ':$$: 'Text"Use 'the' to access the value of the column."
), Typeable a) => SqlType (Only a)
Some value that is representable in SQL.
Constructors
Instances3Eq, Ord, Show
Eq SqlTypeRepDefined in selda-0.5.2.1 · Database.Selda.SqlTypeOrd SqlTypeRepDefined in selda-0.5.2.1 · Database.Selda.SqlTypeShow SqlTypeRepDefined in selda-0.5.2.1 · Database.Selda.SqlType
Backend-specific configuration for the SQL pretty-printer.
Constructors
PPConfigppType :: SqlTypeRep -> TextThe SQL type name of the given type.
This function should be used everywhere a type is needed to be printed but in primary keys position. This is due to the fact that some backends might have a special representation of primary keys (using sequences are such). If you have such a need, please use the ppTypePK record instead.
ppTypeHook :: SqlTypeRep -> [ColAttr] -> (SqlTypeRep -> Text) -> TextHook that allows you to modify ppType output.
ppTypePK :: SqlTypeRep -> TextThe SQL type name of the given type for primary keys uses.
ppPlaceholder :: Int -> TextParameter placeholder for the
nth parameter.ppColAttrs :: [ColAttr] -> TextList of column attributes.
ppColAttrsHook :: SqlTypeRep -> [ColAttr] -> ([ColAttr] -> Text) -> TextHook that allows you to modify ppColAttrs output.
ppAutoIncInsert :: TextThe value used for the next value for an auto-incrementing column. For instance,
DEFAULTfor PostgreSQL, andNULLfor SQLite.ppMaxInsertParams :: Maybe IntInsert queries may have at most this many parameters; if an insertion has more parameters than this, it will be chunked.
Note that only insertions of multiple rows are chunked. If your table has more than this many columns, you should really rethink your database design.
ppIndexMethodHook :: IndexMethod -> TextCREATE INDEXsuffix to indicate that the index should use the given index method.
Default settings for pretty-printing. Geared towards SQLite.
The default definition of ppTypePK is 'defType, so that you don’t have to do anything special if you don’t use special types for primary keys.
Comprehensive information about a table.
Constructors
TableInfotableInfoName :: TableNameName of the table.
tableColumnInfos :: [ColumnInfo]Ordered information about each table column.
tableUniqueGroups :: [[ColName]]Unordered list of all (non-PK) uniqueness constraints on this table.
tablePrimaryKey :: [ColName]Unordered list of all primary key constraints on this table.
Comprehensive information about a column.
Constructors
ColumnInfocolName :: ColNameName of the column.
colType :: Either Text SqlTypeRepSelda type of the column, or the type name given by the database if Selda couldn't make sense of the type.
colIsAutoPrimary :: BoolIs the given column auto-incrementing?
colIsNullable :: BoolCan the column be NULL?
colHasIndex :: BoolIs the column explicitly indexed (i.e. using
indexed)?colFKs :: [(TableName, ColName)]Any foreign key (table, column) pairs referenced by this column.
Instances2Eq, Show
Eq ColumnInfoDefined in selda-0.5.2.1 · Database.Selda.Backend.InternalShow ColumnInfoDefined in selda-0.5.2.1 · Database.Selda.Backend.Internal
Get the column information for each column in the given table.
Convert a ColInfo into a ColumnInfo.
Format string used to represent date and time when representing timestamps as text. If at all possible, use SqlUTCTime instead.
Format string used to represent date when representing dates as text. If at all possible, use SqlDate instead.
Format string used to represent time of day when representing time as text. If at all possible, use SqlTime instead.
Generate a fresh statement identifier, guaranteed to be unique per process.
Create a new Selda connection for the given backend and database identifier string.
Get all statements and their corresponding identifiers for the current connection.
Run a Selda transformer. Backends should use this to implement their
withX functions.
Get the backend in use by the computation.