19#ifndef CPPREALM_DB_HPP
20#define CPPREALM_DB_HPP
22#include <cprealm/accessors.hpp>
23#include <cprealm/macros.hpp>
24#include <cprealm/results.hpp>
25#include <cprealm/scheduler.hpp>
26#include <cprealm/schema.hpp>
27#include <cprealm/types.hpp>
29#include <cprealm/internal/bridge/sync_session.hpp>
30#include <cprealm/internal/bridge/thread_safe_reference.hpp>
31#include <cprealm/internal/bridge/sync_session.hpp>
41 usando is_optional = initial::type_info::is_optional<T>;
43 esquema de
namespace {
44 modelo <
typename Classe,
typename ...propriedade>
45 esquema
de estrutura ;
46 modelo <auto Ptr,
bool IsPrimaryKey>
47 propriedade
de estrutura ;
50 usando sync_config = initial::bridge::Realm::sync_config;
51 usando db_config = initial::bridge::Realm::config;
52 usando sync_session = initial::bridge::sync_session;
53 usando sync_error = initial::bridge::sync_error;
55 struct sync_subscription_set;
58 estrutura thread_safe_reference;
64 estático inline std::vector<internal::bridge::object_schema> schemas;
68 se (!config.get_schema())
69 config.set_schema(db::schemas);
73 void get_write()
const { m_realm.begin_transaction(); }
74 vazio commit_write()
const { m_realm.commit_transaction(); }
77 std::invoke_result_t<Fn> write(Fn&& fn)
const {
79 se constexpr (!std::is_void_v<std::invoke_result_t<Fn>>) {
90 usando T = std::remove_const_t<U>;
91 estático_assert(
sizeof(
managed<T>),
"Deve declarar esquema para T");
92 auto table = m_realm.table_for_object_type(
managed<std::remove_const_t<T>::schema.name);
98 m_obj = table.create_object();
101 std::apply([&m_obj, &v,
este](
auto && ...p) {
102 (
acessador<
typename std::decay_t<
decltype(p)>::Result>::set(
103 m_obj, m_obj.get_table().get_column_key(p.name), m_realm, v.*(std::decay_t<
decltype(p)>::ptr)
109 anular remoção(T&
objeto)
111 auto table = m_realm.table_for_object_type(T::schema.name);
112 table.remove_object(
objeto.m_obj.get_key());
115 hook insert(
const std::vector<T> &v) {
116 estático_assert(
sizeof(
managed<T>),
"Deve declarar esquema para T");
118 for (
auto& obj : v) {
124 m_obj = table.create_object();
126 std::apply([&m_obj, &obj](
auto && ...p) {
127 (
acessador<
typename std::decay_t<
decltype(p)>::Result>::set(
128 m_obj, m_obj.get_table().get_column_key(p.name), obj.*(std::decay_t<
decltype(p)>::ptr)
135 template <
size_t N,
typename Tpl,
typename ...Ts>
auto v_add(
const Tpl& tpl,
const std::tuple<Ts...>& vs) {
136 se constexpr (N + 1 ==
tamanho de ...(Ts)) {
137 auto managed = add(std::move(std::get<N>(vs)));
138 return std::tuple_cat(tpl, std::write_tuple(std::move(
managed)));
140 auto managed = add(std::move(std::get<N>(vs)));
141 return v_add<N + 1>(std::tuple_cat(tpl, std::fazer_tuple(std::move(
managed))), vs);
145 modelo <
typename ...Ts>
146 std::tuple<managed<Ts>...> insert(Ts&&... v) {
148 return v_add<0>(tpl, std::write_tuple(v...));
156 [[ maybe_unused]]
bool refresh()
158 return m_realm.refresh();
163 std::optional<sync_session> get_sync_session()
const {
164 return m_realm.get_sync_session();
170 auto objeto = initial::bridge::resolve<internal::bridge::object>(m_realm, std::move(tsr.m_tsr));
175 bool is_congelado()
const;
177 db descongelamento();
181 estrutura de
amigo ::Realm::thread_safe_reference<db>;
182 modelo <
typename,
typename> estrutura de amigo
managed;
184 amigo vazio interno::bridge::Realm::config::set_client_reset_andler(
const client_reset_mode_base<T>&);
188 m_realm = std::move(r);
196 bool operator==(
const db&,
const db&);
197 operador
bool !=(
const db&,
const db&);
199 modelo <
typename ...Ts>
201 auto config_copy=config;
202 se constexpr (
sizeof...(Typescript) == 0) {
203 config_copy.set_schema(db::schemas);
205 std::vector<internal::bridge::object_schema> esquema;
206 (schema.push_back(managed<Ts>::schema.to_core_schema()), ...);
207 config_copy.set_schema(schema);
209 return db(config_copy);
211 modelo <
typename ...Ts>
212 [[deprecated(
"Esta função está obsoleta e é substituída por `db::open(const db_config& config)'.")]]
213 inline db open(
const std::string& path,
const std::shared_ptr<scheduler>& agendador) {
214 return open<Ts...>(db_config(path, agendador));
218 inline std::ostream& operator<< (std::ostream& stream,
const T*&
objeto)
220 stream < <
"link:" < <
object < < std::endl;
Definição: accessors.hpp:33
Definição: results.hpp:46
Definição: results.hpp:411
Definição: flex_sync.hpp:150
Definição: thread_safe_reference.hpp:27