/
UCS
/
sqlite_orm
Обзор
Документация
Войти
/
UCS
/
sqlite_orm
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
1.6
dev/view.h
74 строки
3 KB
fnc12
removved string_from_expression for get_all_t
13 май 2020, 01:16
13 май 2020, 01:16
77752cd
Код
Авторство
О чём код?
#pragma once #include <memory> // std::shared_ptr #include <string> // std::string #include <utility> // std::forward, std::move #include <sqlite3.h> #include <system_error> // std::system_error #include <tuple> // std::tuple, std::make_tuple #include "row_extractor.h" #include "statement_finalizer.h" #include "error_code.h" #include "iterator.h" #include "ast_iterator.h" #include "prepared_statement.h" #include "connection_holder.h" namespace sqlite_orm { namespace internal { template<class T, class S, class... Args> struct view_t { using mapped_type = T; using storage_type = S; using self = view_t<T, S, Args...>; storage_type &storage; connection_ref connection; get_all_t<T, std::vector<T>, Args...> args; view_t(storage_type &stor, decltype(connection) conn, Args &&... args_) : storage(stor), connection(std::move(conn)), args{std::make_tuple(std::forward<Args>(args_)...)} {} size_t size() { return this->storage.template count<T>(); } bool empty() { return !this->size(); } iterator_t<self> end() { return {nullptr, *this}; } iterator_t<self> begin() { sqlite3_stmt *stmt = nullptr; auto db = this->connection.get(); using context_t = serializator_context<typename storage_type::impl_type>; context_t context{this->storage.impl}; context.skip_table_name = false; context.replace_bindable_with_question = true; auto query = serialize(this->args, context); auto ret = sqlite3_prepare_v2(db, query.c_str(), -1, &stmt, nullptr); if(ret == SQLITE_OK) { auto index = 1; iterate_ast(this->args.conditions, [&index, stmt, db](auto &node) { using node_type = typename std::decay<decltype(node)>::type; conditional_binder<node_type, is_bindable<node_type>> binder{stmt, index}; if(SQLITE_OK != binder(node)) { throw std::system_error(std::error_code(sqlite3_errcode(db), get_sqlite_error_category()), sqlite3_errmsg(db)); } }); return {stmt, *this}; } else { throw std::system_error(std::error_code(sqlite3_errcode(db), get_sqlite_error_category()), sqlite3_errmsg(db)); } } }; } }