mirror of
https://github.com/getml/sqlgen.git
synced 2026-01-01 23:19:58 -06:00
872 B
872 B
sqlgen::PrimaryKey
Sometimes you would like to set primary keys on your tables. This is possible as well:
struct People {
rfl::PrimaryKey<std::string> first_name;
std::string last_name;
uint age;
};
Now, the generated SQL code will look something like this:
CREATE TABLE IF NOT EXISTS "People"("first_name" TEXT NOT NULL,
"last_name" TEXT NOT NULL,
"age" INTEGER NOT NULL,
PRIMARY_KEY("first_name"));
rfl::PrimaryKey<...> is a simple wrapper. You can simply assign to it as follows:
const auto person = People{.first_name = "Homer", ...};
And you can retrieve the underlying value using any of the following:
person.first_name();
person.first_name.get();
person.first_name.value();