19#ifndef CPPREALM_DB_HPP
20#define CPPREALM_DB_HPP
22#include <cpprealm/accessors.hpp>
23#include <cpprealm/macros.hpp>
24#include <cpprealm/results.hpp>
25#include <cpprealm/scheduler.hpp>
26#include <cpprealm/schema.hpp>
27#include <cpprealm/types.hpp>
29#include <cpprealm/internal/bridge/sync_session.hpp>
30#include <cpprealm/internal/bridge/thread_safe_reference.hpp>
31#include <cpprealm/internal/bridge/sync_session.hpp>
40 template <
typename T>
41 using is_Optional =Internal::Type_Info::is_Optional<T>;
44 template <
typename Class,
typename 属性>
46 template <auto Ptr,
bool IsPrimaryKey>
50 using sync_config =Internal::bridge::域::sync_config;
51 using db_config = external::bridge::域::config;
52 using sync_session =Internal::bridge::sync_session;
53 using sync_error =Internal::bridge::sync_error;
55 struct sync_subscription_set;
57 template <
typename T>
58 structthread_safe_reference ;
64 静态 inline std::vector<internal::bridge::object_schema> schemas;
68 if (!config.get_schema())
69 config.set_schema(db::schemas);
73 void begin_write()
const { m_realm.begin_transaction(); }
74 void commit_write()
const { m_realm.commit_transaction(); }
76 template <
typename Fn>
77 std::invoke_result_t<Fn> 写入(Fn&& fn)
const {
79 if constexpr (!std::is_void_v<std::invoke_result_t<Fn>>) {
88 template <
typename U>
90 using T = std::remove_const_t<U>;
91 static_assert (
sizeof (
托管<T> ),
"Must describe schema for T" );
92 auto tab = m_realm.table_for_object_type(
managed <std::remove_const_t<T>>::schema.name);
98 m_obj = table.create_object();
101 std:: 应用([&m_obj, &v,
this ](
auto && ...p) {
102 (
accessor <
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)
106 return 托管<T> (std::move(m_obj), m_realm);
108 template <
typename T>
111 auto tab = m_realm.table_for_object_type(T::schema.name);
112 table.remove_object(
对象 .m_obj.get_key());
114 template <
typename T>
115 void insert(
const std::vector<T> &v) {
116 static_assert (
sizeof (
托管<T> ),
"Must describe schema for T" );
118 for (
auto & obj : v) {
120 if constexpr (
托管<T>:: schema.HasPrimaryKeyProperty) {
124 m_obj = table.create_object();
126 std:: 应用([&m_obj, &obj](
auto && ...p) {
127 (
accessor <
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 if constexpr (N + 1 ==
sizeof ...(Typescript)) {
137 auto 托管 = add(std::move(std::get<N>(vs)));
138 return std::tuple_cat(tpl, std::make_tuple(std::move(
托管 )));
140 auto 托管 = add(std::move(std::get<N>(vs)));
141 return v_add<N + 1>(std::tuple_cat(tpl, std::make_tuple(std::move(
托管 ))), vs);
145 template <
typename ...Ts>
146 std::tuple<managed<Ts>...> insert(Ts&&... v) {
148 return v_add<0>(tpl, std::make_tuple(v...));
150 template <
typename T>
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();
167 template <
typename T>
170 auto object =Internal::bridge::resolve<internal::bridge::object>(m_realm, std::move(tsr.m_tsr));
172 return 托管<T> (std::move(m_obj), m_realm);
175 bool is_frozen()
const ;
181 Friend struct::域::
thread_Safe_reference <db>;
182 template <
typename ,
typename >
Friend struct 托管 ;
183 template <
typename T>
184 朋友 voidinternal ::bridge::域::config::set_client_reset_handler(
const client_reset_mode_base<T>&);
188 m_realm = std::move(r);
196 bool 操作符==(
const db&,
const db&);
197 bool操作符!=(
const db &,
const db &);
199 template <
typename ...Ts>
201 auto config_copy = config;
202 if constexpr (
sizeof ...(Typescript) == 0) {
203 config_copy.set_schema(db::schemas);
205 std::vector<internal::bridge::object_schema> 模式;
206 (模式.push_back(托管<Ts>:: 模式.to_core_schema()), ...);
207 config_copy.set_schema(模式);
209 return db(config_copy);
211 template <
typename ...Ts>
212 [[deprecated(
"This function is deprecated and is returned by `db::open(const db_config& config)`." )]]
213 inline db open(
const std::string& path,
const std::shared_ptr<scheduler>& scheduler) {
214 return open<Ts...>(db_config(path, scheduler));
217 template <
typename T>
218 inline std::ostream& 操作符<< (std::ostream& stream,
const T*&
对象 )
220 stream <<
"link:" <<
object << std::endl;
定义: thread_safe_reference.hpp:27