Skip to content

Commit

Permalink
Merge branch 'dev' into feature/fts5
Browse files Browse the repository at this point in the history
  • Loading branch information
fnc12 committed Oct 5, 2023
2 parents 47235a3 + afdbde0 commit b85f3f2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 81 deletions.
21 changes: 1 addition & 20 deletions dev/serializer_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace sqlite_orm {
bool replace_bindable_with_question = false;
bool skip_table_name = true;
bool use_parentheses = true;
bool skip_types_and_constraints = false;
};

template<class DBOs>
Expand All @@ -19,19 +20,6 @@ namespace sqlite_orm {
serializer_context(const db_objects_type& dbObjects) : db_objects{dbObjects} {}
};

template<class 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) {}
};

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

template<class S>
struct serializer_context_builder {
using storage_type = S;
Expand All @@ -45,13 +33,6 @@ namespace sqlite_orm {

const storage_type& storage;
};

template<class T>
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 {
};
}

}
8 changes: 5 additions & 3 deletions dev/statement_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1021,11 +1021,12 @@ namespace sqlite_orm {

std::stringstream ss;
ss << streaming_identifier(column.name);
if(!no_need_types_and_constraints<Ctx>::value) {
if(!context.skip_types_and_constraints) {
ss << " " << type_printer<field_type_t<column_type>>().print();
const bool columnIsNotNull = column.is_not_null();
auto constraintsTuple = streaming_column_constraints(
call_as_template_base<column_constraints>(polyfill::identity{})(column),
column.is_not_null(),
columnIsNotNull,
context);
if(std::tuple_size<decltype(constraintsTuple)>::value > 0) {
ss << " " << constraintsTuple;
Expand Down Expand Up @@ -1634,7 +1635,8 @@ namespace sqlite_orm {
std::string operator()(const statement_type& statement, const Ctx& context) const {
std::stringstream ss;
ss << "USING FTS5(";
auto subContext = make_serializer_context_with_no_types_and_constraints(context);
auto subContext = context;
subContext.skip_types_and_constraints = true;
ss << streaming_expressions_tuple(statement.columns, subContext) << ")";
return ss.str();
}
Expand Down
4 changes: 1 addition & 3 deletions dev/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,9 @@ namespace sqlite_orm {
storage_t(std::string filename, db_objects_type dbObjects) :
storage_base{std::move(filename), foreign_keys_count(dbObjects)}, db_objects{std::move(dbObjects)} {}

// private:
public:
private:
db_objects_type db_objects;

private:
/**
* Obtain a storage_t's const db_objects_tuple.
*
Expand Down
33 changes: 7 additions & 26 deletions include/sqlite_orm/sqlite_orm.h
Original file line number Diff line number Diff line change
Expand Up @@ -2741,6 +2741,7 @@ namespace sqlite_orm {
bool replace_bindable_with_question = false;
bool skip_table_name = true;
bool use_parentheses = true;
bool skip_types_and_constraints = false;
};

template<class DBOs>
Expand All @@ -2752,19 +2753,6 @@ namespace sqlite_orm {
serializer_context(const db_objects_type& dbObjects) : db_objects{dbObjects} {}
};

template<class 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) {}
};

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

template<class S>
struct serializer_context_builder {
using storage_type = S;
Expand All @@ -2778,13 +2766,6 @@ namespace sqlite_orm {

const storage_type& storage;
};

template<class T>
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 {
};
}

}
Expand Down Expand Up @@ -16605,11 +16586,12 @@ namespace sqlite_orm {

std::stringstream ss;
ss << streaming_identifier(column.name);
if(!no_need_types_and_constraints<Ctx>::value) {
if(!context.skip_types_and_constraints) {
ss << " " << type_printer<field_type_t<column_type>>().print();
const bool columnIsNotNull = column.is_not_null();
auto constraintsTuple = streaming_column_constraints(
call_as_template_base<column_constraints>(polyfill::identity{})(column),
column.is_not_null(),
columnIsNotNull,
context);
if(std::tuple_size<decltype(constraintsTuple)>::value > 0) {
ss << " " << constraintsTuple;
Expand Down Expand Up @@ -17218,7 +17200,8 @@ namespace sqlite_orm {
std::string operator()(const statement_type& statement, const Ctx& context) const {
std::stringstream ss;
ss << "USING FTS5(";
auto subContext = make_serializer_context_with_no_types_and_constraints(context);
auto subContext = context;
subContext.skip_types_and_constraints = true;
ss << streaming_expressions_tuple(statement.columns, subContext) << ")";
return ss.str();
}
Expand Down Expand Up @@ -17740,11 +17723,9 @@ namespace sqlite_orm {
storage_t(std::string filename, db_objects_type dbObjects) :
storage_base{std::move(filename), foreign_keys_count(dbObjects)}, db_objects{std::move(dbObjects)} {}

// private:
public:
private:
db_objects_type db_objects;

private:
/**
* Obtain a storage_t's const db_objects_tuple.
*
Expand Down
7 changes: 4 additions & 3 deletions tests/statement_serializer_tests/schema/column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ TEST_CASE("statement_serializer column") {
std::string value;
std::string expected;
SECTION("with types and constraints") {
context.skip_types_and_constraints = false;
SECTION("id INTEGER NOT NULL") {
auto column = make_column("id", &User::id);
value = serialize(column, context);
Expand All @@ -31,15 +32,15 @@ TEST_CASE("statement_serializer column") {
}
}
SECTION("without types and constraints") {
auto subContext = internal::make_serializer_context_with_no_types_and_constraints(context);
context.skip_types_and_constraints = true;
SECTION("id INTEGER NOT NULL") {
auto column = make_column("id", &User::id);
value = serialize(column, subContext);
value = serialize(column, context);
expected = "\"id\"";
}
SECTION("name TEXT NOT NULL") {
auto column = make_column("name", &User::name);
value = serialize(column, subContext);
value = serialize(column, context);
expected = "\"name\"";
}
}
Expand Down
26 changes: 0 additions & 26 deletions tests/tests4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@
#include <optional> // std::optional
#endif // SQLITE_ORM_OPTIONAL_SUPPORTED

#include <iostream>

using namespace sqlite_orm;

using std::cout;
using std::endl;

TEST_CASE("Unique ptr in update") {

struct User {
Expand All @@ -24,27 +19,6 @@ TEST_CASE("Unique ptr in update") {
auto storage = make_storage({}, nameTable);
storage.sync_schema();

using NameTable = decltype(nameTable);
using Storage = decltype(storage);
using NameColumnType = decltype(nameColumn);
using FieldType = NameColumnType::field_type;

cout << "[!] nameColumn.is_not_null() = " << nameColumn.is_not_null() << endl;
cout << "[!] type_is_nullable = " << type_is_nullable<FieldType>::value << endl;

STATIC_REQUIRE(std::is_same<FieldType, std::unique_ptr<std::string>>::value);
STATIC_REQUIRE(type_is_nullable<FieldType>::value);

{
using db_objects_type = typename Storage::db_objects_type;

internal::statement_serializer<NameTable, void> serializer;
using context_t = internal::serializer_context<db_objects_type>;
context_t context{storage.db_objects};
const auto sql = serializer.serialize(nameTable, context, nameTable.name);
cout << "[!] nameTable = " << sql << endl;
}

storage.insert(User{});
storage.insert(User{});
storage.insert(User{});
Expand Down

0 comments on commit b85f3f2

Please sign in to comment.