Skip to content

Commit

Permalink
added rank
Browse files Browse the repository at this point in the history
  • Loading branch information
fnc12 committed Sep 21, 2023
1 parent b3ced5e commit dbc9144
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 5 deletions.
11 changes: 11 additions & 0 deletions dev/ast/rank.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

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

inline internal::rank_t rank() {
return {};
}
}
15 changes: 13 additions & 2 deletions dev/statement_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "ast/group_by.h"
#include "ast/into.h"
#include "ast/match.h"
#include "ast/rank.h"
#include "core_functions.h"
#include "constraints.h"
#include "conditions.h"
Expand Down Expand Up @@ -341,13 +342,23 @@ namespace sqlite_orm {
}
};

template<>
struct statement_serializer<rank_t, void> {
using statement_type = rank_t;

template<class Ctx>
std::string operator()(const statement_type& /*statement*/, const Ctx&) const {
return "rank";
}
};

template<>
struct statement_serializer<rowid_t, void> {
using statement_type = rowid_t;

template<class Ctx>
std::string operator()(const statement_type& s, const Ctx&) const {
return static_cast<std::string>(s);
std::string operator()(const statement_type& statement, const Ctx&) const {
return static_cast<std::string>(statement);
}
};

Expand Down
27 changes: 25 additions & 2 deletions include/sqlite_orm/sqlite_orm.h
Original file line number Diff line number Diff line change
Expand Up @@ -15459,6 +15459,19 @@ namespace sqlite_orm {

// #include "ast/match.h"

// #include "ast/rank.h"


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

inline internal::rank_t rank() {
return {};
}
}

// #include "core_functions.h"

// #include "constraints.h"
Expand Down Expand Up @@ -16005,13 +16018,23 @@ namespace sqlite_orm {
}
};

template<>
struct statement_serializer<rank_t, void> {
using statement_type = rank_t;

template<class Ctx>
std::string operator()(const statement_type& /*statement*/, const Ctx&) const {
return "rank";
}
};

template<>
struct statement_serializer<rowid_t, void> {
using statement_type = rowid_t;

template<class Ctx>
std::string operator()(const statement_type& s, const Ctx&) const {
return static_cast<std::string>(s);
std::string operator()(const statement_type& statement, const Ctx&) const {
return static_cast<std::string>(statement);
}
};

Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ add_executable(unit_tests
statement_serializer_tests/ast/excluded.cpp
statement_serializer_tests/ast/set.cpp
statement_serializer_tests/ast/match.cpp
statement_serializer_tests/ast/rank.cpp
statement_serializer_tests/arithmetic_operators.cpp
statement_serializer_tests/base_types.cpp
statement_serializer_tests/collate.cpp
Expand Down
2 changes: 1 addition & 1 deletion tests/schema/virtual_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ TEST_CASE("virtual table") {
/// FROM posts
/// WHERE posts MATCH 'text'
/// ORDER BY rank;
auto orderedPosts = storage.get_all<Post>(where(match<Post>("fts5"), order_by(rank())));
auto orderedPosts = storage.get_all<Post>(where(match<Post>("fts5")), order_by(rank()));
}
24 changes: 24 additions & 0 deletions tests/statement_serializer_tests/ast/rank.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <sqlite_orm/sqlite_orm.h>
#include <catch2/catch_all.hpp>

using namespace sqlite_orm;

TEST_CASE("statement_serializer rank") {
using db_objects_t = internal::db_objects_tuple<>;
auto dbObjects = db_objects_t{};
using context_t = internal::serializer_context<db_objects_t>;
context_t context{dbObjects};
std::string value;
std::string expected;
SECTION("rank") {
auto node = rank();
value = serialize(node, context);
expected = "rank";
}
SECTION("order by rank") {
auto node = order_by(rank());
value = serialize(node, context);
expected = "ORDER BY rank";
}
REQUIRE(value == expected);
}

0 comments on commit dbc9144

Please sign in to comment.