generic-persistence-0.2.0.0: Database persistence using generics
Safe HaskellSafe-Inferred
LanguageGHC2021

Database.GP.Entity

Synopsis

Documentation

class Data a => Entity a where Source #

Minimal complete definition

Nothing

Methods

fromRow :: [SqlValue] -> GP a Source #

Converts a database row to a value of type a.

default fromRow :: [SqlValue] -> GP a Source #

toRow :: a -> GP [SqlValue] Source #

Converts a value of type a to a database row.

default toRow :: a -> GP [SqlValue] Source #

idField :: a -> String Source #

Returns the name of the primary key field for a type a.

default idField :: a -> String Source #

fieldsToColumns :: a -> [(String, String)] Source #

Returns a list of tuples that map field names to column names for a type a.

default fieldsToColumns :: a -> [(String, String)] Source #

tableName :: a -> String Source #

Returns the name of the table for a type a.

default tableName :: a -> String Source #

columnNameFor :: Entity a => a -> String -> String Source #

A convenience function: returns the name of the column for a field of a type a.

fieldTypeFor :: Entity a => a -> String -> TypeRep Source #

A convenience function: returns the TypeRep of a field of a type a.

toString :: Entity a => a -> String Source #

Returns a string representation of a value of type a.

evidence :: forall a. Entity a => a Source #

A convenience function: returns an evidence instance of type a. This is useful for type inference where no instance is available.

evidenceFrom :: forall a. Entity a => TypeInfo a -> a Source #

type ResolutionCache = [(EntityId, Dynamic)] Source #

The resolution cache maps an EntityId to a Dynamic value (representing an Entity). It is used to resolve circular references during loading and storing of Entities.

type EntityId = (TypeRep, SqlValue) Source #

The EntityId is a tuple of the TypeRep and the primary key value of an Entity. It is used as a key in the resolution cache.

data Ctx Source #

type Ctx defines the context in which the persistence operations are executed. It contains a connection to the database and a resolution cache for circular lookups.

Constructors

Ctx 

Fields

type GP = RIO Ctx Source #