Copyright | Flipstone Technology Partners 2023 |
---|---|
License | MIT |
Stability | Stable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Since: 1.0.0.0
Synopsis
- data TableDefinition key writeEntity readEntity
- data HasKey key
- data NoKey
- mkTableDefinition :: String -> PrimaryKey key -> SqlMarshaller writeEntity readEntity -> TableDefinition (HasKey key) writeEntity readEntity
- mkTableDefinitionWithoutKey :: String -> SqlMarshaller writeEntity readEntity -> TableDefinition NoKey writeEntity readEntity
- dropColumns :: [String] -> TableDefinition key writeEntity readEntity -> TableDefinition key writeEntity readEntity
- columnsToDrop :: TableDefinition key writeEntity readEntity -> Set String
- tableIdentifier :: TableDefinition key writeEntity readEntity -> TableIdentifier
- tableName :: TableDefinition key writeEntity readEntity -> Qualified TableName
- setTableSchema :: String -> TableDefinition key writeEntity readEntity -> TableDefinition key writeEntity readEntity
- tableConstraints :: TableDefinition key writeEntity readEntity -> TableConstraints
- addTableConstraints :: [ConstraintDefinition] -> TableDefinition key writeEntity readEntity -> TableDefinition key writeEntity readEntity
- tableIndexes :: TableDefinition key writeEntity readEntity -> Map IndexMigrationKey IndexDefinition
- addTableIndexes :: [IndexDefinition] -> TableDefinition key writeEntity readEntity -> TableDefinition key writeEntity readEntity
- tablePrimaryKey :: TableDefinition (HasKey key) writeEntity readEntity -> PrimaryKey key
- tableMarshaller :: TableDefinition key writeEntity readEntity -> AnnotatedSqlMarshaller writeEntity readEntity
- mapTableMarshaller :: (SqlMarshaller readEntityA writeEntityA -> SqlMarshaller readEntityB writeEntityB) -> TableDefinition key readEntityA writeEntityA -> TableDefinition key readEntityB writeEntityB
- mkInsertExpr :: ReturningOption returningClause -> TableDefinition key writeEntity readEntity -> NonEmpty writeEntity -> InsertExpr
- mkCreateTableExpr :: TableDefinition key writeEntity readEntity -> CreateTableExpr
- mkTableColumnDefinitions :: TableDefinition key writeEntity readEntity -> [ColumnDefinition]
- mkTablePrimaryKeyExpr :: TableDefinition key writeEntity readEntity -> Maybe PrimaryKeyExpr
- mkInsertColumnList :: SqlMarshaller writeEntity readEntity -> InsertColumnList
- mkInsertSource :: SqlMarshaller writeEntity readEntity -> NonEmpty writeEntity -> InsertSource
- mkTableReturningClause :: ReturningOption returningClause -> TableDefinition key writeEntity readEntty -> Maybe ReturningExpr
Documentation
data TableDefinition key writeEntity readEntity Source #
Contains the definition of a SQL table for Orville to use for generating queries and marshalling Haskell values to and from the database.
key
is a Haskell type used to indicate whether the table has a primary key and what the type of the key is if so. SeeHasKey
andNoKey
for values to be used in this parameter.writeEntity
is the Haskell type for values that Orville will write to the database for you (i.e. both inserts and updates).readEntity
is the Haskell type for values that Orville will decode from the result set when entities are queried from this table.
Since: 1.0.0.0
HasKey
is a type with no constructors. It is used only at the type level
as the key
parameter to the TableDefinition
type to indicate that the
table has a primary key and what the Haskell type of the primary key is.
Since: 1.0.0.0
NoKey
is a type with no constructors. It is used only at the type level
as the key
parameter to the TableDefinition
type to indicate that the
table does not have a primary key.
Since: 1.0.0.0
:: String | The name of the table |
-> PrimaryKey key | Definition of the table's primary key |
-> SqlMarshaller writeEntity readEntity | A |
-> TableDefinition (HasKey key) writeEntity readEntity |
Constructs a new TableDefinition
with the basic fields required for
operation. For convenience, this function accepts a PrimaryKey
even though
this is not required for all Orville operations to work. If you need to
create a table without any primary key, see mkTableDefinitionWithoutKey
.
Since: 1.0.0.0
mkTableDefinitionWithoutKey Source #
:: String | The name of the table |
-> SqlMarshaller writeEntity readEntity | A |
-> TableDefinition NoKey writeEntity readEntity |
Constructs a new TableDefinition
with the minimal fields required for
operation. Note: tables created via this function will not have a primary
key. Certain Orville functions require a primary key. Attempting to call
functions requiring a primary key will fail to compile when using a table
that has no key.
Since: 1.0.0.0
:: [String] | Columns that should be dropped from the table |
-> TableDefinition key writeEntity readEntity | |
-> TableDefinition key writeEntity readEntity |
Annotates a TableDefinition
with a direction to drop columns if they are
found in the database. Orville does not drop columns during auto-migration
unless they are explicitly requested to be dropped via dropColumns
.
If you remove a reference to a column from the table's SqlMarshaller
without adding the column's name to dropColumns
, Orville will operate as if
the column does not exist without actually dropping the column. This is often
useful if you're not sure you want to lose the data in the column, or if you
have zero down-time deployments, which requires the column not be referenced
by deployed code before it can be dropped.
Since: 1.0.0.0
columnsToDrop :: TableDefinition key writeEntity readEntity -> Set String Source #
Returns the set of columns that have been marked as dropped by dropColumns
.
Since: 1.0.0.0
tableIdentifier :: TableDefinition key writeEntity readEntity -> TableIdentifier Source #
Returns the table's TableIdentifier
.
Since: 1.0.0.0
tableName :: TableDefinition key writeEntity readEntity -> Qualified TableName Source #
Returns the table's name as an expression that can be used to build SQL statements. If the table has a schema name set, the name will be qualified with it.
Since: 1.0.0.0
setTableSchema :: String -> TableDefinition key writeEntity readEntity -> TableDefinition key writeEntity readEntity Source #
Sets the table's schema to the name in the given String
, which will be
treated as a SQL identifier. If a table has a schema name set, it will be
included as a qualifier on the table name for all queries involving the
table.
Since: 1.0.0.0
tableConstraints :: TableDefinition key writeEntity readEntity -> TableConstraints Source #
Retrieves all the table constraints that have been added to the table either
via addTableConstraints
or that are found on
FieldDefinition
s included with this table's
SqlMarshaller
.
Since: 1.0.0.0
addTableConstraints :: [ConstraintDefinition] -> TableDefinition key writeEntity readEntity -> TableDefinition key writeEntity readEntity Source #
Adds the given table constraints to the table definition. It's also possible
to add constraints that apply to only one column, adding them to the
FieldDefinition
s that are included in the table's
SqlMarshaller
.
If you wish to constrain multiple columns with a single constraint (e.g. a
multi-column unique constraint), you must use addTableConstraints
.
Note: If multiple constraints are added with the same
ConstraintMigrationKey
, only the last one that is
added will be part of the TableDefinition
. Any previously-added constraint
with the same key is replaced by the new one.
Since: 1.0.0.0
tableIndexes :: TableDefinition key writeEntity readEntity -> Map IndexMigrationKey IndexDefinition Source #
Retrieves all the table indexes that have been added to the table via
addTableIndexes
.
Since: 1.0.0.0
addTableIndexes :: [IndexDefinition] -> TableDefinition key writeEntity readEntity -> TableDefinition key writeEntity readEntity Source #
Adds the given table indexes to the table definition.
Note: If multiple indexes are added with the same IndexMigrationKey
, only
the last one that is added will be part of the TableDefinition
. Any
previously-added index with the same key is replaced by the new one.
Since: 1.0.0.0
tablePrimaryKey :: TableDefinition (HasKey key) writeEntity readEntity -> PrimaryKey key Source #
Returns the primary key for the table, as defined at construction via
mkTableDefinition
.
Since: 1.0.0.0
tableMarshaller :: TableDefinition key writeEntity readEntity -> AnnotatedSqlMarshaller writeEntity readEntity Source #
Returns the marshaller for the table, as defined at construction via
mkTableDefinition
.
Since: 1.0.0.0
mapTableMarshaller :: (SqlMarshaller readEntityA writeEntityA -> SqlMarshaller readEntityB writeEntityB) -> TableDefinition key readEntityA writeEntityA -> TableDefinition key readEntityB writeEntityB Source #
Applies the provided function to the underlying SqlMarshaller
of the
TableDefinition
.
Since: 1.0.0.0
mkInsertExpr :: ReturningOption returningClause -> TableDefinition key writeEntity readEntity -> NonEmpty writeEntity -> InsertExpr Source #
Builds an InsertExpr
that will insert the given entities into the SQL
table when it is executed. A RETURNING
clause will either be included to
return the inserted rows or not, depending on the ReturningOption
given.
Since: 1.0.0.0
mkCreateTableExpr :: TableDefinition key writeEntity readEntity -> CreateTableExpr Source #
Builds a CreateTableExpr
that will create a SQL table matching the
given TableDefinition
when it is executed.
Since: 1.0.0.0
mkTableColumnDefinitions :: TableDefinition key writeEntity readEntity -> [ColumnDefinition] Source #
Builds the ColumnDefinitions
for all the fields described by the
table definition's SqlMarshaller
.
Since: 1.0.0.0
mkTablePrimaryKeyExpr :: TableDefinition key writeEntity readEntity -> Maybe PrimaryKeyExpr Source #
Builds the PrimaryKeyExpr
for this table, or none if this table has no
primary key.
Since: 1.0.0.0
mkInsertColumnList :: SqlMarshaller writeEntity readEntity -> InsertColumnList Source #
Builds an InsertColumnList
that specifies the columns for an
insert statement in the order that they appear in the given SqlMarshaller
.
In normal circumstances you will want to build the complete insert statement
via mkInsertExpr
, but this is exported in case you are composing SQL
yourself and need the column list of an insert as a fragment.
Since: 1.0.0.0
mkInsertSource :: SqlMarshaller writeEntity readEntity -> NonEmpty writeEntity -> InsertSource Source #
Builds an InsertSource
that will insert the given entities with their
values specified in the order that the fields appear in the given
SqlMarshaller
(which matches the order of column names produced by
mkInsertColumnList
).
In normal circumstances you will want to build the complete insert statement
via mkInsertExpr
, but this is exported in case you are composing SQL
yourself and need the column list of an insert as a fragment.
Since: 1.0.0.0
mkTableReturningClause :: ReturningOption returningClause -> TableDefinition key writeEntity readEntty -> Maybe ReturningExpr Source #
When WithReturning
is given, builds a ReturningExpr
that will
return all the columns in the given TableDefinition
.
Since: 1.0.0.0