Skip to content

make_column

Yevgeniy Zakharov edited this page Feb 11, 2017 · 4 revisions
template<class O, class T, class ...Op>
column_t<O, T, Op...> make_column(const std::string &name, T O::*m, Op ...options);

Creates column objects used as make_table function argument.

Parameters

(1) name Column name from database.

(2) m Member pointer mapped to this column. Example: &User::id.

(3) options Extra options used to specify column more precisely. For example: primary_key, autoincrement and default_value.

Return value

column_t<O, T, Op...> instance.

Example

struct Employee {
    int id;
    std::string name;
    int age;
    std::shared_ptr<std::string> address;   //  optional
    std::shared_ptr<double> salary; //  optional
};

using namespace sqlite_orm;
auto storage = make_storage("make_storage_example.sqlite",
                            make_table("COMPANY",
                                       make_column("ID",
                                                   &Employee::id,
                                                   primary_key()),
                                       make_column("NAME",
                                                   &Employee::name),
                                       make_column("AGE",
                                                   &Employee::age),
                                       make_column("ADDRESS",
                                                   &Employee::address),
                                       make_column("SALARY",
                                                   &Employee::salary)));

Clone this wiki locally