Skip to content

Commit

Permalink
Merge pull request #1213 from fnc12/fts5
Browse files Browse the repository at this point in the history
added match
  • Loading branch information
fnc12 authored Sep 30, 2023
2 parents fccff09 + 7396afc commit eb7ea99
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 2 deletions.
21 changes: 21 additions & 0 deletions dev/ast/match.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

namespace sqlite_orm {
namespace internal {

template<class T, class X>
struct match_t {
using mapped_type = T;
using argument_type = X;

argument_type argument;

match_t(argument_type argument) : argument(std::move(argument)) {}
};
}

template<class T, class X>
internal::match_t<T, X> match(X argument) {
return {std::move(argument)};
}
}
11 changes: 11 additions & 0 deletions dev/ast_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "ast/group_by.h"
#include "ast/exists.h"
#include "ast/set.h"
#include "ast/match.h"

namespace sqlite_orm {

Expand Down Expand Up @@ -85,6 +86,16 @@ namespace sqlite_orm {
}
};

template<class T, class X>
struct ast_iterator<match_t<T, X>, void> {
using node_type = match_t<T, X>;

template<class L>
void operator()(const node_type& node, L& lambda) const {
iterate_ast(node.argument, lambda);
}
};

template<class... Args>
struct ast_iterator<group_by_t<Args...>, void> {
using node_type = group_by_t<Args...>;
Expand Down
4 changes: 4 additions & 0 deletions dev/node_tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "ast/where.h"
#include "ast/into.h"
#include "ast/group_by.h"
#include "ast/match.h"

namespace sqlite_orm {

Expand Down Expand Up @@ -68,6 +69,9 @@ namespace sqlite_orm {
template<class C>
struct node_tuple<where_t<C>, void> : node_tuple<C> {};

template<class T, class X>
struct node_tuple<match_t<T, X>, void> : node_tuple<X> {};

/**
* Column alias
*/
Expand Down
14 changes: 14 additions & 0 deletions dev/statement_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "ast/excluded.h"
#include "ast/group_by.h"
#include "ast/into.h"
#include "ast/match.h"
#include "core_functions.h"
#include "constraints.h"
#include "conditions.h"
Expand Down Expand Up @@ -212,6 +213,19 @@ namespace sqlite_orm {
}
};

template<class T, class X>
struct statement_serializer<match_t<T, X>, void> {
using statement_type = match_t<T, X>;

template<class Ctx>
std::string operator()(const statement_type& statement, const Ctx& context) const {
auto& table = pick_table<T>(context.db_objects);
std::stringstream ss;
ss << streaming_identifier(table.name) << " MATCH " << serialize(statement.argument, context);
return ss.str();
}
};

template<char... C>
struct statement_serializer<column_alias<C...>, void> {
using statement_type = column_alias<C...>;
Expand Down
52 changes: 52 additions & 0 deletions include/sqlite_orm/sqlite_orm.h
Original file line number Diff line number Diff line change
Expand Up @@ -12357,6 +12357,28 @@ namespace sqlite_orm {

// #include "ast/set.h"

// #include "ast/match.h"

namespace sqlite_orm {
namespace internal {

template<class T, class X>
struct match_t {
using mapped_type = T;
using argument_type = X;

argument_type argument;

match_t(argument_type argument) : argument(std::move(argument)) {}
};
}

template<class T, class X>
internal::match_t<T, X> match(X argument) {
return {std::move(argument)};
}
}

namespace sqlite_orm {

namespace internal {
Expand Down Expand Up @@ -12421,6 +12443,16 @@ namespace sqlite_orm {
}
};

template<class T, class X>
struct ast_iterator<match_t<T, X>, void> {
using node_type = match_t<T, X>;

template<class L>
void operator()(const node_type& node, L& lambda) const {
iterate_ast(node.argument, lambda);
}
};

template<class... Args>
struct ast_iterator<group_by_t<Args...>, void> {
using node_type = group_by_t<Args...>;
Expand Down Expand Up @@ -15142,6 +15174,8 @@ namespace sqlite_orm {

// #include "ast/into.h"

// #include "ast/match.h"

// #include "core_functions.h"

// #include "constraints.h"
Expand Down Expand Up @@ -15556,6 +15590,19 @@ namespace sqlite_orm {
}
};

template<class T, class X>
struct statement_serializer<match_t<T, X>, void> {
using statement_type = match_t<T, X>;

template<class Ctx>
std::string operator()(const statement_type& statement, const Ctx& context) const {
auto& table = pick_table<T>(context.db_objects);
std::stringstream ss;
ss << streaming_identifier(table.name) << " MATCH " << serialize(statement.argument, context);
return ss.str();
}
};

template<char... C>
struct statement_serializer<column_alias<C...>, void> {
using statement_type = column_alias<C...>;
Expand Down Expand Up @@ -18836,6 +18883,8 @@ namespace sqlite_orm {

// #include "ast/group_by.h"

// #include "ast/match.h"

namespace sqlite_orm {

namespace internal {
Expand Down Expand Up @@ -18883,6 +18932,9 @@ namespace sqlite_orm {
template<class C>
struct node_tuple<where_t<C>, void> : node_tuple<C> {};

template<class T, class X>
struct node_tuple<match_t<T, X>, void> : node_tuple<X> {};

/**
* Column alias
*/
Expand Down
5 changes: 5 additions & 0 deletions tests/ast_iterator_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ TEST_CASE("ast_iterator") {
auto node = into<User>();
iterate_ast(node, lambda);
}
SECTION("match") {
auto node = match<User>(std::string("Plazma"));
expected.push_back(typeid(std::string));
iterate_ast(node, lambda);
}
SECTION("replace") {
auto node =
replace(into<User>(), columns(&User::id, &User::name), values(std::make_tuple(1, std::string("Ellie"))));
Expand Down
1 change: 0 additions & 1 deletion tests/private_getters_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <sqlite_orm/sqlite_orm.h>
#include <iostream>
#include <catch2/catch_all.hpp>

using namespace sqlite_orm;
Expand Down
6 changes: 6 additions & 0 deletions tests/static_tests/node_tuple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@ TEST_CASE("Node tuple") {
using Tuple = node_tuple_t<Expression>;
STATIC_REQUIRE(is_same<Tuple, tuple<>>::value);
}
SECTION("match") {
auto expression = match<User>(std::string("Plazma"));
using Expression = decltype(expression);
using Tuple = node_tuple_t<Expression>;
STATIC_REQUIRE(is_same<Tuple, tuple<std::string>>::value);
}
SECTION("select") {
SECTION("select(&User::id)") {
auto sel = select(&User::id);
Expand Down
1 change: 0 additions & 1 deletion tests/sync_schema_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <sqlite_orm/sqlite_orm.h>
#include <iostream>
#include <catch2/catch_all.hpp>

using namespace sqlite_orm;
Expand Down

0 comments on commit eb7ea99

Please sign in to comment.