Skip to content

Request for interest: c++-20 modularization of sqlpp11 (I did some in my own project) and making sqlpp11 modularization-friendly. #617

@germandiagogomez

Description

@germandiagogomez

Dear Sqlpp11 project,

I am converting my own code into a modularized codebase, which made me convert several dependencies, among them, partial sqlpp11.

Please note that I am using sqlite3 so ignore the sqlite3 stuff, it is there just bc it made my port more convenient. That would belong to a sqlite3 module, obviously.

This is just a partial conversion and exposes a module with symbols in a per-need basis from a project I am developing. So far I have something like this (and it works):

Partial module file (so far)

module;

#include <sqlpp11/sqlpp11.h>
#include <sqlpp11/sqlite3/connection.h>
#include <sqlpp11/sqlite3/connection_config.h>
#include <sqlpp11/connection_pool.h>
#include <sqlpp11/sqlite3/connection_pool.h>

inline constexpr int SQLITE_OPEN_READONLY_MODULES = SQLITE_OPEN_READONLY;
inline constexpr int SQLITE_OPEN_READWRITE_MODULES = SQLITE_OPEN_READWRITE;
inline constexpr int SQLITE_OPEN_CREATE_MODULES = SQLITE_OPEN_CREATE;

#undef SQLITE_OPEN_READONLY
#undef SQLITE_OPEN_READWRITE
#undef SQLITE_OPEN_CREATE

inline constexpr int SQLITE_OPEN_READONLY = {SQLITE_OPEN_READONLY_MODULES};
inline constexpr int SQLITE_OPEN_READWRITE = {SQLITE_OPEN_READWRITE_MODULES};
inline constexpr int SQLITE_OPEN_CREATE = {SQLITE_OPEN_CREATE_MODULES};



export module sqlpp11;

export {

using ::SQLITE_OPEN_READONLY;
using ::SQLITE_OPEN_READWRITE;
using ::SQLITE_OPEN_CREATE;

}


export namespace sqlpp {

    using ::sqlpp::make_char_sequence;
    using ::sqlpp::make_traits;
    using ::sqlpp::char_;
    using ::sqlpp::time_point;
    using ::sqlpp::varchar;
    using ::sqlpp::integer;
    using ::sqlpp::bigint;
    using ::sqlpp::smallint;
    using ::sqlpp::smallint_unsigned;
    using ::sqlpp::blob;
    using ::sqlpp::bigint_unsigned;


    using ::sqlpp::interpret_tuple_element;
    using ::sqlpp::interpret_tuple_impl;
    using ::sqlpp::interpret_tuple;


    using ::sqlpp::all_of;
    using ::sqlpp::select;
    using ::sqlpp::insert;
    using ::sqlpp::insert_into;
    using ::sqlpp::update;
    using ::sqlpp::remove;
    using ::sqlpp::connection_pool;

    namespace chrono {
        using ::sqlpp::chrono::floor;
    }

    namespace detail {
        using ::sqlpp::detail::make_type_set;
        using ::sqlpp::detail::make_type_set_if;
        using ::sqlpp::detail::make_difference_set;
    }

    using ::sqlpp::table_t;
    using ::sqlpp::column_t;

    namespace tag {
        using ::sqlpp::tag::require_insert;
        using ::sqlpp::tag::can_be_null;
        using ::sqlpp::tag::must_not_insert;
        using ::sqlpp::tag::requires_parens;
        using ::sqlpp::tag::is_column;
    }

    namespace sqlite3 {
        using ::sqlpp::sqlite3::pooled_connection;
        using ::sqlpp::sqlite3::connection;
        using ::sqlpp::sqlite3::connection_pool;
        using ::sqlpp::sqlite3::connection_config;
    }
}

// Sure, this does not belong here, I packed it all at once for the sake of advancing in my own project.
export using ::sqlite3_exec;

About generated code (via ddl2cpp)

I am also converting my table files with ddl2cpp via a custom script that does something like this. Basically I let ddl2cpp convert the code, I get that input, I remove all lines starting with a hash, I replace by

export module my.tables;
import sqlpp11;

export namespace thetablesnamespace {
//...
}

Problems found while modularizing.

So far I found a single problem: in file interpret_tuple.h, the static function interpret_tuple_element cannot be exported, but if it is not, then the code won't compile. I patched sqlpp11 to just remove static since I could not find a workaround.

I would like to talk about contributing, in a more tidied-up and systematic way a modularized sqlpp11 version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions