orville-postgresql-1.0.0.0: A Haskell library for PostgreSQL
CopyrightFlipstone Technology Partners 2023
LicenseMIT
StabilityStable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Orville.PostgreSQL.Execution.EntityOperations

Description

Entry-level functions for executing based CRUD operations on entity tables. These are the functions that you will use most often for interacting with tables.

Since: 1.0.0.0

Synopsis

Documentation

insertEntity :: MonadOrville m => TableDefinition key writeEntity readEntity -> writeEntity -> m () Source #

Inserts an entity into the specified table.

Since: 1.0.0.0

insertEntityAndReturnRowCount :: MonadOrville m => TableDefinition key writeEntity readEntity -> writeEntity -> m Int Source #

Inserts an entity into the specified table. Returns the number of rows affected by the query.

Since: 1.0.0.0

insertAndReturnEntity :: MonadOrville m => TableDefinition key writeEntity readEntity -> writeEntity -> m readEntity Source #

Inserts an entity into the specified table, returning the data inserted into the database.

You can use this function to obtain any column values filled in by the database, such as auto-incrementing ids.

Since: 1.0.0.0

insertEntities :: MonadOrville m => TableDefinition key writeEntity readEntity -> NonEmpty writeEntity -> m () Source #

Inserts a non-empty list of entities into the specified table.

Since: 1.0.0.0

insertAndReturnEntities :: MonadOrville m => TableDefinition key writeEntity readEntity -> NonEmpty writeEntity -> m [readEntity] Source #

Inserts a non-empty list of entities into the specified table, returning the data that was inserted into the database.

You can use this function to obtain any column values filled in by the database, such as auto-incrementing ids.

Since: 1.0.0.0

insertEntitiesAndReturnRowCount :: MonadOrville m => TableDefinition key writeEntity readEntity -> NonEmpty writeEntity -> m Int Source #

Inserts a non-empty list of entities into the specified table. Returns the number of rows affected by the query.

Since: 1.0.0.0

updateEntity :: MonadOrville m => TableDefinition (HasKey key) writeEntity readEntity -> key -> writeEntity -> m () Source #

Updates the row with the given key with the data given by writeEntity.

Since: 1.0.0.0

updateEntityAndReturnRowCount :: MonadOrville m => TableDefinition (HasKey key) writeEntity readEntity -> key -> writeEntity -> m Int Source #

Updates the row with the given key with the data given by writeEntity. Returns the number of rows affected by the query.

Since: 1.0.0.0

updateAndReturnEntity :: MonadOrville m => TableDefinition (HasKey key) writeEntity readEntity -> key -> writeEntity -> m (Maybe readEntity) Source #

Updates the row with the given key with the data given by writeEntity, returning the updated row from the database. If no row matches the given key, Nothing will be returned.

You can use this function to obtain any column values computed by the database during the update, including columns with triggers attached to them.

Since: 1.0.0.0

updateFields :: MonadOrville m => TableDefinition (HasKey key) writeEntity readEntity -> NonEmpty SetClause -> Maybe BooleanExpr -> m () Source #

Applies the given SetClauses to the rows in the table that match the given where condition. The easiest way to construct a SetClause is via the setField function (also exported as .:=).

Since: 1.0.0.0

updateFieldsAndReturnEntities :: MonadOrville m => TableDefinition (HasKey key) writeEntity readEntity -> NonEmpty SetClause -> Maybe BooleanExpr -> m [readEntity] Source #

Like updateFields, but uses a RETURNING clause to return the updated version of any rows that were affected by the update.

Since: 1.0.0.0

updateFieldsAndReturnRowCount :: MonadOrville m => TableDefinition (HasKey key) writeEntity readEntity -> NonEmpty SetClause -> Maybe BooleanExpr -> m Int Source #

Applies the given SetClauses to the rows in the table that match the given where condition. The easiest way to construct a SetClause is via the setField function (also exported as .:=). Returns the number of rows affected by the query.

Since: 1.0.0.0

deleteEntity :: MonadOrville m => TableDefinition (HasKey key) writeEntity readEntity -> key -> m () Source #

Deletes the row with the given key.

Since: 1.0.0.0

deleteEntityAndReturnRowCount :: MonadOrville m => TableDefinition (HasKey key) writeEntity readEntity -> key -> m Int Source #

Deletes the row with the given key. Returns the number of rows affected by the query.

Since: 1.0.0.0

deleteAndReturnEntity :: MonadOrville m => TableDefinition (HasKey key) writeEntity readEntity -> key -> m (Maybe readEntity) Source #

Deletes the row with the given key, returning the row that was deleted. If no row matches the given key, Nothing is returned.

Since: 1.0.0.0

deleteEntities :: MonadOrville m => TableDefinition key writeEntity readEntity -> Maybe BooleanExpr -> m () Source #

Deletes all rows in the given table that match the where condition.

Since: 1.0.0.0

deleteEntitiesAndReturnRowCount :: MonadOrville m => TableDefinition key writeEntity readEntity -> Maybe BooleanExpr -> m Int Source #

Deletes all rows in the given table that match the where condition. Returns the number of rows affected by the query.

Since: 1.0.0.0

deleteAndReturnEntities :: MonadOrville m => TableDefinition key writeEntity readEntity -> Maybe BooleanExpr -> m [readEntity] Source #

Deletes all rows in the given table that match the where condition, returning the rows that were deleted.

Since: 1.0.0.0

findEntitiesBy :: MonadOrville m => TableDefinition key writeEntity readEntity -> SelectOptions -> m [readEntity] Source #

Finds all the entities in the given table according to the specified SelectOptions, which may include where conditions to match, ordering specifications, etc.

Since: 1.0.0.0

findFirstEntityBy :: MonadOrville m => TableDefinition key writeEntity readEntity -> SelectOptions -> m (Maybe readEntity) Source #

Like findEntitiesBy, but adds a 'LIMIT 1' to the query and then returns the first item from the list. Usually when you use this you will want to provide an order by clause in the SelectOptions because the database will not guarantee ordering.

Since: 1.0.0.0

findEntity :: MonadOrville m => TableDefinition (HasKey key) writeEntity readEntity -> key -> m (Maybe readEntity) Source #

Finds a single entity by the table's primary key value.

Since: 1.0.0.0

findEntities :: MonadOrville m => TableDefinition (HasKey key) writeEntity readEntity -> NonEmpty key -> m [readEntity] Source #

Finds multiple entities by the table's primary key.

Since: 1.0.0.0