small query compiler progress
This commit is contained in:
parent
a3f467a5a8
commit
b11993d60b
|
|
@ -41,6 +41,7 @@ struct book
|
|||
namespace field = matador::utils::access;
|
||||
field::primary_key(op, "id", id);
|
||||
field::attribute(op, "title", title, 511);
|
||||
field::has_one(op, "authors", book_author, matador::utils::default_foreign_attributes);
|
||||
field::attribute(op, "published_in", published_in);
|
||||
}
|
||||
};
|
||||
|
|
@ -50,7 +51,8 @@ int main()
|
|||
using namespace matador::sql;
|
||||
const std::string env_var{"MATADOR_BACKENDS_PATH"};
|
||||
|
||||
std::string dns;
|
||||
std::string dns{"sqlite://demo.db"};
|
||||
// std::string dns{"memory://test"};
|
||||
auto s = std::make_shared<schema>();
|
||||
connection c(dns, s);
|
||||
|
||||
|
|
@ -61,6 +63,8 @@ int main()
|
|||
.on("book.author_id"_col == "author.id"_col)
|
||||
.where("book.published_in"_col < 2008 && "author.name"_col == "Michael Crichton")
|
||||
.order_by("book.title").asc()
|
||||
.offset(2)
|
||||
.limit(5)
|
||||
.fetch_all<book>();
|
||||
|
||||
// SELECT book.title, book.id, book.author_id, book.published_in, author.name
|
||||
|
|
@ -68,6 +72,7 @@ int main()
|
|||
// INNER JOIN author ON book.author_id = author.id
|
||||
// WHERE book.published_in < 2008 AND author.name = "Michael Crichton"
|
||||
// ORDER BY "book.title" ASC
|
||||
// OFFSET 2 LIMIT 5
|
||||
|
||||
|
||||
// char var[1024];
|
||||
|
|
|
|||
|
|
@ -73,6 +73,8 @@ public:
|
|||
|
||||
statement prepare();
|
||||
|
||||
std::string str() const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<query_result_impl> fetch();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -23,6 +23,12 @@ record query_select_finish::fetch_one()
|
|||
return *connection_.fetch(compiler.compile(&data_)).begin().get();
|
||||
}
|
||||
|
||||
std::string query_select_finish::str() const
|
||||
{
|
||||
query_compiler compiler(connection_.dialect());
|
||||
return compiler.compile(&data_).sql;
|
||||
}
|
||||
|
||||
std::unique_ptr<query_result_impl> query_select_finish::fetch()
|
||||
{
|
||||
query_compiler compiler(connection_.dialect());
|
||||
|
|
|
|||
Loading…
Reference in New Issue