Skip to content

Commit

Permalink
added highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
fnc12 committed Sep 22, 2023
1 parent dbc9144 commit 856132b
Show file tree
Hide file tree
Showing 15 changed files with 275 additions and 265 deletions.
26 changes: 13 additions & 13 deletions dev/ast/match.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
namespace sqlite_orm {
namespace internal {

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

argument_type argument;
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)};
}
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)};
}

}
10 changes: 5 additions & 5 deletions dev/ast/rank.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace sqlite_orm {
namespace internal {
struct rank_t {};
}
struct rank_t {};
}

inline internal::rank_t rank() {
return {};
}
inline internal::rank_t rank() {
return {};
}
}
12 changes: 12 additions & 0 deletions dev/ast_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ namespace sqlite_orm {
}
};

template<class T, class X, class Y, class Z>
struct ast_iterator<highlight_t<T, X, Y, Z>, void> {
using node_type = highlight_t<T, X, Y, Z>;

template<class L>
void operator()(const node_type& expression, L& lambda) const {
iterate_ast(expression.argument0, lambda);
iterate_ast(expression.argument1, lambda);
iterate_ast(expression.argument2, lambda);
}
};

template<class T>
struct ast_iterator<excluded_t<T>, void> {
using node_type = excluded_t<T>;
Expand Down
5 changes: 5 additions & 0 deletions dev/column_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ namespace sqlite_orm {
using type = typename T::result_type;
};

template<class DBOs, class T, class X, class Y, class Z>
struct column_result_t<DBOs, highlight_t<T, X, Y, Z>, void> {
using type = std::string;
};

/**
* Result for the most simple queries like `SELECT 1`
*/
Expand Down
4 changes: 2 additions & 2 deletions dev/conditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,13 @@ namespace sqlite_orm {
};

template<class L, class R>
struct is_equal_with_table_t: negatable_t {
struct is_equal_with_table_t : negatable_t {
using left_type = L;
using right_type = R;

right_type rhs;

is_equal_with_table_t(right_type rhs): rhs(std::move(rhs)) {}
is_equal_with_table_t(right_type rhs) : rhs(std::move(rhs)) {}
};

struct is_not_equal_string {
Expand Down
20 changes: 20 additions & 0 deletions dev/core_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,21 @@ namespace sqlite_orm {

template<class T>
using field_type_or_type_t = polyfill::detected_or_t<T, type_t, member_field_type<T>>;

template<class T, class X, class Y, class Z>
struct highlight_t {
using table_type = T;
using argument0_type = X;
using argument1_type = Y;
using argument2_type = Z;

argument0_type argument0;
argument1_type argument1;
argument2_type argument2;

highlight_t(argument0_type argument0, argument1_type argument1, argument2_type argument2) :
argument0(std::move(argument0)), argument1(std::move(argument1)), argument2(std::move(argument2)) {}
};
}

/**
Expand Down Expand Up @@ -2102,4 +2117,9 @@ namespace sqlite_orm {
return {get_from_expression(std::forward<L>(l)), get_from_expression(std::forward<R>(r))};
}
}

template<class T, class X, class Y, class Z>
internal::highlight_t<T, X, Y, Z> highlight(X x, Y y, Z z) {
return {std::move(x), std::move(y), std::move(z)};
}
}
8 changes: 8 additions & 0 deletions dev/node_tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ namespace sqlite_orm {
using type = tuple_cat_t<node_tuple_t<Args>...>;
};

template<class T, class X, class Y, class Z>
struct node_tuple<highlight_t<T, X, Y, Z>, void> {
using x_node_tuple = node_tuple_t<X>;
using y_node_tuple = node_tuple_t<Y>;
using z_node_tuple = node_tuple_t<Z>;
using type = tuple_cat_t<x_node_tuple, y_node_tuple, z_node_tuple>;
};

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

Expand Down
20 changes: 9 additions & 11 deletions dev/schema/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ namespace sqlite_orm {
struct is_table<table_t<O, W, Cs...>> : std::true_type {};

template<class M>
struct virtual_table_t: basic_table {
struct virtual_table_t : basic_table {
using module_details_type = M;
using object_type = typename module_details_type::object_type;
using elements_type = typename module_details_type::columns_type;
Expand All @@ -277,7 +277,7 @@ namespace sqlite_orm {

module_details_type module_details;

virtual_table_t(std::string name, module_details_type module_details):
virtual_table_t(std::string name, module_details_type module_details) :
basic_table{std::move(name)}, module_details{std::move(module_details)} {}

/**
Expand Down Expand Up @@ -321,7 +321,7 @@ namespace sqlite_orm {

columns_type columns;

using_fts5_t(columns_type columns): columns(std::move(columns)) {}
using_fts5_t(columns_type columns) : columns(std::move(columns)) {}

/**
* Call passed lambda with columns not having the specified constraint trait `OpTrait`.
Expand Down Expand Up @@ -353,7 +353,8 @@ namespace sqlite_orm {
};

template<class O, bool WithoutRowId, class... Cs, class G, class S>
bool exists_in_composite_primary_key(const table_t<O, WithoutRowId, Cs...> &table, const column_field<G, S>& column) {
bool exists_in_composite_primary_key(const table_t<O, WithoutRowId, Cs...>& table,
const column_field<G, S>& column) {
bool res = false;
table.for_each_primary_key([&column, &res](auto& primaryKey) {
using colrefs_tuple = decltype(primaryKey.columns);
Expand All @@ -362,8 +363,7 @@ namespace sqlite_orm {
check_if_is_type<member_field_type_t<G>>::template fn,
member_field_type_t>;
iterate_tuple(primaryKey.columns, same_type_index_sequence{}, [&res, &column](auto& memberPointer) {
if(compare_any(memberPointer, column.member_pointer) ||
compare_any(memberPointer, column.setter)) {
if(compare_any(memberPointer, column.member_pointer) || compare_any(memberPointer, column.setter)) {
res = true;
}
});
Expand All @@ -372,21 +372,19 @@ namespace sqlite_orm {
}

template<class M, class G, class S>
bool exists_in_composite_primary_key(const virtual_table_t<M> &virtualTable, const column_field<G, S>& column) {
bool exists_in_composite_primary_key(const virtual_table_t<M>& virtualTable, const column_field<G, S>& column) {
return false;
}
}

template<class... Cs, class T = typename std::tuple_element_t<0, std::tuple<Cs...>>::object_type>
internal::using_fts5_t<T, Cs...> using_fts5(Cs... columns) {
SQLITE_ORM_CLANG_SUPPRESS_MISSING_BRACES(
return {std::make_tuple(std::forward<Cs>(columns)...)});
SQLITE_ORM_CLANG_SUPPRESS_MISSING_BRACES(return {std::make_tuple(std::forward<Cs>(columns)...)});
}

template<class T, class... Cs>
internal::using_fts5_t<T, Cs...> using_fts5(Cs... columns) {
SQLITE_ORM_CLANG_SUPPRESS_MISSING_BRACES(
return {std::make_tuple(std::forward<Cs>(columns)...)});
SQLITE_ORM_CLANG_SUPPRESS_MISSING_BRACES(return {std::make_tuple(std::forward<Cs>(columns)...)});
}

/**
Expand Down
12 changes: 7 additions & 5 deletions dev/serializer_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ namespace sqlite_orm {
};

template<class DBOs>
struct serializer_context_with_no_types_and_constraints: serializer_context<DBOs> {
struct serializer_context_with_no_types_and_constraints : serializer_context<DBOs> {
using super = serializer_context<DBOs>;

serializer_context_with_no_types_and_constraints(const super &parentContext): super(parentContext) {}
serializer_context_with_no_types_and_constraints(const super& parentContext) : super(parentContext) {}
};

template<class DBOs>
serializer_context_with_no_types_and_constraints<DBOs> make_serializer_context_with_no_types_and_constraints(const serializer_context<DBOs> &parentContext) {
serializer_context_with_no_types_and_constraints<DBOs>
make_serializer_context_with_no_types_and_constraints(const serializer_context<DBOs>& parentContext) {
return {parentContext};
}

Expand All @@ -46,10 +47,11 @@ namespace sqlite_orm {
};

template<class T>
struct no_need_types_and_constraints: std::false_type {};
struct no_need_types_and_constraints : std::false_type {};

template<class DBOs>
struct no_need_types_and_constraints<serializer_context_with_no_types_and_constraints<DBOs>>: std::true_type {};
struct no_need_types_and_constraints<serializer_context_with_no_types_and_constraints<DBOs>> : std::true_type {
};
}

}
30 changes: 23 additions & 7 deletions dev/statement_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,22 @@ namespace sqlite_orm {
}
};

template<class T, class X, class Y, class Z>
struct statement_serializer<highlight_t<T, X, Y, Z>, void> {
using statement_type = highlight_t<T, X, Y, Z>;

template<class Ctx>
std::string operator()(const statement_type& statement, const Ctx& context) {
std::stringstream ss;
auto& tableName = lookup_table_name<T>(context.db_objects);
ss << "HIGHLIGHT (" << streaming_identifier(tableName);
ss << ", " << serialize(statement.argument0, context);
ss << ", " << serialize(statement.argument1, context);
ss << ", " << serialize(statement.argument2, context) << ")";
return ss.str();
}
};

/**
* Serializer for literal values.
*/
Expand All @@ -142,7 +158,7 @@ namespace sqlite_orm {
using statement_type = T;

template<class Ctx>
std::string operator()(const T& literal, const Ctx& context) const {
std::string operator()(const statement_type& literal, const Ctx& context) const {
static_assert(is_bindable_v<type_t<T>>, "A literal value must be also bindable");

Ctx literalCtx = context;
Expand Down Expand Up @@ -970,13 +986,13 @@ namespace sqlite_orm {

std::stringstream ss;
ss << streaming_identifier(column.name);
if (!no_need_types_and_constraints<Ctx>::value) {
if(!no_need_types_and_constraints<Ctx>::value) {
ss << " " << type_printer<field_type_t<column_type>>().print();
auto constraintsTuple = streaming_column_constraints(
call_as_template_base<column_constraints>(polyfill::identity{})(column),
column.is_not_null(),
context);
if (std::tuple_size<decltype(constraintsTuple)>::value > 0) {
call_as_template_base<column_constraints>(polyfill::identity{})(column),
column.is_not_null(),
context);
if(std::tuple_size<decltype(constraintsTuple)>::value > 0) {
ss << " " << constraintsTuple;
}
}
Expand Down Expand Up @@ -1220,7 +1236,7 @@ namespace sqlite_orm {
using statement_type = match_t<T, X>;

template<class Ctx>
std::string operator()(const statement_type &statement, const Ctx& context) const {
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);
Expand Down
3 changes: 2 additions & 1 deletion dev/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,8 @@ namespace sqlite_orm {
context.replace_bindable_with_question = true;

auto con = this->get_connection();
sqlite3_stmt* stmt = prepare_stmt(con.get(), serialize(statement, context));
const auto sql = serialize(statement, context);
sqlite3_stmt* stmt = prepare_stmt(con.get(), sql);
return prepared_statement_t<S>{std::forward<S>(statement), stmt, con};
}

Expand Down
5 changes: 5 additions & 0 deletions dev/table_name_collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ namespace sqlite_orm {
void operator()(const table__rowid_t<T>&) {
this->table_names.emplace(lookup_table_name<T>(this->db_objects), "");
}

template<class T, class X, class Y, class Z>
void operator()(const highlight_t<T, X, Y, Z>&) {
this->table_names.emplace(lookup_table_name<T>(this->db_objects), "");
}
};

template<class DBOs, satisfies<is_db_objects, DBOs> = true>
Expand Down
Loading

0 comments on commit 856132b

Please sign in to comment.