Lightweight 0.20261105.1
Loading...
Searching...
No Matches
Lightweight::SqlMigrationInsertBuilder Class Referencefinal

Query builder for building INSERT queries in migrations. More...

#include <Migrate.hpp>

Public Member Functions

 SqlMigrationInsertBuilder (SqlInsertDataPlan &plan)
 Constructs a migration INSERT builder.
 
template<typename T >
SqlMigrationInsertBuilder & Set (std::string columnName, T const &value)
 Sets a column value for the INSERT.
 
LIGHTWEIGHT_API SqlMigrationInsertBuilder & IfNotExists (std::vector< std::string > keyColumns)
 Makes the INSERT skip its row when a row with the same key values already exists.
 

Detailed Description

Query builder for building INSERT queries in migrations.

See also
SqlMigrationQueryBuilder

Definition at line 389 of file Migrate.hpp.

Constructor & Destructor Documentation

◆ SqlMigrationInsertBuilder()

Lightweight::SqlMigrationInsertBuilder::SqlMigrationInsertBuilder ( SqlInsertDataPlan &  plan)
inlineexplicit

Constructs a migration INSERT builder.

Definition at line 393 of file Migrate.hpp.

Member Function Documentation

◆ Set()

template<typename T >
SqlMigrationInsertBuilder & Lightweight::SqlMigrationInsertBuilder::Set ( std::string  columnName,
T const &  value 
)
inline

Sets a column value for the INSERT.

Definition at line 400 of file Migrate.hpp.

◆ IfNotExists()

LIGHTWEIGHT_API SqlMigrationInsertBuilder & Lightweight::SqlMigrationInsertBuilder::IfNotExists ( std::vector< std::string >  keyColumns)

Makes the INSERT skip its row when a row with the same key values already exists.

Renders INSERT INTO t (...) SELECT ... WHERE NOT EXISTS (SELECT 1 FROM t WHERE key = ...), so a seed row a database already holds no longer fails the migration. An existing row is left as it is, even when its non-key columns differ from the values given here. Rendering the plan throws std::invalid_argument when a key column is not one of the Set columns or its value is NULL.

Parameters
keyColumnsThe columns identifying the row; must not be empty.
Returns
This builder, for chaining.
Exceptions
std::invalid_argumentkeyColumns is empty.

The documentation for this class was generated from the following file: