-
-
Notifications
You must be signed in to change notification settings - Fork 318
values
Yevgeniy Zakharov edited this page Aug 21, 2021
·
1 revision
(1) template<class... Args> auto values(Args... args)
(2) template<class T> auto values(std::vector<T> vector)
values
function is used to add VALUES
SQL keyword into your statement.
CREATE TABLE devices (serial_number TEXT NOT NULL, device_id TEXT NOT NULL);
DELETE FROM devices
WHERE (serial_number, device_id) IN (VALUES ('abc', '123'), ('def', '456'));
Usage of the first overload:
struct Device {
std::string serialNumber;
std::string deviceId;
};
auto storage = make_storage({},
make_table("devices",
make_column("serial_number", &Device::serialNumber),
make_column("device_id", &Device::deviceId)));
storage.sync_schema();
storage.remove_all<Device>(where(in(std::make_tuple(&Device::serialNumber, &Device::deviceId),
values(std::make_tuple("abc", "123"), std::make_tuple("def", "456")))));
Usage of the second overload:
storage.remove_all<Device>(
where(in(std::make_tuple(&Device::serialNumber, &Device::deviceId),
values(std::vector<std::tuple<std::string, std::string>>{std::make_tuple("abc", "123"),
std::make_tuple("def", "456")}))));
Why two overloads exist? Cause the first one is static and the second one is dynamic. Both functions will make the same queries but static one can be altered using get<N>(statement)
API in case you use prepared statements. If you don't use prepared statements then don't mind.
Return type is not specified in docs and can be changed in future.