From b11993d60b57116ce850f2756aeeba4e4ef9e459 Mon Sep 17 00:00:00 2001 From: Sascha Kuehl Date: Sun, 18 Feb 2024 19:58:56 +0100 Subject: [PATCH] small query compiler progress --- demo/main.cpp | 7 ++++++- include/matador/sql/query_intermediates.hpp | 2 ++ src/sql/query_intermediates.cpp | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/demo/main.cpp b/demo/main.cpp index affdc22..21b5036 100644 --- a/demo/main.cpp +++ b/demo/main.cpp @@ -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(); 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(); // 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]; diff --git a/include/matador/sql/query_intermediates.hpp b/include/matador/sql/query_intermediates.hpp index 170b36c..3d5b5fc 100644 --- a/include/matador/sql/query_intermediates.hpp +++ b/include/matador/sql/query_intermediates.hpp @@ -73,6 +73,8 @@ public: statement prepare(); + std::string str() const; + private: std::unique_ptr fetch(); }; diff --git a/src/sql/query_intermediates.cpp b/src/sql/query_intermediates.cpp index 26cc349..92a58c3 100644 --- a/src/sql/query_intermediates.cpp +++ b/src/sql/query_intermediates.cpp @@ -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_select_finish::fetch() { query_compiler compiler(connection_.dialect());