|
Lightweight 0.20261105.1
|
Query builder for building SQL migration queries. More...
#include <Migrate.hpp>
Public Member Functions | |
| SqlMigrationQueryBuilder (SqlQueryFormatter const &formatter) | |
| Constructs a migration query builder. | |
| LIGHTWEIGHT_API SqlMigrationQueryBuilder & | WithSchema (std::string schemaName) |
| LIGHTWEIGHT_API SqlMigrationQueryBuilder & | CreateDatabase (std::string_view databaseName) |
| Creates a new database. | |
| LIGHTWEIGHT_API SqlMigrationQueryBuilder & | DropDatabase (std::string_view databaseName) |
| Drops a database. | |
| LIGHTWEIGHT_API SqlCreateTableQueryBuilder | CreateTable (std::string_view tableName) |
| Creates a new table. | |
| LIGHTWEIGHT_API SqlCreateTableQueryBuilder | CreateTableIfNotExists (std::string_view tableName) |
| LIGHTWEIGHT_API SqlAlterTableQueryBuilder | AlterTable (std::string_view tableName) |
| Alters an existing table. | |
| LIGHTWEIGHT_API SqlMigrationQueryBuilder & | DropTable (std::string_view tableName) |
| Drops a table. | |
| LIGHTWEIGHT_API SqlMigrationQueryBuilder & | DropTableIfExists (std::string_view tableName) |
| Drops a table if it exists. | |
| LIGHTWEIGHT_API SqlMigrationQueryBuilder & | DropTableCascade (std::string_view tableName) |
| template<typename Record > | |
| SqlCreateTableQueryBuilder | CreateTable () |
| Creates a new table for the given record type. | |
| template<typename Record > | |
| SqlAlterTableQueryBuilder | AlterTable () |
| Alters an existing table. | |
| LIGHTWEIGHT_API SqlMigrationQueryBuilder & | RawSql (std::string_view sql) |
| Executes raw SQL. | |
| LIGHTWEIGHT_API SqlMigrationQueryBuilder & | CreateIndex (std::string indexName, std::string tableName, std::vector< std::string > columns, bool unique=false) |
| LIGHTWEIGHT_API SqlMigrationQueryBuilder & | CreateIndex (std::string indexName, std::string tableName, std::vector< std::string > columns, SqlCreateIndexOptions options) |
| LIGHTWEIGHT_API SqlMigrationQueryBuilder & | CreateUniqueIndex (std::string indexName, std::string tableName, std::vector< std::string > columns) |
| LIGHTWEIGHT_API SqlMigrationQueryBuilder & | CreateIndex (std::string tableName, std::vector< std::string > columns, IndexType type=IndexType::NonUnique) |
| LIGHTWEIGHT_API SqlMigrationInsertBuilder | Insert (std::string_view tableName) |
| Creates an INSERT statement for the migration. | |
| LIGHTWEIGHT_API SqlMigrationUpdateBuilder | Update (std::string_view tableName) |
| Creates an UPDATE statement for the migration. | |
| LIGHTWEIGHT_API SqlMigrationDeleteBuilder | Delete (std::string_view tableName) |
| Creates a DELETE statement for the migration. | |
| LIGHTWEIGHT_API SqlMigrationQueryBuilder & | BeginTransaction () |
| Starts a transaction. | |
| LIGHTWEIGHT_API SqlMigrationQueryBuilder & | CommitTransaction () |
| Commits a transaction. | |
| LIGHTWEIGHT_API SqlMigrationPlan const & | GetPlan () const & |
| Gets the migration plan. | |
| LIGHTWEIGHT_API SqlMigrationPlan | GetPlan () && |
Query builder for building SQL migration queries.
Definition at line 520 of file Migrate.hpp.
|
inlineexplicit |
Constructs a migration query builder.
Definition at line 524 of file Migrate.hpp.
| LIGHTWEIGHT_API SqlMigrationQueryBuilder & Lightweight::SqlMigrationQueryBuilder::WithSchema | ( | std::string | schemaName | ) |
Sets the schema name for the migration.
On SQL Server and PostgreSQL, CreateTable then creates the table in that schema, which must exist. On PostgreSQL this differs from earlier releases, which created it in the search_path schema, so the checksums of such migrations changed (see dbtool rewrite-checksums).
| LIGHTWEIGHT_API SqlCreateTableQueryBuilder Lightweight::SqlMigrationQueryBuilder::CreateTableIfNotExists | ( | std::string_view | tableName | ) |
Creates a new table only if it does not already exist.
| LIGHTWEIGHT_API SqlMigrationQueryBuilder & Lightweight::SqlMigrationQueryBuilder::DropTableCascade | ( | std::string_view | tableName | ) |
Drops a table and all foreign key constraints referencing it. On PostgreSQL, uses CASCADE. On MS SQL, drops FK constraints first.
|
inline |
Creates a new table for the given record type.
Definition at line 569 of file Migrate.hpp.
|
inline |
Alters an existing table.
Definition at line 580 of file Migrate.hpp.
| LIGHTWEIGHT_API SqlMigrationQueryBuilder & Lightweight::SqlMigrationQueryBuilder::CreateIndex | ( | std::string | indexName, |
| std::string | tableName, | ||
| std::vector< std::string > | columns, | ||
| bool | unique = false |
||
| ) |
Creates an index on a table.
| indexName | The name of the index to create. |
| tableName | The name of the table to create the index on. |
| columns | The columns to include in the index. |
| unique | If true, creates a UNIQUE index. |
| LIGHTWEIGHT_API SqlMigrationQueryBuilder & Lightweight::SqlMigrationQueryBuilder::CreateIndex | ( | std::string | indexName, |
| std::string | tableName, | ||
| std::vector< std::string > | columns, | ||
| SqlCreateIndexOptions | options | ||
| ) |
Creates an index on a table, optionally unique and/or partial.
A non-empty options.whereExpression renders a partial / filtered index, CREATE [UNIQUE] INDEX ... ON t (cols) WHERE <expression>, which SQLite, PostgreSQL and SQL Server all support.
ANSI_WARNINGS ON, i.e. on connections using SqlStringTruncationMode::Error; the default SqlStringTruncationMode::Truncate fails them with error 1934.| indexName | The name of the index to create. |
| tableName | The name of the table to create the index on. |
| columns | The columns to include in the index. |
| options | Uniqueness and the optional index predicate. |
| LIGHTWEIGHT_API SqlMigrationQueryBuilder & Lightweight::SqlMigrationQueryBuilder::CreateUniqueIndex | ( | std::string | indexName, |
| std::string | tableName, | ||
| std::vector< std::string > | columns | ||
| ) |
Creates a unique index on a table.
| indexName | The name of the index to create. |
| tableName | The name of the table to create the index on. |
| columns | The columns to include in the index. |
| LIGHTWEIGHT_API SqlMigrationQueryBuilder & Lightweight::SqlMigrationQueryBuilder::CreateIndex | ( | std::string | tableName, |
| std::vector< std::string > | columns, | ||
| IndexType | type = IndexType::NonUnique |
||
| ) |
Creates an index on a table with auto-generated name.
The index name is automatically generated as idx_{tableName}_{col1}_{col2}_...
| tableName | The name of the table to create the index on. |
| columns | The columns to include in the index. |
| type | The type of index (NonUnique or Unique). |
| LIGHTWEIGHT_API SqlMigrationPlan Lightweight::SqlMigrationQueryBuilder::GetPlan | ( | ) | && |
Gets the migration plan.