Skip to content

evertonantunes/compile_time_sql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

conan install . --build=missing
cmake CMakeLists.txt
cmake --build . --targe all
    database::create_table<database::tables::strings>();
    database::create_table<database::tables::users>();

    database::insert_into<users_t>(   users_t::first_name = database::insert_into<strings_t>(strings_t::text = "Blaise")
                                    , users_t::second_name = database::insert_into<strings_t>(strings_t::text = "Pascal")
                                    , users_t::age = 39l );

    
    using f_name = alias<strings_t, decltype("f_name"_s)>;
    using s_name = alias<strings_t, decltype("s_name"_s)>;

    using my_select_t = decltype(database::select(   users_t::id
                                                   , f_name::as(strings_t::text)
                                                   , s_name::as(strings_t::text)
                                                   , users_t::age)
        .from<users_t>()
        .left_join<f_name>(f_name::as(strings_t::id) == users_t::first_name)
        .left_join<s_name>(s_name::as(strings_t::id) == users_t::second_name));

    const auto text = my_select_t().where(users_t::age == 39l || users_t::age > 70l).to_string(); // return StaticArray<'' ... >

    std::cout << "text: " << text.view() << std::endl; // text: SELECT users.id, f_name.text, s_name.text, users.age FROM users LEFT JOIN strings as f_name ON f_name.id == users.first_name LEFT JOIN strings as s_name ON s_name.id == users.second_name WHERE users.age == ? OR users.age > ?;

    for (const auto [id, first_name, second_name, age] : my_select_t().where(users_t::age == 39l || users_t::age > 70l))
    {
	...
    }

About

DSL for compile time generate and validade SQL

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published