| Copyright | © Clément Delafargue 2018 Théophile Choutri 2021 |
|---|---|
| License | MIT |
| Maintainer | theophile@choutri.eu |
| Stability | stable |
| Safe Haskell | None |
| Language | Haskell2010 |
Database.PostgreSQL.Entity.Types
Description
Types and classes
Synopsis
- class Entity e where
- data Field
- field :: QuasiQuoter
- fieldName :: Field -> Text
- fieldType :: Field -> Maybe Text
- newtype UpdateRow a = UpdateRow {
- getUpdate :: a
- data Options = Options {
- tableNameModifier :: Text -> Text
- primaryKeyModifier :: Text -> Text
- fieldModifier :: Text -> Text
- defaultEntityOptions :: Options
- newtype GenericEntity t e = GenericEntity {
- getGenericEntity :: e
- class EntityOptions xs where
- data PrimaryKey t
- data TableName t
The Entity Typeclass
An Entity stores the following information about the structure of a database table:
- Its name
- Its primary key
- The fields it contains
Example
data ExampleEntity = E
{ key :: Key
, field1 :: Int
, field2 :: Bool
}
deriving stock (Eq, Show, Generic)
deriving anyclass (FromRow, ToRow)
deriving Entity
via (GenericEntity '[TableName "entities"] ExampleEntity)When using the functions provided by this library, you will sometimes need to be explicit about the Entity you are referring to.
Since: 0.0.1.0
Minimal complete definition
Nothing
Methods
The name of the table in the PostgreSQL database.
primaryKey :: Field Source #
The name of the primary key for the table.
default primaryKey :: GetFields (Rep e) => Field Source #
fields :: Vector Field Source #
The fields of the table.
Associated Types
A wrapper for table fields.
Since: 0.0.1.0
field :: QuasiQuoter Source #
A quasi-quoter for safely constructing Fields.
Example:
instance Entity BlogPost where
tableName = "blogposts"
primaryKey = [field| blogpost_id |]
fields = [ [field| blogpost_id |]
, [field| author_id |]
, [field| uuid_list :: uuid[] |] -- ← This is where we specify an optional PostgreSQL type annotation
, [field| title |]
, [field| content |]
, [field| created_at |]
]Since: 0.1.0.0
Wrapper used by the update function in order to have the primary key as the last parameter passed, since it appears in the WHERE clause.
Since: 0.0.1.0
Generics
Term-level options
Constructors
| Options | |
Fields
| |
DerivingVia Options
newtype GenericEntity t e Source #
Constructors
| GenericEntity | |
Fields
| |
class EntityOptions xs where Source #
Type-level options for Deriving Via
Methods
Instances
| EntityOptions ('[] :: [k]) Source # | |
Defined in Database.PostgreSQL.Entity.Types Methods | |
| (GetName name, EntityOptions xs) => EntityOptions (PrimaryKey name ': xs :: [Type]) Source # | |
Defined in Database.PostgreSQL.Entity.Types Methods | |
| (GetName name, EntityOptions xs) => EntityOptions (TableName name ': xs :: [Type]) Source # | |
Defined in Database.PostgreSQL.Entity.Types Methods | |
data PrimaryKey t Source #
Instances
| (GetName name, EntityOptions xs) => EntityOptions (PrimaryKey name ': xs :: [Type]) Source # | |
Defined in Database.PostgreSQL.Entity.Types Methods | |
Instances
| (GetName name, EntityOptions xs) => EntityOptions (TableName name ': xs :: [Type]) Source # | |
Defined in Database.PostgreSQL.Entity.Types Methods | |