pg-entity-0.0.4.1: A pleasant PostgreSQL layer
Copyright© Clément Delafargue 2018
Théophile Choutri 2021
LicenseMIT
Maintainertheophile@choutri.eu
Stabilitystable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Database.PostgreSQL.Entity.Types

Description

Types and classes

Synopsis

The Entity Typeclass

class Entity e where Source #

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

tableName :: Text Source #

The name of the table in the PostgreSQL database.

default tableName :: GetTableName (Rep e) => Text Source #

schema :: Maybe Text Source #

The name of the schema; will be appended to the table name: schema."tablename"

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.

default fields :: GetFields (Rep e) => Vector Field Source #

Associated Types

data Field Source #

A wrapper for table fields.

Since: 0.0.1.0

Instances

Instances details
ForbiddenIsString => IsString Field Source #

Using the Overloaded String syntax for Field names is forbidden.

Instance details

Defined in Database.PostgreSQL.Entity.Internal.Unsafe

Methods

fromString :: String -> Field #

Show Field Source # 
Instance details

Defined in Database.PostgreSQL.Entity.Internal.Unsafe

Methods

showsPrec :: Int -> Field -> ShowS #

show :: Field -> String #

showList :: [Field] -> ShowS #

Eq Field Source # 
Instance details

Defined in Database.PostgreSQL.Entity.Internal.Unsafe

Methods

(==) :: Field -> Field -> Bool #

(/=) :: Field -> Field -> Bool #

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

fieldName :: Field -> Text Source #

Get the name of a field.

Since: 0.1.0.0

fieldType :: Field -> Maybe Text Source #

Get the type of a field, if any.

Since: 0.1.0.0

newtype UpdateRow a Source #

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

Constructors

UpdateRow 

Fields

Instances

Instances details
Show a => Show (UpdateRow a) Source # 
Instance details

Defined in Database.PostgreSQL.Entity.Types

Eq a => Eq (UpdateRow a) Source # 
Instance details

Defined in Database.PostgreSQL.Entity.Types

Methods

(==) :: UpdateRow a -> UpdateRow a -> Bool #

(/=) :: UpdateRow a -> UpdateRow a -> Bool #

Entity a => Entity (UpdateRow a) Source # 
Instance details

Defined in Database.PostgreSQL.Entity.Types

ToRow a => ToRow (UpdateRow a) Source # 
Instance details

Defined in Database.PostgreSQL.Entity.Types

Methods

toRow :: UpdateRow a -> [Action] #

Generics

data Options Source #

Term-level options

DerivingVia Options

newtype GenericEntity t e Source #

Constructors

GenericEntity 

Fields

Instances

Instances details
(EntityOptions t, GetTableName (Rep e), GetFields (Rep e)) => Entity (GenericEntity t e) Source # 
Instance details

Defined in Database.PostgreSQL.Entity.Types

class EntityOptions xs where Source #

Type-level options for Deriving Via

Instances

Instances details
EntityOptions ('[] :: [k]) Source # 
Instance details

Defined in Database.PostgreSQL.Entity.Types

(TextModifier mods, EntityOptions xs) => EntityOptions (FieldModifiers mods ': xs :: [Type]) Source # 
Instance details

Defined in Database.PostgreSQL.Entity.Types

(GetName name, EntityOptions xs) => EntityOptions (PrimaryKey name ': xs :: [Type]) Source # 
Instance details

Defined in Database.PostgreSQL.Entity.Types

(GetName name, EntityOptions xs) => EntityOptions (Schema name ': xs :: [Type]) Source # 
Instance details

Defined in Database.PostgreSQL.Entity.Types

(GetName name, EntityOptions xs) => EntityOptions (TableName name ': xs :: [Type]) Source # 
Instance details

Defined in Database.PostgreSQL.Entity.Types

data PrimaryKey (t :: Symbol) Source #

Instances

Instances details
(GetName name, EntityOptions xs) => EntityOptions (PrimaryKey name ': xs :: [Type]) Source # 
Instance details

Defined in Database.PostgreSQL.Entity.Types

data Schema (t :: Symbol) Source #

Instances

Instances details
(GetName name, EntityOptions xs) => EntityOptions (Schema name ': xs :: [Type]) Source # 
Instance details

Defined in Database.PostgreSQL.Entity.Types

data TableName (t :: Symbol) Source #

Instances

Instances details
(GetName name, EntityOptions xs) => EntityOptions (TableName name ': xs :: [Type]) Source # 
Instance details

Defined in Database.PostgreSQL.Entity.Types

data FieldModifiers ms Source #

Contains a list of TextModifiers modifiers

Instances

Instances details
(TextModifier mods, EntityOptions xs) => EntityOptions (FieldModifiers mods ': xs :: [Type]) Source # 
Instance details

Defined in Database.PostgreSQL.Entity.Types

class TextModifier t where Source #

The modifiers that you can apply to the fields:

Instances

Instances details
(KnownSymbol separator, NonEmptyText separator) => TextModifier (CamelTo separator :: Type) Source # 
Instance details

Defined in Database.PostgreSQL.Entity.Types

KnownSymbol prefix => TextModifier (StripPrefix prefix :: Type) Source # 
Instance details

Defined in Database.PostgreSQL.Entity.Types

TextModifier ('[] :: [k]) Source # 
Instance details

Defined in Database.PostgreSQL.Entity.Types

(TextModifier x, TextModifier xs) => TextModifier (x ': xs :: [a]) Source # 
Instance details

Defined in Database.PostgreSQL.Entity.Types

data StripPrefix (prefix :: Symbol) Source #

TextModifier to remove a certain prefix from the fields

Instances

Instances details
KnownSymbol prefix => TextModifier (StripPrefix prefix :: Type) Source # 
Instance details

Defined in Database.PostgreSQL.Entity.Types

data CamelTo (separator :: Symbol) Source #

FieldModifier taking a separator Char when transforming from CamelCase.

Instances

Instances details
(KnownSymbol separator, NonEmptyText separator) => TextModifier (CamelTo separator :: Type) Source # 
Instance details

Defined in Database.PostgreSQL.Entity.Types

type CamelToSnake = CamelTo "_" Source #

CamelCase to snake_case

type CamelToKebab = CamelTo "-" Source #

CamelCase to kebab-case