Skip to content

storage_t::replace

Yevgeniy Zakharov edited this page Aug 19, 2018 · 2 revisions
template<class O>
void replace(const O &o);

INSERT OR REPLACE query. Does the same that insert does but inserts primary key too. Use insert to create id and replace to update or insert with specified id. If table has no primary key insert and replace work the same way.

Parameters

class O is a mapped type you want to insert. Doesn't have to specified explicitly until you want to insert a subclass object.

o object to insert or replace itself.

Example

struct Object {
    int id;
    std::string name;
};

auto storage = make_storage("test_replace.sqlite",
                            make_table("objects",
                                       make_column("id", &Object::id, primary_key()),
                                       make_column("name", &Object::name)));

storage.sync_schema();

storage.replace(Object{
    100,
    "Baby",
});

External links

REPLACE in SQLite