Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
-
class
PersistField
a =>
IsCol
a
where
- getSqlType :: Proxy a -> SqlColType
- newtype SqlColType = SqlColType Text
- toColType :: SqlType -> SqlColType
-
newtype
Primary
=
Primary
{
- getPrimary :: Int
- data Table (name :: Symbol ) = Table
- newtype Col (name :: Symbol ) a = Col a
- data a :. b = a :. b
-
class
IsRow
row
where
- getTableName :: Proxy row -> Text
- getColNames :: Proxy row -> [ Text ]
- getSqlTypes :: Proxy row -> [ SqlColType ]
- toSqlValues :: row -> [ PersistValue ]
- fromSqlValues :: [ PersistValue ] -> Either Text row
- data Query row
- callSql :: ( MonadIO m, IsRow row) => Query row -> SqlPersistT m [row]
- runSql :: MonadIO m => Query () -> SqlPersistT m ()
- createTable :: IsRow row => Proxy row -> Query ()
- selectAll :: forall row. IsRow row => Query row
- insertOne :: forall row. IsRow row => row -> Query ()
- repsertOne :: forall row. IsRow row => (row :. Col "id" Primary ) -> Query ()
- updateOne :: forall row. IsRow row => (row :. Col "id" Primary ) -> Query ()
- deleteAll :: forall row. IsRow row => Proxy row -> Query ()
- deleteOne :: forall row. IsRow row => Proxy row -> Col "id" Primary -> Query ()
- testPerson :: PersonRow
Synopsis
Typed database tables and rows.
Database columns
class PersistField a => IsCol a where Source #
Class of columns that can be stored in database tables.
getSqlType :: Proxy a -> SqlColType Source #
Instances
IsCol Int Source # | |
Defined in Database.Schema getSqlType :: Proxy Int -> SqlColType Source # |
|
( PersistField a, PersistFieldSql a) => IsCol a Source # | |
Defined in Database.Schema getSqlType :: Proxy a -> SqlColType Source # |
|
IsCol Primary Source # | |
Defined in Database.Schema getSqlType :: Proxy Primary -> SqlColType Source # |
|
IsCol ( Maybe Int ) Source # | |
Defined in Database.Schema getSqlType :: Proxy ( Maybe Int ) -> SqlColType Source # |
newtype SqlColType Source #
SQL column types, including constraints.
Values of type
SqlColType
represent SQL types such as
INTEGER PRIMARY KEY NOT NULL TEXT NOT NULL
Instances
Eq SqlColType Source # | |
Defined in Database.Schema (==) :: SqlColType -> SqlColType -> Bool Source # (/=) :: SqlColType -> SqlColType -> Bool Source # |
|
Ord SqlColType Source # | |
Defined in Database.Schema compare :: SqlColType -> SqlColType -> Ordering Source # (<) :: SqlColType -> SqlColType -> Bool Source # (<=) :: SqlColType -> SqlColType -> Bool Source # (>) :: SqlColType -> SqlColType -> Bool Source # (>=) :: SqlColType -> SqlColType -> Bool Source # max :: SqlColType -> SqlColType -> SqlColType Source # min :: SqlColType -> SqlColType -> SqlColType Source # |
|
Show SqlColType Source # | |
Defined in Database.Schema |
toColType :: SqlType -> SqlColType Source #
Helper for converting
SqlType
into an SQL column type with constraints.
Primary key.
Primary | |
|
Instances
Eq Primary Source # | |
Ord Primary Source # | |
Show Primary Source # | |
PersistField Primary Source # | |
Defined in Database.Schema toPersistValue :: Primary -> PersistValue Source # fromPersistValue :: PersistValue -> Either Text Primary Source # |
|
IsCol Primary Source # | |
Defined in Database.Schema getSqlType :: Proxy Primary -> SqlColType Source # |
Database rows and tables
data Table (name :: Symbol ) Source #
Named database table.
Instances
Eq ( Table name) Source # | |
Ord ( Table name) Source # | |
Defined in Database.Schema compare :: Table name -> Table name -> Ordering Source # (<) :: Table name -> Table name -> Bool Source # (<=) :: Table name -> Table name -> Bool Source # (>) :: Table name -> Table name -> Bool Source # (>=) :: Table name -> Table name -> Bool Source # |
|
Show ( Table name) Source # | |
KnownSymbol name => IsRow ( Table name) Source # | |
Defined in Database.Schema getTableName :: Proxy ( Table name) -> Text Source # getColNames :: Proxy ( Table name) -> [ Text ] Source # getSqlTypes :: Proxy ( Table name) -> [ SqlColType ] Source # toSqlValues :: Table name -> [ PersistValue ] Source # fromSqlValues :: [ PersistValue ] -> Either Text ( Table name) Source # |
newtype Col (name :: Symbol ) a Source #
Named database column.
Col a |
Instances
Eq a => Eq ( Col name a) Source # | |
Ord a => Ord ( Col name a) Source # | |
Defined in Database.Schema compare :: Col name a -> Col name a -> Ordering Source # (<) :: Col name a -> Col name a -> Bool Source # (<=) :: Col name a -> Col name a -> Bool Source # (>) :: Col name a -> Col name a -> Bool Source # (>=) :: Col name a -> Col name a -> Bool Source # |
|
Show a => Show ( Col name a) Source # | |
( IsRow row, KnownSymbol name, IsCol a) => IsRow (row :. Col name a) Source # | |
Defined in Database.Schema getTableName :: Proxy (row :. Col name a) -> Text Source # getColNames :: Proxy (row :. Col name a) -> [ Text ] Source # getSqlTypes :: Proxy (row :. Col name a) -> [ SqlColType ] Source # toSqlValues :: (row :. Col name a) -> [ PersistValue ] Source # fromSqlValues :: [ PersistValue ] -> Either Text (row :. Col name a) Source # |
Infix notation for a pair of types.
a :. b infixl 3 |
Instances
( Eq a, Eq b) => Eq (a :. b) Source # | |
( Ord a, Ord b) => Ord (a :. b) Source # | |
Defined in Database.Schema |
|
( Read a, Read b) => Read (a :. b) Source # | |
( Show a, Show b) => Show (a :. b) Source # | |
( IsRow row, KnownSymbol name, IsCol a) => IsRow (row :. Col name a) Source # | |
Defined in Database.Schema getTableName :: Proxy (row :. Col name a) -> Text Source # getColNames :: Proxy (row :. Col name a) -> [ Text ] Source # getSqlTypes :: Proxy (row :. Col name a) -> [ SqlColType ] Source # toSqlValues :: (row :. Col name a) -> [ PersistValue ] Source # fromSqlValues :: [ PersistValue ] -> Either Text (row :. Col name a) Source # |
class IsRow row where Source #
Class of row types that can be stored in database tables. Instances of this class are essentially lists of columns. Example:
type PersonRow = Table "person" :. Col "name" Text :. Col "age" Int
getTableName :: Proxy row -> Text Source #
getColNames :: Proxy row -> [ Text ] Source #
getSqlTypes :: Proxy row -> [ SqlColType ] Source #
toSqlValues :: row -> [ PersistValue ] Source #
fromSqlValues :: [ PersistValue ] -> Either Text row Source #
Instances
KnownSymbol name => IsRow ( Table name) Source # | |
Defined in Database.Schema getTableName :: Proxy ( Table name) -> Text Source # getColNames :: Proxy ( Table name) -> [ Text ] Source # getSqlTypes :: Proxy ( Table name) -> [ SqlColType ] Source # toSqlValues :: Table name -> [ PersistValue ] Source # fromSqlValues :: [ PersistValue ] -> Either Text ( Table name) Source # |
|
( IsRow row, KnownSymbol name, IsCol a) => IsRow (row :. Col name a) Source # | |
Defined in Database.Schema getTableName :: Proxy (row :. Col name a) -> Text Source # getColNames :: Proxy (row :. Col name a) -> [ Text ] Source # getSqlTypes :: Proxy (row :. Col name a) -> [ SqlColType ] Source # toSqlValues :: (row :. Col name a) -> [ PersistValue ] Source # fromSqlValues :: [ PersistValue ] -> Either Text (row :. Col name a) Source # |
SQL Queries
An SQL query that returns a list of values of type
row
.
callSql :: ( MonadIO m, IsRow row) => Query row -> SqlPersistT m [row] Source #
Run an SQL query and return a list of rows as result.
runSql :: MonadIO m => Query () -> SqlPersistT m () Source #
Execute an SQL query, but do not return any results
createTable :: IsRow row => Proxy row -> Query () Source #
Create a database table that can store the given rows.
insertOne :: forall row. IsRow row => row -> Query () Source #
Insert a single row into the corresponding table.
repsertOne :: forall row. IsRow row => (row :. Col "id" Primary ) -> Query () Source #
Replace or insert a single row with a primary key into a database.
FIXME: It would be nicer if the "id" column was the first column instead of the last column in the table.
updateOne :: forall row. IsRow row => (row :. Col "id" Primary ) -> Query () Source #
Update one row with a given "id" column in a database table.
deleteAll :: forall row. IsRow row => Proxy row -> Query () Source #
Delete all rows in a database table
deleteOne :: forall row. IsRow row => Proxy row -> Col "id" Primary -> Query () Source #
Delete one row with a given "id" column in a database table.
Testing
testPerson :: PersonRow Source #