added query helper macro and join query parts

This commit is contained in:
2024-02-19 22:57:43 +01:00
parent b11993d60b
commit b255ae22b4
14 changed files with 234 additions and 32 deletions
+17 -4
View File
@@ -6,6 +6,9 @@
#include "matador/utils/access.hpp"
#include "query_helper.hpp"
#include <iostream>
#include <string>
struct author
@@ -46,26 +49,36 @@ struct book
}
};
QUERY_HELPER(author, id, first_name, last_name, date_of_birth, year_of_birth, distinguished)
QUERY_HELPER(book, id, book_author, title, published_in)
int main()
{
using namespace matador::sql;
const std::string env_var{"MATADOR_BACKENDS_PATH"};
std::string dns{"sqlite://demo.db"};
// std::string dns{"memory://test"};
auto s = std::make_shared<schema>();
s->attach<author>("authors");
s->attach<book>("books");
connection c(dns, s);
auto books = c.query()
.select<book>({"author.name"})
.from("book")
.join_left("author")
.select<book>({qh::book.id.name})
.from({"book"})
.join_left({"authors"})
.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>();
.str();
// .fetch_all<book>();
std::cout << "SQL: " << books << "\n";
// SELECT book.title, book.id, book.author_id, book.published_in, author.name
// FROM book