mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 12:29:41 +08:00
Document multi_insert for time_point columns (#367)
This commit is contained in:
parent
cc946f8a32
commit
4178942015
@ -2,6 +2,8 @@ Haven't found the time to document this in any detail, yet, but this is an examp
|
||||
|
||||
```C++
|
||||
db(insert_into(tab).set(tab.gamma = true));
|
||||
db(insert_into(tabDateTime)
|
||||
.set(tabDateTime.colTimePoint = std::chrono::system_clock::now()));
|
||||
```
|
||||
|
||||
This is how you could insert multiple rows at a time:
|
||||
@ -15,4 +17,19 @@ multi_insert.values.add(t.gamma = sqlpp::value_or_null(true),
|
||||
t.beta = sqlpp::value_or_null("pie"),
|
||||
t.delta = sqlpp::value_or_null<sqlpp::integer>(sqlpp::null));
|
||||
db(multi_insert);
|
||||
```
|
||||
```
|
||||
|
||||
Note that `add` currently requires precise value types, equal to the respective column's value
|
||||
type. For instance, time point columns are represented as
|
||||
`std::chrono::time_point<std::chrono::system_clock, std::chrono::microseconds>`.
|
||||
|
||||
Thus, when using such a column in a `multi_insert`, you might have to cast to the right
|
||||
time point.
|
||||
|
||||
```
|
||||
auto multi_time_insert = insert_into(tabDateTime).columns(tabDateTime.colTimePoint);
|
||||
multi_time_insert.values.add(tabDateTime.colTimePoint = std::chrono::time_point_cast<std::chrono::microseconds>(
|
||||
std::chrono::system_clock::now()));
|
||||
```
|
||||
|
||||
Similar for other data types.
|
||||
|
@ -35,6 +35,7 @@ int Insert(int, char*[])
|
||||
MockDb db = {};
|
||||
MockDb::_serializer_context_t printer = {};
|
||||
const auto t = test::TabBar{};
|
||||
const auto tabDateTime = test::TabDateTime{};
|
||||
// test::TabFoo f;
|
||||
|
||||
{
|
||||
@ -71,6 +72,14 @@ int Insert(int, char*[])
|
||||
printer.reset();
|
||||
std::cerr << serialize(multi_insert, printer).str() << std::endl;
|
||||
|
||||
// Beware, you need exact types for inserted values in multi_insert
|
||||
insert_into(tabDateTime)
|
||||
.set(tabDateTime.colTimePoint = std::chrono::system_clock::now());
|
||||
|
||||
auto multi_time_insert = insert_into(tabDateTime).columns(tabDateTime.colTimePoint);
|
||||
multi_time_insert.values.add(tabDateTime.colTimePoint = std::chrono::time_point_cast<std::chrono::microseconds>(
|
||||
std::chrono::system_clock::now()));
|
||||
|
||||
auto i = dynamic_insert_into(db, t).dynamic_set();
|
||||
i.insert_list.add(t.beta = "kirschauflauf");
|
||||
printer.reset();
|
||||
|
Loading…
Reference in New Issue
Block a user