schema progress
This commit is contained in:
parent
7e1713ddd3
commit
c9a84e0568
|
|
@ -1,2 +1,3 @@
|
||||||
.idea
|
.idea
|
||||||
cmake-build-debug
|
cmake-build-debug
|
||||||
|
Testing
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class QueryRecordFixture
|
||||||
public:
|
public:
|
||||||
QueryRecordFixture()
|
QueryRecordFixture()
|
||||||
: db(matador::test::connection::dns)
|
: db(matador::test::connection::dns)
|
||||||
, schema(std::make_shared<matador::sql::schema>(db.dialect().default_schema_name()))
|
, schema(db.dialect().default_schema_name())
|
||||||
{
|
{
|
||||||
db.open();
|
db.open();
|
||||||
}
|
}
|
||||||
|
|
@ -27,7 +27,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
matador::sql::connection db;
|
matador::sql::connection db;
|
||||||
std::shared_ptr<matador::sql::schema> schema;
|
matador::sql::schema schema;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void drop_table_if_exists(const std::string &table_name) {
|
void drop_table_if_exists(const std::string &table_name) {
|
||||||
|
|
@ -317,7 +317,7 @@ TEST_CASE_METHOD(QueryRecordFixture, "Execute select statement with group by and
|
||||||
res = db.query(schema).insert().into("person", {"id", "name", "age"}).values({5, "charlie", 67}).execute();
|
res = db.query(schema).insert().into("person", {"id", "name", "age"}).values({5, "charlie", 67}).execute();
|
||||||
REQUIRE(res == 1);
|
REQUIRE(res == 1);
|
||||||
|
|
||||||
auto result = db.query(schema).select({alias(count("age"), "age_count"), "age"})
|
auto result = db.query(schema).select({count("age").as("age_count"), "age"})
|
||||||
.from("person")
|
.from("person")
|
||||||
.group_by("age")
|
.group_by("age")
|
||||||
.order_by("age_count").desc()
|
.order_by("age_count").desc()
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ class QueryFixture
|
||||||
public:
|
public:
|
||||||
QueryFixture()
|
QueryFixture()
|
||||||
: db(matador::test::connection::dns)
|
: db(matador::test::connection::dns)
|
||||||
, schema(std::make_shared<matador::sql::schema>(db.dialect().default_schema_name()))
|
, schema(db.dialect().default_schema_name())
|
||||||
{
|
{
|
||||||
db.open();
|
db.open();
|
||||||
}
|
}
|
||||||
|
|
@ -33,7 +33,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
matador::sql::connection db;
|
matador::sql::connection db;
|
||||||
std::shared_ptr<matador::sql::schema> schema;
|
matador::sql::schema schema;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void drop_table_if_exists(const std::string &table_name)
|
void drop_table_if_exists(const std::string &table_name)
|
||||||
|
|
@ -46,6 +46,8 @@ private:
|
||||||
|
|
||||||
TEST_CASE_METHOD(QueryFixture, "Create table with foreign key relation", "[session]")
|
TEST_CASE_METHOD(QueryFixture, "Create table with foreign key relation", "[session]")
|
||||||
{
|
{
|
||||||
|
schema.attach<airplane>("airplane");
|
||||||
|
schema.attach<flight>("flight");
|
||||||
db.query(schema).create()
|
db.query(schema).create()
|
||||||
.table<airplane>("airplane")
|
.table<airplane>("airplane")
|
||||||
.execute();
|
.execute();
|
||||||
|
|
@ -67,6 +69,7 @@ TEST_CASE_METHOD(QueryFixture, "Create table with foreign key relation", "[sessi
|
||||||
|
|
||||||
TEST_CASE_METHOD(QueryFixture, "Execute select statement with where clause", "[session]")
|
TEST_CASE_METHOD(QueryFixture, "Execute select statement with where clause", "[session]")
|
||||||
{
|
{
|
||||||
|
schema.attach<person>("person");
|
||||||
db.query(schema).create()
|
db.query(schema).create()
|
||||||
.table<person>("person")
|
.table<person>("person")
|
||||||
.execute();
|
.execute();
|
||||||
|
|
@ -96,7 +99,7 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with where clause", "[s
|
||||||
REQUIRE(i.at(1).type() == data_type_t::type_varchar);
|
REQUIRE(i.at(1).type() == data_type_t::type_varchar);
|
||||||
REQUIRE(i.at(1).as<std::string>() == george.name);
|
REQUIRE(i.at(1).as<std::string>() == george.name);
|
||||||
REQUIRE(i.at(2).name() == "age");
|
REQUIRE(i.at(2).name() == "age");
|
||||||
REQUIRE(i.at(2).type() == matador::sql::data_type_t::type_unsigned_int);
|
REQUIRE(i.at(2).type() == matador::sql::data_type_t::type_long_long);
|
||||||
REQUIRE(i.at(2).as<long long>() == george.age);
|
REQUIRE(i.at(2).as<long long>() == george.age);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -156,6 +159,8 @@ TEST_CASE_METHOD(QueryFixture, "Execute insert statement", "[session]")
|
||||||
|
|
||||||
TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[session]")
|
TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[session]")
|
||||||
{
|
{
|
||||||
|
schema.attach<airplane>("airplane");
|
||||||
|
schema.attach<flight>("flight");
|
||||||
db.query(schema).create()
|
db.query(schema).create()
|
||||||
.table<airplane>("airplane")
|
.table<airplane>("airplane")
|
||||||
.execute();
|
.execute();
|
||||||
|
|
@ -195,6 +200,8 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key", "[session]")
|
||||||
|
|
||||||
TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left", "[session][join_left]")
|
TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and join_left", "[session][join_left]")
|
||||||
{
|
{
|
||||||
|
schema.attach<airplane>("airplane");
|
||||||
|
schema.attach<flight>("flight");
|
||||||
db.query(schema).create()
|
db.query(schema).create()
|
||||||
.table<airplane>("airplane")
|
.table<airplane>("airplane")
|
||||||
.execute();
|
.execute();
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ class StatementTestFixture
|
||||||
public:
|
public:
|
||||||
StatementTestFixture()
|
StatementTestFixture()
|
||||||
: db(matador::test::connection::dns)
|
: db(matador::test::connection::dns)
|
||||||
, schema(std::make_shared<matador::sql::schema>(db.dialect().default_schema_name()))
|
, schema(db.dialect().default_schema_name())
|
||||||
{
|
{
|
||||||
db.open();
|
db.open();
|
||||||
db.query(schema).create().table<airplane>("airplane").execute();
|
db.query(schema).create().table<airplane>("airplane").execute();
|
||||||
|
|
@ -29,7 +29,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
matador::sql::connection db;
|
matador::sql::connection db;
|
||||||
std::shared_ptr<matador::sql::schema> schema;
|
matador::sql::schema schema;
|
||||||
|
|
||||||
std::vector<entity<airplane>> planes{
|
std::vector<entity<airplane>> planes{
|
||||||
make_entity<airplane>(1, "Airbus", "A380"),
|
make_entity<airplane>(1, "Airbus", "A380"),
|
||||||
|
|
@ -48,6 +48,7 @@ private:
|
||||||
|
|
||||||
TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]")
|
TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]")
|
||||||
{
|
{
|
||||||
|
schema.attach<airplane>("airplane");
|
||||||
table ap{"airplane"};
|
table ap{"airplane"};
|
||||||
SECTION("Insert with prepared statement and placeholder") {
|
SECTION("Insert with prepared statement and placeholder") {
|
||||||
auto stmt = db.query(schema).insert()
|
auto stmt = db.query(schema).insert()
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ class TypeTraitsTestFixture
|
||||||
public:
|
public:
|
||||||
TypeTraitsTestFixture()
|
TypeTraitsTestFixture()
|
||||||
: db(matador::test::connection::dns)
|
: db(matador::test::connection::dns)
|
||||||
, schema(std::make_shared<matador::sql::schema>(db.dialect().default_schema_name()))
|
, schema(db.dialect().default_schema_name())
|
||||||
{
|
{
|
||||||
db.open();
|
db.open();
|
||||||
db.query(schema).create()
|
db.query(schema).create()
|
||||||
|
|
@ -30,7 +30,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
matador::sql::connection db;
|
matador::sql::connection db;
|
||||||
std::shared_ptr<matador::sql::schema> schema;
|
matador::sql::schema schema;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void drop_table_if_exists(const std::string &table_name) {
|
void drop_table_if_exists(const std::string &table_name) {
|
||||||
|
|
@ -84,6 +84,7 @@ struct data_type_traits<Color, void>
|
||||||
|
|
||||||
TEST_CASE_METHOD(TypeTraitsTestFixture, "Special handling of attributes with type traits", "[typetraits]")
|
TEST_CASE_METHOD(TypeTraitsTestFixture, "Special handling of attributes with type traits", "[typetraits]")
|
||||||
{
|
{
|
||||||
|
schema.attach<location>("location");
|
||||||
SECTION("Insert and select with direct execution") {
|
SECTION("Insert and select with direct execution") {
|
||||||
location loc{1, "center", {1, 2, 3}, Color::Black};
|
location loc{1, "center", {1, 2, 3}, Color::Black};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,9 +62,9 @@ int main()
|
||||||
const std::string env_var{"MATADOR_BACKENDS_PATH"};
|
const std::string env_var{"MATADOR_BACKENDS_PATH"};
|
||||||
|
|
||||||
std::string dns{"sqlite://demo.db"};
|
std::string dns{"sqlite://demo.db"};
|
||||||
auto s = std::make_shared<schema>("main");
|
schema s("main");
|
||||||
s->attach<author>("authors");
|
s.attach<author>("authors");
|
||||||
s->attach<book>("books");
|
s.attach<book>("books");
|
||||||
|
|
||||||
connection c(dns);
|
connection c(dns);
|
||||||
c.open();
|
c.open();
|
||||||
|
|
@ -81,17 +81,17 @@ int main()
|
||||||
|
|
||||||
std::cout << "SQL: " << create_authors_sql << "\n";
|
std::cout << "SQL: " << create_authors_sql << "\n";
|
||||||
|
|
||||||
auto mc = make_entity<author>();
|
author mc;
|
||||||
mc->id = 1;
|
mc.id = 1;
|
||||||
mc->first_name = "Michael";
|
mc.first_name = "Michael";
|
||||||
mc->last_name = "Crichton";
|
mc.last_name = "Crichton";
|
||||||
mc->date_of_birth = "19.8.1954";
|
mc.date_of_birth = "19.8.1954";
|
||||||
mc->year_of_birth = 1954;
|
mc.year_of_birth = 1954;
|
||||||
mc->distinguished = true;
|
mc.distinguished = true;
|
||||||
auto insert_authors_sql = c.query(s)
|
auto insert_authors_sql = c.query(s)
|
||||||
.insert()
|
.insert()
|
||||||
.into<author>(qh::authors)
|
.into<author>(qh::authors)
|
||||||
.values(*mc)
|
.values(mc)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
std::cout << "SQL: " << insert_authors_sql << "\n";
|
std::cout << "SQL: " << insert_authors_sql << "\n";
|
||||||
|
|
@ -126,13 +126,13 @@ int main()
|
||||||
c.query(s)
|
c.query(s)
|
||||||
.insert()
|
.insert()
|
||||||
.into<book>(qh::books)
|
.into<book>(qh::books)
|
||||||
.values({2, "It", mc->id, 1980})
|
.values({2, "It", mc.id, 1980})
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
c.query(s)
|
c.query(s)
|
||||||
.insert()
|
.insert()
|
||||||
.into<book>(qh::books)
|
.into<book>(qh::books)
|
||||||
.values({3, "Misery", mc->id, 1984})
|
.values({3, "Misery", mc.id, 1984})
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
auto select_books_sql = c.query(s)
|
auto select_books_sql = c.query(s)
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ public:
|
||||||
template<class ContainerType>
|
template<class ContainerType>
|
||||||
void on_has_many(const char *, ContainerType &, const char *, const char *, const utils::foreign_attributes &attr)
|
void on_has_many(const char *, ContainerType &, const char *, const char *, const utils::foreign_attributes &attr)
|
||||||
{
|
{
|
||||||
if (attr.fetch() == fetch_type::LAZY) {
|
if (attr.fetch() == utils::fetch_type::LAZY) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto info = table_schema_.info<typename ContainerType::value_type::value_type>();
|
const auto info = table_schema_.info<typename ContainerType::value_type::value_type>();
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ public:
|
||||||
[[nodiscard]] bool exists(const std::string &schema_name, const std::string &table_name) const;
|
[[nodiscard]] bool exists(const std::string &schema_name, const std::string &table_name) const;
|
||||||
[[nodiscard]] bool exists(const std::string &table_name) const;
|
[[nodiscard]] bool exists(const std::string &table_name) const;
|
||||||
|
|
||||||
sql::query query(const std::shared_ptr<sql::schema> &schema) const;
|
sql::query query(const sql::schema &schema) const;
|
||||||
|
|
||||||
query_result<record> fetch(const query_context &q) const;
|
query_result<record> fetch(const query_context &q) const;
|
||||||
[[nodiscard]] std::unique_ptr<query_result_impl> fetch(const std::string &sql) const;
|
[[nodiscard]] std::unique_ptr<query_result_impl> fetch(const std::string &sql) const;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ class connection;
|
||||||
class query
|
class query
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit query(connection &db, const std::shared_ptr<sql::schema> &schema);
|
explicit query(connection &db, const sql::schema &schema);
|
||||||
query(const query &) = delete;
|
query(const query &) = delete;
|
||||||
query& operator=(const query &) = delete;
|
query& operator=(const query &) = delete;
|
||||||
|
|
||||||
|
|
@ -28,19 +28,19 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
connection &connection_;
|
connection &connection_;
|
||||||
std::shared_ptr<sql::schema> schema_;
|
const sql::schema &schema_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
query_select_intermediate query::select()
|
query_select_intermediate query::select()
|
||||||
{
|
{
|
||||||
return select(column_name_generator::generate<Type>(*schema_));
|
return select(column_name_generator::generate<Type>(schema_));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
query_select_intermediate query::select(std::initializer_list<column> columns)
|
query_select_intermediate query::select(std::initializer_list<column> columns)
|
||||||
{
|
{
|
||||||
auto cols = column_name_generator::generate<Type>(*schema_);
|
auto cols = column_name_generator::generate<Type>(schema_);
|
||||||
cols.insert(cols.end(), columns);
|
cols.insert(cols.end(), columns);
|
||||||
return select(cols);
|
return select(cols);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,17 +24,17 @@ class connection;
|
||||||
class basic_query_intermediate
|
class basic_query_intermediate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit basic_query_intermediate(connection &db, const std::shared_ptr<sql::schema> &schema);
|
explicit basic_query_intermediate(connection &db, const sql::schema &schema);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
connection &connection_;
|
connection &connection_;
|
||||||
std::shared_ptr<sql::schema> schema_;
|
const sql::schema &schema_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class query_intermediate : public basic_query_intermediate
|
class query_intermediate : public basic_query_intermediate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
query_intermediate(connection &db, const std::shared_ptr<sql::schema> &schema, query_data &data);
|
query_intermediate(connection &db, const sql::schema &schema, query_data &data);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
query_data &data_;
|
query_data &data_;
|
||||||
|
|
@ -188,7 +188,7 @@ private:
|
||||||
class query_start_intermediate : public basic_query_intermediate
|
class query_start_intermediate : public basic_query_intermediate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit query_start_intermediate(connection &db, const std::shared_ptr<sql::schema> &schema);
|
explicit query_start_intermediate(connection &db, const sql::schema &schema);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
query_data data_;
|
query_data data_;
|
||||||
|
|
@ -197,7 +197,7 @@ protected:
|
||||||
class query_select_intermediate : public query_start_intermediate
|
class query_select_intermediate : public query_start_intermediate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
query_select_intermediate(connection &db, const std::shared_ptr<sql::schema> &schema, const std::vector<column>& columns);
|
query_select_intermediate(connection &db, const sql::schema &schema, const std::vector<column>& columns);
|
||||||
|
|
||||||
query_from_intermediate from(const table& t);
|
query_from_intermediate from(const table& t);
|
||||||
};
|
};
|
||||||
|
|
@ -234,24 +234,24 @@ public:
|
||||||
class query_create_intermediate : public query_start_intermediate
|
class query_create_intermediate : public query_start_intermediate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit query_create_intermediate(connection &db, const std::shared_ptr<sql::schema> &schema);
|
explicit query_create_intermediate(connection &db, const sql::schema &schema);
|
||||||
|
|
||||||
query_execute_finish table(const sql::table &table, std::initializer_list<column_definition> columns);
|
query_execute_finish table(const sql::table &table, std::initializer_list<column_definition> columns);
|
||||||
query_execute_finish table(const sql::table &table, const std::vector<column_definition> &columns);
|
query_execute_finish table(const sql::table &table, const std::vector<column_definition> &columns);
|
||||||
template<class Type>
|
template<class Type>
|
||||||
query_execute_finish table(const sql::table &table)
|
query_execute_finish table(const sql::table &table)
|
||||||
{
|
{
|
||||||
if (!schema_->exists<Type>()) {
|
// if (!schema_.exists<Type>()) {
|
||||||
schema_->attach<Type>(table.name);
|
// schema_.attach<Type>(table.name);
|
||||||
}
|
// }
|
||||||
return this->table(table, column_generator::generate<Type>(*schema_));
|
return this->table(table, column_generator::generate<Type>(schema_));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class query_drop_intermediate : query_start_intermediate
|
class query_drop_intermediate : query_start_intermediate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit query_drop_intermediate(connection &db, const std::shared_ptr<sql::schema> &schema);
|
explicit query_drop_intermediate(connection &db, const sql::schema &schema);
|
||||||
|
|
||||||
query_execute_finish table(const sql::table &table);
|
query_execute_finish table(const sql::table &table);
|
||||||
};
|
};
|
||||||
|
|
@ -259,14 +259,14 @@ public:
|
||||||
class query_insert_intermediate : public query_start_intermediate
|
class query_insert_intermediate : public query_start_intermediate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit query_insert_intermediate(connection &db, const std::shared_ptr<sql::schema> &schema);
|
explicit query_insert_intermediate(connection &db, const sql::schema &schema);
|
||||||
|
|
||||||
query_into_intermediate into(const sql::table &table, std::initializer_list<column> column_names);
|
query_into_intermediate into(const sql::table &table, std::initializer_list<column> column_names);
|
||||||
query_into_intermediate into(const sql::table &table, std::vector<column> &&column_names);
|
query_into_intermediate into(const sql::table &table, std::vector<column> &&column_names);
|
||||||
template<class Type>
|
template<class Type>
|
||||||
query_into_intermediate into(const sql::table &table)
|
query_into_intermediate into(const sql::table &table)
|
||||||
{
|
{
|
||||||
return into(table, column_name_generator::generate<Type>(*schema_));
|
return into(table, column_name_generator::generate<Type>(schema_));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -296,7 +296,7 @@ private:
|
||||||
class query_update_intermediate : public query_start_intermediate
|
class query_update_intermediate : public query_start_intermediate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
query_update_intermediate(connection &db, const std::shared_ptr<sql::schema> &schema, const sql::table& table);
|
query_update_intermediate(connection &db, const sql::schema &schema, const sql::table& table);
|
||||||
|
|
||||||
query_set_intermediate set(std::initializer_list<key_value_pair> columns);
|
query_set_intermediate set(std::initializer_list<key_value_pair> columns);
|
||||||
query_set_intermediate set(std::vector<key_value_pair> &&columns);
|
query_set_intermediate set(std::vector<key_value_pair> &&columns);
|
||||||
|
|
@ -325,7 +325,7 @@ private:
|
||||||
class query_delete_intermediate : public query_start_intermediate
|
class query_delete_intermediate : public query_start_intermediate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit query_delete_intermediate(connection &db, const std::shared_ptr<sql::schema> &schema);
|
explicit query_delete_intermediate(connection &db, const sql::schema &schema);
|
||||||
|
|
||||||
query_delete_from_intermediate from(const sql::table &table);
|
query_delete_from_intermediate from(const sql::table &table);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,12 @@ public:
|
||||||
using iterator = repository::iterator;
|
using iterator = repository::iterator;
|
||||||
using const_iterator = repository::const_iterator;
|
using const_iterator = repository::const_iterator;
|
||||||
|
|
||||||
|
schema() = delete;
|
||||||
explicit schema(std::string name);
|
explicit schema(std::string name);
|
||||||
|
schema(const schema&) = delete;
|
||||||
|
schema& operator=(const schema&) = delete;
|
||||||
|
schema(schema&&) noexcept = default;
|
||||||
|
schema& operator=(schema&&) noexcept = default;
|
||||||
|
|
||||||
[[nodiscard]] std::string name() const;
|
[[nodiscard]] std::string name() const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ private:
|
||||||
connection_pool<connection> &pool_;
|
connection_pool<connection> &pool_;
|
||||||
const class dialect &dialect_;
|
const class dialect &dialect_;
|
||||||
|
|
||||||
std::shared_ptr<schema> schema_;
|
std::unique_ptr<schema> schema_;
|
||||||
mutable std::unordered_map<std::string, record> prototypes_;
|
mutable std::unordered_map<std::string, record> prototypes_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -74,7 +74,7 @@ entity<Type> session::insert(Type *obj)
|
||||||
if (!info) {
|
if (!info) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
c->query(schema_).insert().into<Type>(info->name).values(*obj).execute();
|
c->query(*schema_).insert().into<Type>(info->name).values(*obj).execute();
|
||||||
|
|
||||||
return entity{obj};
|
return entity{obj};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace matador::utils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Defines fetch types
|
* @brief Defines fetch types
|
||||||
*
|
*
|
||||||
|
|
@ -14,4 +16,6 @@ enum class fetch_type : uint8_t
|
||||||
EAGER /**< Indicates eager fetch */
|
EAGER /**< Indicates eager fetch */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif //QUERY_FETCH_TYPE_HPP
|
#endif //QUERY_FETCH_TYPE_HPP
|
||||||
|
|
|
||||||
|
|
@ -140,9 +140,7 @@ set(UTILS_SOURCES
|
||||||
|
|
||||||
add_library(matador STATIC
|
add_library(matador STATIC
|
||||||
${SQL_SOURCES} ${SQL_HEADER}
|
${SQL_SOURCES} ${SQL_HEADER}
|
||||||
# ${QUERY_SOURCES} ${QUERY_HEADER}
|
|
||||||
${UTILS_SOURCES} ${UTILS_HEADER}
|
${UTILS_SOURCES} ${UTILS_HEADER}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(matador PUBLIC ${PROJECT_SOURCE_DIR}/include)
|
target_include_directories(matador PUBLIC ${PROJECT_SOURCE_DIR}/include)
|
||||||
#set_target_properties(matador PROPERTIES LINKER_LANGUAGE CXX)
|
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ size_t connection::execute(const std::string &sql) const
|
||||||
return connection_->execute(sql);
|
return connection_->execute(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
sql::query connection::query(const std::shared_ptr<sql::schema> &schema) const
|
sql::query connection::query(const sql::schema &schema) const
|
||||||
{
|
{
|
||||||
return sql::query(*const_cast<connection*>(this), schema);
|
return sql::query(*const_cast<connection*>(this), schema);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,9 @@ std::string dialect::prepare_identifier(const column &col) const
|
||||||
} else {
|
} else {
|
||||||
result = sql_func_map_.at(col.function_) + "(" + col.name + ")";
|
result = sql_func_map_.at(col.function_) + "(" + col.name + ")";
|
||||||
}
|
}
|
||||||
// if (!col.alias.empty()) {
|
if (!col.alias.empty()) {
|
||||||
// result += " AS " + col.alias;
|
result += " AS " + col.alias;
|
||||||
// }
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
namespace matador::sql {
|
namespace matador::sql {
|
||||||
|
|
||||||
query::query(connection &db, const std::shared_ptr<sql::schema> &schema)
|
query::query(connection &db, const sql::schema &schema)
|
||||||
: connection_(db)
|
: connection_(db)
|
||||||
, schema_(schema)
|
, schema_(schema)
|
||||||
{}
|
{}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
#include "matador/sql/condition.hpp"
|
#include "matador/sql/condition.hpp"
|
||||||
|
|
||||||
namespace matador::sql {
|
namespace matador::sql {
|
||||||
basic_query_intermediate::basic_query_intermediate(connection &db, const std::shared_ptr<sql::schema> & schema)
|
basic_query_intermediate::basic_query_intermediate(connection &db, const sql::schema & schema)
|
||||||
: connection_(db)
|
: connection_(db)
|
||||||
, schema_(schema) {}
|
, schema_(schema) {}
|
||||||
|
|
||||||
|
|
@ -38,7 +38,7 @@ statement query_select_finish::prepare()
|
||||||
return connection_.prepare(compiler.compile(&data_));
|
return connection_.prepare(compiler.compile(&data_));
|
||||||
}
|
}
|
||||||
|
|
||||||
query_intermediate::query_intermediate(connection &db, const std::shared_ptr<sql::schema> &schema, query_data &data)
|
query_intermediate::query_intermediate(connection &db, const sql::schema &schema, query_data &data)
|
||||||
: basic_query_intermediate(db, schema), data_(data) {}
|
: basic_query_intermediate(db, schema), data_(data) {}
|
||||||
|
|
||||||
query_offset_intermediate query_limit_intermediate::offset(size_t offset)
|
query_offset_intermediate query_limit_intermediate::offset(size_t offset)
|
||||||
|
|
@ -73,7 +73,7 @@ query_order_direction_intermediate query_order_by_intermediate::asc()
|
||||||
|
|
||||||
query_order_direction_intermediate query_order_by_intermediate::desc()
|
query_order_direction_intermediate query_order_by_intermediate::desc()
|
||||||
{
|
{
|
||||||
data_.parts.push_back(std::make_unique<query_order_by_asc_part>());
|
data_.parts.push_back(std::make_unique<query_order_by_desc_part>());
|
||||||
return {connection_, schema_, data_};
|
return {connection_, schema_, data_};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,7 +143,7 @@ query_join_intermediate query_from_intermediate::join_left(const table &t)
|
||||||
return {connection_, schema_, data_};
|
return {connection_, schema_, data_};
|
||||||
}
|
}
|
||||||
|
|
||||||
query_select_intermediate::query_select_intermediate(connection &db, const std::shared_ptr<sql::schema> &schema, const std::vector<column>& columns)
|
query_select_intermediate::query_select_intermediate(connection &db, const sql::schema &schema, const std::vector<column>& columns)
|
||||||
: query_start_intermediate(db, schema)
|
: query_start_intermediate(db, schema)
|
||||||
{
|
{
|
||||||
data_.parts.push_back(std::make_unique<query_select_part>(columns));
|
data_.parts.push_back(std::make_unique<query_select_part>(columns));
|
||||||
|
|
@ -155,7 +155,7 @@ query_from_intermediate query_select_intermediate::from(const table& t)
|
||||||
return {connection_, schema_, data_};
|
return {connection_, schema_, data_};
|
||||||
}
|
}
|
||||||
|
|
||||||
query_insert_intermediate::query_insert_intermediate(connection &db, const std::shared_ptr<sql::schema> &schema)
|
query_insert_intermediate::query_insert_intermediate(connection &db, const sql::schema &schema)
|
||||||
: query_start_intermediate(db, schema)
|
: query_start_intermediate(db, schema)
|
||||||
{
|
{
|
||||||
data_.parts.push_back(std::make_unique<query_insert_part>());
|
data_.parts.push_back(std::make_unique<query_insert_part>());
|
||||||
|
|
@ -201,7 +201,7 @@ query_execute_finish query_into_intermediate::values(std::vector<any_type> &&val
|
||||||
return {connection_, schema_, data_};
|
return {connection_, schema_, data_};
|
||||||
}
|
}
|
||||||
|
|
||||||
query_create_intermediate::query_create_intermediate(connection &db, const std::shared_ptr<sql::schema> &schema)
|
query_create_intermediate::query_create_intermediate(connection &db, const sql::schema &schema)
|
||||||
: query_start_intermediate(db, schema) {
|
: query_start_intermediate(db, schema) {
|
||||||
data_.parts.push_back(std::make_unique<query_create_part>());
|
data_.parts.push_back(std::make_unique<query_create_part>());
|
||||||
}
|
}
|
||||||
|
|
@ -217,7 +217,7 @@ query_execute_finish query_create_intermediate::table(const sql::table &table, c
|
||||||
return {connection_, schema_, data_};
|
return {connection_, schema_, data_};
|
||||||
}
|
}
|
||||||
|
|
||||||
query_drop_intermediate::query_drop_intermediate(connection &db, const std::shared_ptr<sql::schema> &schema)
|
query_drop_intermediate::query_drop_intermediate(connection &db, const sql::schema &schema)
|
||||||
: query_start_intermediate(db, schema)
|
: query_start_intermediate(db, schema)
|
||||||
{
|
{
|
||||||
data_.parts.push_back(std::make_unique<query_drop_part>());
|
data_.parts.push_back(std::make_unique<query_drop_part>());
|
||||||
|
|
@ -241,7 +241,7 @@ query_execute_where_intermediate query_set_intermediate::where_clause(std::uniqu
|
||||||
return {connection_, schema_, data_};
|
return {connection_, schema_, data_};
|
||||||
}
|
}
|
||||||
|
|
||||||
query_update_intermediate::query_update_intermediate(connection &db, const std::shared_ptr<sql::schema> &schema, const sql::table& table)
|
query_update_intermediate::query_update_intermediate(connection &db, const sql::schema &schema, const sql::table& table)
|
||||||
: query_start_intermediate(db, schema)
|
: query_start_intermediate(db, schema)
|
||||||
{
|
{
|
||||||
data_.parts.push_back(std::make_unique<query_update_part>(table));
|
data_.parts.push_back(std::make_unique<query_update_part>(table));
|
||||||
|
|
@ -265,7 +265,7 @@ query_execute_where_intermediate query_delete_from_intermediate::where_clause(st
|
||||||
return {connection_, schema_, data_};
|
return {connection_, schema_, data_};
|
||||||
}
|
}
|
||||||
|
|
||||||
query_delete_intermediate::query_delete_intermediate(connection &db, const std::shared_ptr<sql::schema> &schema)
|
query_delete_intermediate::query_delete_intermediate(connection &db, const sql::schema &schema)
|
||||||
: query_start_intermediate(db, schema)
|
: query_start_intermediate(db, schema)
|
||||||
{
|
{
|
||||||
data_.parts.push_back(std::make_unique<query_delete_part>());
|
data_.parts.push_back(std::make_unique<query_delete_part>());
|
||||||
|
|
@ -277,7 +277,7 @@ query_delete_from_intermediate query_delete_intermediate::from(const sql::table
|
||||||
return {connection_, schema_, data_};
|
return {connection_, schema_, data_};
|
||||||
}
|
}
|
||||||
|
|
||||||
query_start_intermediate::query_start_intermediate(connection &db, const std::shared_ptr<sql::schema> &schema)
|
query_start_intermediate::query_start_intermediate(connection &db, const sql::schema &schema)
|
||||||
: basic_query_intermediate(db, schema)
|
: basic_query_intermediate(db, schema)
|
||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
|
|
@ -7,12 +7,12 @@ namespace matador::sql {
|
||||||
|
|
||||||
void table_info::create(connection &conn, schema &scm) const
|
void table_info::create(connection &conn, schema &scm) const
|
||||||
{
|
{
|
||||||
// conn.query().create().table(name, prototype.columns()).execute();
|
conn.query(scm).create().table(name, prototype.columns()).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
void table_info::drop(connection &conn, schema &scm) const
|
void table_info::drop(connection &conn, schema &scm) const
|
||||||
{
|
{
|
||||||
// conn.query().drop().table(name).execute();
|
conn.query(scm).drop().table(name).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
schema::schema(std::string name)
|
schema::schema(std::string name)
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ namespace matador::sql {
|
||||||
session::session(connection_pool<connection> &pool)
|
session::session(connection_pool<connection> &pool)
|
||||||
: pool_(pool)
|
: pool_(pool)
|
||||||
, dialect_(backend_provider::instance().connection_dialect(pool_.info().type))
|
, dialect_(backend_provider::instance().connection_dialect(pool_.info().type))
|
||||||
, schema_(std::make_shared<sql::schema>(dialect_.default_schema_name())){}
|
, schema_(std::make_unique<sql::schema>(dialect_.default_schema_name())){}
|
||||||
|
|
||||||
void session::create_schema()
|
void session::create_schema()
|
||||||
{
|
{
|
||||||
|
|
@ -26,7 +26,7 @@ void session::drop_table(const std::string &table_name)
|
||||||
throw std::logic_error("no database connection available");
|
throw std::logic_error("no database connection available");
|
||||||
}
|
}
|
||||||
|
|
||||||
c->query(schema_).drop().table(table_name).execute();
|
c->query(*schema_).drop().table(table_name).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
query_result<record> session::fetch(const query_context &q) const
|
query_result<record> session::fetch(const query_context &q) const
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ matador::utils::cascade_type matador::utils::foreign_attributes::cascade() const
|
||||||
return cascade_;
|
return cascade_;
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch_type matador::utils::foreign_attributes::fetch() const
|
matador::utils::fetch_type matador::utils::foreign_attributes::fetch() const
|
||||||
{
|
{
|
||||||
return fetch_;
|
return fetch_;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,12 @@ FetchContent_Declare(
|
||||||
|
|
||||||
FetchContent_MakeAvailable(Catch2)
|
FetchContent_MakeAvailable(Catch2)
|
||||||
|
|
||||||
add_executable(tests QueryBuilderTest.cpp
|
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
|
||||||
|
include(CTest)
|
||||||
|
include(Catch)
|
||||||
|
|
||||||
|
add_executable(tests
|
||||||
|
QueryBuilderTest.cpp
|
||||||
RecordTest.cpp
|
RecordTest.cpp
|
||||||
ConnectionPoolTest.cpp
|
ConnectionPoolTest.cpp
|
||||||
BackendProviderTest.cpp
|
BackendProviderTest.cpp
|
||||||
|
|
@ -39,3 +44,5 @@ target_link_libraries(tests PRIVATE
|
||||||
${SQLite3_LIBRARIES}
|
${SQLite3_LIBRARIES}
|
||||||
${PostgreSQL_LIBRARY})
|
${PostgreSQL_LIBRARY})
|
||||||
target_include_directories(tests PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>/include)
|
target_include_directories(tests PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>/include)
|
||||||
|
|
||||||
|
catch_discover_tests(tests)
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ using namespace matador::utils;
|
||||||
TEST_CASE("Create table sql statement string", "[query]")
|
TEST_CASE("Create table sql statement string", "[query]")
|
||||||
{
|
{
|
||||||
connection noop("noop://noop.db");
|
connection noop("noop://noop.db");
|
||||||
auto scm = std::make_shared<schema>("noop");
|
schema scm("noop");
|
||||||
query q(noop, scm);
|
query q(noop, scm);
|
||||||
auto result = q.create().table({"person"}, {
|
auto result = q.create().table({"person"}, {
|
||||||
make_pk_column<unsigned long>("id"),
|
make_pk_column<unsigned long>("id"),
|
||||||
|
|
@ -38,7 +38,7 @@ TEST_CASE("Create table sql statement string", "[query]")
|
||||||
TEST_CASE("Drop table sql statement string", "[query]")
|
TEST_CASE("Drop table sql statement string", "[query]")
|
||||||
{
|
{
|
||||||
connection noop("noop://noop.db");
|
connection noop("noop://noop.db");
|
||||||
auto scm = std::make_shared<schema>("noop");
|
schema scm("noop");
|
||||||
query q(noop, scm);
|
query q(noop, scm);
|
||||||
const auto result = q.drop().table("person").build();
|
const auto result = q.drop().table("person").build();
|
||||||
|
|
||||||
|
|
@ -49,7 +49,7 @@ TEST_CASE("Drop table sql statement string", "[query]")
|
||||||
TEST_CASE("Select sql statement string", "[query]")
|
TEST_CASE("Select sql statement string", "[query]")
|
||||||
{
|
{
|
||||||
connection noop("noop://noop.db");
|
connection noop("noop://noop.db");
|
||||||
auto scm = std::make_shared<schema>("noop");
|
schema scm("noop");
|
||||||
query q(noop, scm);
|
query q(noop, scm);
|
||||||
const auto result = q.select({"id", "name", "age"}).from("person").build();
|
const auto result = q.select({"id", "name", "age"}).from("person").build();
|
||||||
|
|
||||||
|
|
@ -60,7 +60,7 @@ TEST_CASE("Select sql statement string", "[query]")
|
||||||
TEST_CASE("Insert sql statement string", "[query]")
|
TEST_CASE("Insert sql statement string", "[query]")
|
||||||
{
|
{
|
||||||
connection noop("noop://noop.db");
|
connection noop("noop://noop.db");
|
||||||
auto scm = std::make_shared<schema>("noop");
|
schema scm("noop");
|
||||||
query q(noop, scm);
|
query q(noop, scm);
|
||||||
const auto result = q.insert().into("person", {
|
const auto result = q.insert().into("person", {
|
||||||
"id", "name", "age"
|
"id", "name", "age"
|
||||||
|
|
@ -73,7 +73,7 @@ TEST_CASE("Insert sql statement string", "[query]")
|
||||||
TEST_CASE("Update sql statement string", "[query]")
|
TEST_CASE("Update sql statement string", "[query]")
|
||||||
{
|
{
|
||||||
connection noop("noop://noop.db");
|
connection noop("noop://noop.db");
|
||||||
auto scm = std::make_shared<schema>("noop");
|
schema scm("noop");
|
||||||
query q(noop, scm);
|
query q(noop, scm);
|
||||||
const auto result = q.update("person").set({
|
const auto result = q.update("person").set({
|
||||||
{"id", 7UL},
|
{"id", 7UL},
|
||||||
|
|
@ -88,7 +88,7 @@ TEST_CASE("Update sql statement string", "[query]")
|
||||||
TEST_CASE("Update limit sql statement", "[query][update][limit]")
|
TEST_CASE("Update limit sql statement", "[query][update][limit]")
|
||||||
{
|
{
|
||||||
connection noop("noop://noop.db");
|
connection noop("noop://noop.db");
|
||||||
auto scm = std::make_shared<schema>("noop");
|
schema scm("noop");
|
||||||
query q(noop, scm);
|
query q(noop, scm);
|
||||||
const auto result = q.update("person")
|
const auto result = q.update("person")
|
||||||
.set({{"id", 7UL}, {"name", "george"}, {"age", 65U}})
|
.set({{"id", 7UL}, {"name", "george"}, {"age", 65U}})
|
||||||
|
|
@ -104,7 +104,7 @@ TEST_CASE("Update limit sql statement", "[query][update][limit]")
|
||||||
TEST_CASE("Delete sql statement string", "[query]")
|
TEST_CASE("Delete sql statement string", "[query]")
|
||||||
{
|
{
|
||||||
connection noop("noop://noop.db");
|
connection noop("noop://noop.db");
|
||||||
auto scm = std::make_shared<schema>("noop");
|
schema scm("noop");
|
||||||
query q(noop, scm);
|
query q(noop, scm);
|
||||||
const auto result = q.remove().from("person").build();
|
const auto result = q.remove().from("person").build();
|
||||||
|
|
||||||
|
|
@ -115,7 +115,7 @@ TEST_CASE("Delete sql statement string", "[query]")
|
||||||
TEST_CASE("Delete limit sql statement", "[query][delete][limit]")
|
TEST_CASE("Delete limit sql statement", "[query][delete][limit]")
|
||||||
{
|
{
|
||||||
connection noop("noop://noop.db");
|
connection noop("noop://noop.db");
|
||||||
auto scm = std::make_shared<schema>("noop");
|
schema scm("noop");
|
||||||
query q(noop, scm);
|
query q(noop, scm);
|
||||||
const auto result = q.remove()
|
const auto result = q.remove()
|
||||||
.from("person")
|
.from("person")
|
||||||
|
|
@ -131,7 +131,7 @@ TEST_CASE("Delete limit sql statement", "[query][delete][limit]")
|
||||||
TEST_CASE("Select sql statement string with where clause", "[query]")
|
TEST_CASE("Select sql statement string with where clause", "[query]")
|
||||||
{
|
{
|
||||||
connection noop("noop://noop.db");
|
connection noop("noop://noop.db");
|
||||||
auto scm = std::make_shared<schema>("noop");
|
schema scm("noop");
|
||||||
query q(noop, scm);
|
query q(noop, scm);
|
||||||
auto result = q.select({"id", "name", "age"})
|
auto result = q.select({"id", "name", "age"})
|
||||||
.from("person")
|
.from("person")
|
||||||
|
|
@ -153,7 +153,7 @@ TEST_CASE("Select sql statement string with where clause", "[query]")
|
||||||
TEST_CASE("Insert sql statement with placeholder", "[query]")
|
TEST_CASE("Insert sql statement with placeholder", "[query]")
|
||||||
{
|
{
|
||||||
connection noop("noop://noop.db");
|
connection noop("noop://noop.db");
|
||||||
auto scm = std::make_shared<schema>("noop");
|
schema scm("noop");
|
||||||
query q(noop, scm);
|
query q(noop, scm);
|
||||||
const auto result = q.insert().into("person", {
|
const auto result = q.insert().into("person", {
|
||||||
"id", "name", "age"
|
"id", "name", "age"
|
||||||
|
|
@ -167,7 +167,7 @@ TEST_CASE("Insert sql statement with placeholder", "[query]")
|
||||||
TEST_CASE("Select sql statement string with order by", "[query]")
|
TEST_CASE("Select sql statement string with order by", "[query]")
|
||||||
{
|
{
|
||||||
connection noop("noop://noop.db");
|
connection noop("noop://noop.db");
|
||||||
auto scm = std::make_shared<schema>("noop");
|
schema scm("noop");
|
||||||
query q(noop, scm);
|
query q(noop, scm);
|
||||||
const auto result = q.select({"id", "name", "age"})
|
const auto result = q.select({"id", "name", "age"})
|
||||||
.from("person")
|
.from("person")
|
||||||
|
|
@ -181,7 +181,7 @@ TEST_CASE("Select sql statement string with order by", "[query]")
|
||||||
TEST_CASE("Select sql statement string with group by", "[query]")
|
TEST_CASE("Select sql statement string with group by", "[query]")
|
||||||
{
|
{
|
||||||
connection noop("noop://noop.db");
|
connection noop("noop://noop.db");
|
||||||
auto scm = std::make_shared<schema>("noop");
|
schema scm("noop");
|
||||||
query q(noop, scm);
|
query q(noop, scm);
|
||||||
const auto result = q.select({"id", "name", "age"})
|
const auto result = q.select({"id", "name", "age"})
|
||||||
.from("person")
|
.from("person")
|
||||||
|
|
@ -195,7 +195,7 @@ TEST_CASE("Select sql statement string with group by", "[query]")
|
||||||
TEST_CASE("Select sql statement string with offset and limit", "[query]")
|
TEST_CASE("Select sql statement string with offset and limit", "[query]")
|
||||||
{
|
{
|
||||||
connection noop("noop://noop.db");
|
connection noop("noop://noop.db");
|
||||||
auto scm = std::make_shared<schema>("noop");
|
schema scm("noop");
|
||||||
query q(noop, scm);
|
query q(noop, scm);
|
||||||
const auto result = q.select({"id", "name", "age"})
|
const auto result = q.select({"id", "name", "age"})
|
||||||
.from("person")
|
.from("person")
|
||||||
|
|
@ -211,7 +211,7 @@ TEST_CASE("Select sql statement string with offset and limit", "[query]")
|
||||||
TEST_CASE("Create, insert and select a blob column", "[query][blob]")
|
TEST_CASE("Create, insert and select a blob column", "[query][blob]")
|
||||||
{
|
{
|
||||||
connection noop("noop://noop.db");
|
connection noop("noop://noop.db");
|
||||||
auto scm = std::make_shared<schema>("noop");
|
schema scm("noop");
|
||||||
query q(noop, scm);
|
query q(noop, scm);
|
||||||
auto result = q.create().table("person", {
|
auto result = q.create().table("person", {
|
||||||
make_pk_column<unsigned long>("id"),
|
make_pk_column<unsigned long>("id"),
|
||||||
|
|
@ -238,7 +238,7 @@ TEST_CASE("Create, insert and select a blob column", "[query][blob]")
|
||||||
TEST_CASE("Select statement with join_left", "[query][join_left]")
|
TEST_CASE("Select statement with join_left", "[query][join_left]")
|
||||||
{
|
{
|
||||||
connection noop("noop://noop.db");
|
connection noop("noop://noop.db");
|
||||||
auto scm = std::make_shared<schema>("noop");
|
schema scm("noop");
|
||||||
query q(noop, scm);
|
query q(noop, scm);
|
||||||
auto result = q.select({"f.id", "ap.brand", "f.pilot_name"})
|
auto result = q.select({"f.id", "ap.brand", "f.pilot_name"})
|
||||||
.from({"flight", "f"})
|
.from({"flight", "f"})
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include "matador/utils/access.hpp"
|
#include "matador/utils/access.hpp"
|
||||||
#include "matador/utils/cascade_type.hpp"
|
#include "matador/utils/cascade_type.hpp"
|
||||||
|
#include "matador/utils/fetch_type.hpp"
|
||||||
#include "matador/utils/field_attributes.hpp"
|
#include "matador/utils/field_attributes.hpp"
|
||||||
|
|
||||||
#include "matador/sql/entity.hpp"
|
#include "matador/sql/entity.hpp"
|
||||||
|
|
@ -29,7 +30,7 @@ struct flight
|
||||||
namespace field = matador::utils::access;
|
namespace field = matador::utils::access;
|
||||||
using namespace matador::utils;
|
using namespace matador::utils;
|
||||||
field::primary_key(op, "id", id);
|
field::primary_key(op, "id", id);
|
||||||
field::has_one(op, "airplane_id", airplane, utils::cascade_type::ALL);
|
field::has_one(op, "airplane_id", airplane, {utils::cascade_type::ALL, utils::fetch_type::EAGER});
|
||||||
field::attribute(op, "pilot_name", pilot_name, 255);
|
field::attribute(op, "pilot_name", pilot_name, 255);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ struct order
|
||||||
field::attribute(op, "ship_region", ship_region, 255);
|
field::attribute(op, "ship_region", ship_region, 255);
|
||||||
field::attribute(op, "ship_postal_code", ship_postal_code, 255);
|
field::attribute(op, "ship_postal_code", ship_postal_code, 255);
|
||||||
field::attribute(op, "ship_country", ship_country, 255);
|
field::attribute(op, "ship_country", ship_country, 255);
|
||||||
field::has_many(op, "order_details", order_details_, fetch_type::EAGER);
|
field::has_many(op, "order_details", order_details_, utils::fetch_type::EAGER);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue