diff --git a/db/test-schema-v1.2/generated-cpp-source/include/cppbessot/model/Agent.h b/db/test-schema-v1.2/generated-cpp-source/include/cppbessot/model/Agent.h new file mode 100644 index 0000000..2828703 --- /dev/null +++ b/db/test-schema-v1.2/generated-cpp-source/include/cppbessot/model/Agent.h @@ -0,0 +1,47 @@ +/* + * AUTO-GENERATED BY CppBeSsot. + * Direct edits are pointless: this file is regenerated. + * Update the OpenAPI schema and/or CppBeSsot templates, then regenerate generated-* outputs. + */ +#pragma once + +#include +#include + +#include +#include + +namespace models { + +#pragma db model version(1, 2) +#pragma db object table("Agent") +class Agent +{ +public: + #pragma db id + // odbAddedIn: 1.1 + std::string id{}; + // odbAddedIn: 1.1 + std::string role{}; + // odbAddedIn: 1.1 + bool persistent{}; + // odbAddedIn: 1.1 + std::string displayName{}; + // odbAddedIn: 1.2 + int32_t trustScore{}; + + NLOHMANN_DEFINE_TYPE_INTRUSIVE(Agent, id, role, persistent, displayName, trustScore) + + nlohmann::json toJson() const + { + return nlohmann::json(*this); + } + + static Agent fromJson(const nlohmann::json& j) + { + return j.get(); + } +}; + +} // namespace models + diff --git a/db/test-schema-v1.2/generated-cpp-source/include/cppbessot/model/GovernmentAddress.h b/db/test-schema-v1.2/generated-cpp-source/include/cppbessot/model/GovernmentAddress.h new file mode 100644 index 0000000..c7050ab --- /dev/null +++ b/db/test-schema-v1.2/generated-cpp-source/include/cppbessot/model/GovernmentAddress.h @@ -0,0 +1,43 @@ +/* + * AUTO-GENERATED BY CppBeSsot. + * Direct edits are pointless: this file is regenerated. + * Update the OpenAPI schema and/or CppBeSsot templates, then regenerate generated-* outputs. + */ +#pragma once + +#include +#include + +#include +#include + +namespace models { + +#pragma db model version(1, 2) +#pragma db object table("GovernmentAddress") +class GovernmentAddress +{ +public: + #pragma db id + // odbAddedIn: 1.1 + std::string id{}; + // odbAddedIn: 1.1 + std::string addressLabel{}; + // odbAddedIn: 1.1 + std::string regionLookupKey{}; + + NLOHMANN_DEFINE_TYPE_INTRUSIVE(GovernmentAddress, id, addressLabel, regionLookupKey) + + nlohmann::json toJson() const + { + return nlohmann::json(*this); + } + + static GovernmentAddress fromJson(const nlohmann::json& j) + { + return j.get(); + } +}; + +} // namespace models + diff --git a/db/test-schema-v1.2/generated-cpp-source/include/cppbessot/model/TripAttemptResult.h b/db/test-schema-v1.2/generated-cpp-source/include/cppbessot/model/TripAttemptResult.h new file mode 100644 index 0000000..7b482c4 --- /dev/null +++ b/db/test-schema-v1.2/generated-cpp-source/include/cppbessot/model/TripAttemptResult.h @@ -0,0 +1,61 @@ +/* + * AUTO-GENERATED BY CppBeSsot. + * Direct edits are pointless: this file is regenerated. + * Update the OpenAPI schema and/or CppBeSsot templates, then regenerate generated-* outputs. + */ +#pragma once + +#include +#include + +#include +#include + +namespace models { + +#pragma db model version(1, 2) +#pragma db object table("TripAttemptResult") +class TripAttemptResult +{ +public: + #pragma db id + // odbAddedIn: 1.1 + std::string id{}; + // odbAddedIn: 1.1 + std::string result{}; + // odbAddedIn: 1.1 + std::string retryReason{}; + // odbAddedIn: 1.1 + std::string governmentSuspensionReason{}; + // odbAddedIn: 1.1 + std::string governmentTerminationReason{}; + // odbAddedIn: 1.1 + std::string complianceSuspensionReason{}; + // odbAddedIn: 1.1 + std::string complianceTerminationReason{}; + // odbAddedIn: 1.1 + std::string policySuspensionReason{}; + // odbAddedIn: 1.1 + std::string policyTerminationReason{}; + // odbAddedIn: 1.1 + std::string cancelationReason{}; + // odbAddedIn: 1.1 + std::string failureReason{}; + // odbAddedIn: 1.1 + std::string details{}; + + NLOHMANN_DEFINE_TYPE_INTRUSIVE(TripAttemptResult, id, result, retryReason, governmentSuspensionReason, governmentTerminationReason, complianceSuspensionReason, complianceTerminationReason, policySuspensionReason, policyTerminationReason, cancelationReason, failureReason, details) + + nlohmann::json toJson() const + { + return nlohmann::json(*this); + } + + static TripAttemptResult fromJson(const nlohmann::json& j) + { + return j.get(); + } +}; + +} // namespace models + diff --git a/db/test-schema-v1.2/generated-cpp-source/src/model/Agent.cpp b/db/test-schema-v1.2/generated-cpp-source/src/model/Agent.cpp new file mode 100644 index 0000000..c34ad30 --- /dev/null +++ b/db/test-schema-v1.2/generated-cpp-source/src/model/Agent.cpp @@ -0,0 +1,11 @@ +/* + * AUTO-GENERATED BY CppBeSsot. + * Direct edits are pointless: this file is regenerated. + * Update the OpenAPI schema and/or CppBeSsot templates, then regenerate generated-* outputs. + */ +#include "cppbessot/model/Agent.h" + +namespace models { +// Nlohmann-based models are header-only for now. +} // namespace models + diff --git a/db/test-schema-v1.2/generated-cpp-source/src/model/GovernmentAddress.cpp b/db/test-schema-v1.2/generated-cpp-source/src/model/GovernmentAddress.cpp new file mode 100644 index 0000000..26085be --- /dev/null +++ b/db/test-schema-v1.2/generated-cpp-source/src/model/GovernmentAddress.cpp @@ -0,0 +1,11 @@ +/* + * AUTO-GENERATED BY CppBeSsot. + * Direct edits are pointless: this file is regenerated. + * Update the OpenAPI schema and/or CppBeSsot templates, then regenerate generated-* outputs. + */ +#include "cppbessot/model/GovernmentAddress.h" + +namespace models { +// Nlohmann-based models are header-only for now. +} // namespace models + diff --git a/db/test-schema-v1.2/generated-cpp-source/src/model/TripAttemptResult.cpp b/db/test-schema-v1.2/generated-cpp-source/src/model/TripAttemptResult.cpp new file mode 100644 index 0000000..f83b7af --- /dev/null +++ b/db/test-schema-v1.2/generated-cpp-source/src/model/TripAttemptResult.cpp @@ -0,0 +1,11 @@ +/* + * AUTO-GENERATED BY CppBeSsot. + * Direct edits are pointless: this file is regenerated. + * Update the OpenAPI schema and/or CppBeSsot templates, then regenerate generated-* outputs. + */ +#include "cppbessot/model/TripAttemptResult.h" + +namespace models { +// Nlohmann-based models are header-only for now. +} // namespace models + diff --git a/db/test-schema-v1.2/generated-odb-source/postgre/Agent-odb.cxx b/db/test-schema-v1.2/generated-odb-source/postgre/Agent-odb.cxx new file mode 100644 index 0000000..904486b --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/postgre/Agent-odb.cxx @@ -0,0 +1,864 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#include + +#include "Agent-odb.hxx" + +#include +#include // std::memcpy + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace odb +{ + // Agent + // + + const char access::object_traits_impl< ::models::Agent, id_pgsql >:: + persist_statement_name[] = "persist_models_Agent"; + + const char access::object_traits_impl< ::models::Agent, id_pgsql >:: + find_statement_name[] = "find_models_Agent"; + + const char access::object_traits_impl< ::models::Agent, id_pgsql >:: + update_statement_name[] = "update_models_Agent"; + + const char access::object_traits_impl< ::models::Agent, id_pgsql >:: + erase_statement_name[] = "erase_models_Agent"; + + const char access::object_traits_impl< ::models::Agent, id_pgsql >:: + query_statement_name[] = "query_models_Agent"; + + const char access::object_traits_impl< ::models::Agent, id_pgsql >:: + erase_query_statement_name[] = "erase_query_models_Agent"; + + const unsigned int access::object_traits_impl< ::models::Agent, id_pgsql >:: + persist_statement_types[] = + { + pgsql::text_oid, + pgsql::text_oid, + pgsql::bool_oid, + pgsql::text_oid, + pgsql::int4_oid + }; + + const unsigned int access::object_traits_impl< ::models::Agent, id_pgsql >:: + find_statement_types[] = + { + pgsql::text_oid + }; + + const unsigned int access::object_traits_impl< ::models::Agent, id_pgsql >:: + update_statement_types[] = + { + pgsql::text_oid, + pgsql::bool_oid, + pgsql::text_oid, + pgsql::int4_oid, + pgsql::text_oid + }; + + struct access::object_traits_impl< ::models::Agent, id_pgsql >::extra_statement_cache_type + { + extra_statement_cache_type ( + pgsql::connection&, + image_type&, + id_image_type&, + pgsql::binding&, + pgsql::binding&, + pgsql::native_binding&, + const unsigned int*) + { + } + }; + + access::object_traits_impl< ::models::Agent, id_pgsql >::id_type + access::object_traits_impl< ::models::Agent, id_pgsql >:: + id (const image_type& i) + { + pgsql::database* db (0); + ODB_POTENTIALLY_UNUSED (db); + + id_type id; + { + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + id, + i.id_value, + i.id_size, + i.id_null); + } + + return id; + } + + bool access::object_traits_impl< ::models::Agent, id_pgsql >:: + grow (image_type& i, + bool* t) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (t); + + bool grew (false); + + // id + // + if (t[0UL]) + { + i.id_value.capacity (i.id_size); + grew = true; + } + + // role + // + if (t[1UL]) + { + i.role_value.capacity (i.role_size); + grew = true; + } + + // persistent + // + t[2UL] = 0; + + // displayName + // + if (t[3UL]) + { + i.displayName_value.capacity (i.displayName_size); + grew = true; + } + + // trustScore + // + t[4UL] = 0; + + return grew; + } + + void access::object_traits_impl< ::models::Agent, id_pgsql >:: + bind (pgsql::bind* b, + image_type& i, + pgsql::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (sk); + + using namespace pgsql; + + std::size_t n (0); + + // id + // + if (sk != statement_update) + { + b[n].type = pgsql::bind::text; + b[n].buffer = i.id_value.data (); + b[n].capacity = i.id_value.capacity (); + b[n].size = &i.id_size; + b[n].is_null = &i.id_null; + n++; + } + + // role + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.role_value.data (); + b[n].capacity = i.role_value.capacity (); + b[n].size = &i.role_size; + b[n].is_null = &i.role_null; + n++; + + // persistent + // + b[n].type = pgsql::bind::boolean_; + b[n].buffer = &i.persistent_value; + b[n].is_null = &i.persistent_null; + n++; + + // displayName + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.displayName_value.data (); + b[n].capacity = i.displayName_value.capacity (); + b[n].size = &i.displayName_size; + b[n].is_null = &i.displayName_null; + n++; + + // trustScore + // + b[n].type = pgsql::bind::integer; + b[n].buffer = &i.trustScore_value; + b[n].is_null = &i.trustScore_null; + n++; + } + + void access::object_traits_impl< ::models::Agent, id_pgsql >:: + bind (pgsql::bind* b, id_image_type& i) + { + std::size_t n (0); + b[n].type = pgsql::bind::text; + b[n].buffer = i.id_value.data (); + b[n].capacity = i.id_value.capacity (); + b[n].size = &i.id_size; + b[n].is_null = &i.id_null; + } + + bool access::object_traits_impl< ::models::Agent, id_pgsql >:: + init (image_type& i, + const object_type& o, + pgsql::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (sk); + + using namespace pgsql; + + bool grew (false); + + // id + // + if (sk == statement_insert) + { + ::std::string const& v = + o.id; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.id_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.id_value, + size, + is_null, + v); + i.id_null = is_null; + i.id_size = size; + grew = grew || (cap != i.id_value.capacity ()); + } + + // role + // + { + ::std::string const& v = + o.role; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.role_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.role_value, + size, + is_null, + v); + i.role_null = is_null; + i.role_size = size; + grew = grew || (cap != i.role_value.capacity ()); + } + + // persistent + // + { + bool const& v = + o.persistent; + + bool is_null (false); + pgsql::value_traits< + bool, + pgsql::id_boolean >::set_image ( + i.persistent_value, is_null, v); + i.persistent_null = is_null; + } + + // displayName + // + { + ::std::string const& v = + o.displayName; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.displayName_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.displayName_value, + size, + is_null, + v); + i.displayName_null = is_null; + i.displayName_size = size; + grew = grew || (cap != i.displayName_value.capacity ()); + } + + // trustScore + // + { + ::int32_t const& v = + o.trustScore; + + bool is_null (false); + pgsql::value_traits< + ::int32_t, + pgsql::id_integer >::set_image ( + i.trustScore_value, is_null, v); + i.trustScore_null = is_null; + } + + return grew; + } + + void access::object_traits_impl< ::models::Agent, id_pgsql >:: + init (object_type& o, + const image_type& i, + database* db) + { + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (db); + + // id + // + { + ::std::string& v = + o.id; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.id_value, + i.id_size, + i.id_null); + } + + // role + // + { + ::std::string& v = + o.role; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.role_value, + i.role_size, + i.role_null); + } + + // persistent + // + { + bool& v = + o.persistent; + + pgsql::value_traits< + bool, + pgsql::id_boolean >::set_value ( + v, + i.persistent_value, + i.persistent_null); + } + + // displayName + // + { + ::std::string& v = + o.displayName; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.displayName_value, + i.displayName_size, + i.displayName_null); + } + + // trustScore + // + { + ::int32_t& v = + o.trustScore; + + pgsql::value_traits< + ::int32_t, + pgsql::id_integer >::set_value ( + v, + i.trustScore_value, + i.trustScore_null); + } + } + + void access::object_traits_impl< ::models::Agent, id_pgsql >:: + init (id_image_type& i, const id_type& id) + { + bool grew (false); + { + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.id_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.id_value, + size, + is_null, + id); + i.id_null = is_null; + i.id_size = size; + grew = grew || (cap != i.id_value.capacity ()); + } + + if (grew) + i.version++; + } + + const char access::object_traits_impl< ::models::Agent, id_pgsql >::persist_statement[] = + "INSERT INTO \"Agent\" " + "(\"id\", " + "\"role\", " + "\"persistent\", " + "\"displayName\", " + "\"trustScore\") " + "VALUES " + "($1, $2, $3, $4, $5)"; + + const char access::object_traits_impl< ::models::Agent, id_pgsql >::find_statement[] = + "SELECT " + "\"Agent\".\"id\", " + "\"Agent\".\"role\", " + "\"Agent\".\"persistent\", " + "\"Agent\".\"displayName\", " + "\"Agent\".\"trustScore\" " + "FROM \"Agent\" " + "WHERE \"Agent\".\"id\"=$1"; + + const char access::object_traits_impl< ::models::Agent, id_pgsql >::update_statement[] = + "UPDATE \"Agent\" " + "SET " + "\"role\"=$1, " + "\"persistent\"=$2, " + "\"displayName\"=$3, " + "\"trustScore\"=$4 " + "WHERE \"id\"=$5"; + + const char access::object_traits_impl< ::models::Agent, id_pgsql >::erase_statement[] = + "DELETE FROM \"Agent\" " + "WHERE \"id\"=$1"; + + const char access::object_traits_impl< ::models::Agent, id_pgsql >::query_statement[] = + "SELECT " + "\"Agent\".\"id\", " + "\"Agent\".\"role\", " + "\"Agent\".\"persistent\", " + "\"Agent\".\"displayName\", " + "\"Agent\".\"trustScore\" " + "FROM \"Agent\""; + + const char access::object_traits_impl< ::models::Agent, id_pgsql >::erase_query_statement[] = + "DELETE FROM \"Agent\""; + + const char access::object_traits_impl< ::models::Agent, id_pgsql >::table_name[] = + "\"Agent\""; + + void access::object_traits_impl< ::models::Agent, id_pgsql >:: + persist (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + callback (db, + obj, + callback_event::pre_persist); + + image_type& im (sts.image ()); + binding& imb (sts.insert_image_binding ()); + + if (init (im, obj, statement_insert)) + im.version++; + + if (im.version != sts.insert_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_insert); + sts.insert_image_version (im.version); + imb.version++; + } + + insert_statement& st (sts.persist_statement ()); + if (!st.execute ()) + throw object_already_persistent (); + + callback (db, + obj, + callback_event::post_persist); + } + + void access::object_traits_impl< ::models::Agent, id_pgsql >:: + update (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace pgsql; + using pgsql::update_statement; + + callback (db, obj, callback_event::pre_update); + + pgsql::transaction& tr (pgsql::transaction::current ()); + pgsql::connection& conn (tr.connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + const id_type& id ( + obj.id); + id_image_type& idi (sts.id_image ()); + init (idi, id); + + image_type& im (sts.image ()); + if (init (im, obj, statement_update)) + im.version++; + + bool u (false); + binding& imb (sts.update_image_binding ()); + if (im.version != sts.update_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_update); + sts.update_image_version (im.version); + imb.version++; + u = true; + } + + binding& idb (sts.id_image_binding ()); + if (idi.version != sts.update_id_image_version () || + idb.version == 0) + { + if (idi.version != sts.id_image_version () || + idb.version == 0) + { + bind (idb.bind, idi); + sts.id_image_version (idi.version); + idb.version++; + } + + sts.update_id_image_version (idi.version); + + if (!u) + imb.version++; + } + + update_statement& st (sts.update_statement ()); + if (st.execute () == 0) + throw object_not_persistent (); + + callback (db, obj, callback_event::post_update); + pointer_cache_traits::update (db, obj); + } + + void access::object_traits_impl< ::models::Agent, id_pgsql >:: + erase (database& db, const id_type& id) + { + using namespace pgsql; + + ODB_POTENTIALLY_UNUSED (db); + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + id_image_type& i (sts.id_image ()); + init (i, id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + if (sts.erase_statement ().execute () != 1) + throw object_not_persistent (); + + pointer_cache_traits::erase (db, id); + } + + access::object_traits_impl< ::models::Agent, id_pgsql >::pointer_type + access::object_traits_impl< ::models::Agent, id_pgsql >:: + find (database& db, const id_type& id) + { + using namespace pgsql; + + { + pointer_type p (pointer_cache_traits::find (db, id)); + + if (!pointer_traits::null_ptr (p)) + return p; + } + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (l.locked ()) + { + if (!find_ (sts, &id)) + return pointer_type (); + } + + pointer_type p ( + access::object_factory::create ()); + pointer_traits::guard pg (p); + + pointer_cache_traits::insert_guard ig ( + pointer_cache_traits::insert (db, id, p)); + + object_type& obj (pointer_traits::get_ref (p)); + + if (l.locked ()) + { + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + pointer_cache_traits::load (ig.position ()); + } + else + sts.delay_load (id, obj, ig.position ()); + + ig.release (); + pg.release (); + return p; + } + + bool access::object_traits_impl< ::models::Agent, id_pgsql >:: + find (database& db, const id_type& id, object_type& obj) + { + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + reference_cache_traits::position_type pos ( + reference_cache_traits::insert (db, id, obj)); + reference_cache_traits::insert_guard ig (pos); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + reference_cache_traits::load (pos); + ig.release (); + return true; + } + + bool access::object_traits_impl< ::models::Agent, id_pgsql >:: + reload (database& db, object_type& obj) + { + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + const id_type& id ( + obj.id); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, true); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + return true; + } + + bool access::object_traits_impl< ::models::Agent, id_pgsql >:: + find_ (statements_type& sts, + const id_type* id) + { + using namespace pgsql; + + id_image_type& i (sts.id_image ()); + init (i, *id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + select_statement& st (sts.find_statement ()); + + st.execute (); + auto_result ar (st); + select_statement::result r (st.fetch ()); + + if (r == select_statement::truncated) + { + if (grow (im, sts.select_image_truncated ())) + im.version++; + + if (im.version != sts.select_image_version ()) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + st.refetch (); + } + } + + return r != select_statement::no_data; + } + + result< access::object_traits_impl< ::models::Agent, id_pgsql >::object_type > + access::object_traits_impl< ::models::Agent, id_pgsql >:: + query (database&, const query_base_type& q) + { + using namespace pgsql; + using odb::details::shared; + using odb::details::shared_ptr; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + + statements_type& sts ( + conn.statement_cache ().find_object ()); + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + std::string text (query_statement); + if (!q.empty ()) + { + text += " "; + text += q.clause (); + } + + q.init_parameters (); + shared_ptr st ( + new (shared) select_statement ( + sts.connection (), + query_statement_name, + text, + false, + true, + q.parameter_types (), + q.parameter_count (), + q.parameters_binding (), + imb)); + + st->execute (); + st->deallocate (); + + shared_ptr< odb::object_result_impl > r ( + new (shared) pgsql::object_result_impl ( + q, st, sts, 0)); + + return result (r); + } + + unsigned long long access::object_traits_impl< ::models::Agent, id_pgsql >:: + erase_query (database&, const query_base_type& q) + { + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + + std::string text (erase_query_statement); + if (!q.empty ()) + { + text += ' '; + text += q.clause (); + } + + q.init_parameters (); + delete_statement st ( + conn, + erase_query_statement_name, + text, + q.parameter_types (), + q.parameter_count (), + q.parameters_binding ()); + + return st.execute (); + } +} + +#include diff --git a/db/test-schema-v1.2/generated-odb-source/postgre/Agent-odb.hxx b/db/test-schema-v1.2/generated-odb-source/postgre/Agent-odb.hxx new file mode 100644 index 0000000..fa096c2 --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/postgre/Agent-odb.hxx @@ -0,0 +1,353 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#ifndef AGENT_ODB_HXX +#define AGENT_ODB_HXX + +#include + +#if (ODB_VERSION != 20400UL) +#error ODB runtime version mismatch +#endif + +#include + +#include "Agent.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace odb +{ + // Agent + // + template <> + struct class_traits< ::models::Agent > + { + static const class_kind kind = class_object; + }; + + template <> + class access::object_traits< ::models::Agent > + { + public: + typedef ::models::Agent object_type; + typedef ::models::Agent* pointer_type; + typedef odb::pointer_traits pointer_traits; + + static const bool polymorphic = false; + + typedef ::std::string id_type; + + static const bool auto_id = false; + + static const bool abstract = false; + + static id_type + id (const object_type&); + + typedef + no_op_pointer_cache_traits + pointer_cache_traits; + + typedef + no_op_reference_cache_traits + reference_cache_traits; + + static void + callback (database&, object_type&, callback_event); + + static void + callback (database&, const object_type&, callback_event); + }; +} + +#include + +#include +#include +#include +#include +#include + +namespace odb +{ + // Agent + // + template + struct query_columns< ::models::Agent, id_pgsql, A > + { + // id + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + id_type_; + + static const id_type_ id; + + // role + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + role_type_; + + static const role_type_ role; + + // persistent + // + typedef + pgsql::query_column< + pgsql::value_traits< + bool, + pgsql::id_boolean >::query_type, + pgsql::id_boolean > + persistent_type_; + + static const persistent_type_ persistent; + + // displayName + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + displayName_type_; + + static const displayName_type_ displayName; + + // trustScore + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::int32_t, + pgsql::id_integer >::query_type, + pgsql::id_integer > + trustScore_type_; + + static const trustScore_type_ trustScore; + }; + + template + const typename query_columns< ::models::Agent, id_pgsql, A >::id_type_ + query_columns< ::models::Agent, id_pgsql, A >:: + id (A::table_name, "\"id\"", 0); + + template + const typename query_columns< ::models::Agent, id_pgsql, A >::role_type_ + query_columns< ::models::Agent, id_pgsql, A >:: + role (A::table_name, "\"role\"", 0); + + template + const typename query_columns< ::models::Agent, id_pgsql, A >::persistent_type_ + query_columns< ::models::Agent, id_pgsql, A >:: + persistent (A::table_name, "\"persistent\"", 0); + + template + const typename query_columns< ::models::Agent, id_pgsql, A >::displayName_type_ + query_columns< ::models::Agent, id_pgsql, A >:: + displayName (A::table_name, "\"displayName\"", 0); + + template + const typename query_columns< ::models::Agent, id_pgsql, A >::trustScore_type_ + query_columns< ::models::Agent, id_pgsql, A >:: + trustScore (A::table_name, "\"trustScore\"", 0); + + template + struct pointer_query_columns< ::models::Agent, id_pgsql, A >: + query_columns< ::models::Agent, id_pgsql, A > + { + }; + + template <> + class access::object_traits_impl< ::models::Agent, id_pgsql >: + public access::object_traits< ::models::Agent > + { + public: + struct id_image_type + { + details::buffer id_value; + std::size_t id_size; + bool id_null; + + std::size_t version; + }; + + struct image_type + { + // id + // + details::buffer id_value; + std::size_t id_size; + bool id_null; + + // role + // + details::buffer role_value; + std::size_t role_size; + bool role_null; + + // persistent + // + bool persistent_value; + bool persistent_null; + + // displayName + // + details::buffer displayName_value; + std::size_t displayName_size; + bool displayName_null; + + // trustScore + // + int trustScore_value; + bool trustScore_null; + + std::size_t version; + }; + + struct extra_statement_cache_type; + + using object_traits::id; + + static id_type + id (const image_type&); + + static bool + grow (image_type&, + bool*); + + static void + bind (pgsql::bind*, + image_type&, + pgsql::statement_kind); + + static void + bind (pgsql::bind*, id_image_type&); + + static bool + init (image_type&, + const object_type&, + pgsql::statement_kind); + + static void + init (object_type&, + const image_type&, + database*); + + static void + init (id_image_type&, const id_type&); + + typedef pgsql::object_statements statements_type; + + typedef pgsql::query_base query_base_type; + + static const std::size_t column_count = 5UL; + static const std::size_t id_column_count = 1UL; + static const std::size_t inverse_column_count = 0UL; + static const std::size_t readonly_column_count = 0UL; + static const std::size_t managed_optimistic_column_count = 0UL; + + static const std::size_t separate_load_column_count = 0UL; + static const std::size_t separate_update_column_count = 0UL; + + static const bool versioned = false; + + static const char persist_statement[]; + static const char find_statement[]; + static const char update_statement[]; + static const char erase_statement[]; + static const char query_statement[]; + static const char erase_query_statement[]; + + static const char table_name[]; + + static void + persist (database&, const object_type&); + + static pointer_type + find (database&, const id_type&); + + static bool + find (database&, const id_type&, object_type&); + + static bool + reload (database&, object_type&); + + static void + update (database&, const object_type&); + + static void + erase (database&, const id_type&); + + static void + erase (database&, const object_type&); + + static result + query (database&, const query_base_type&); + + static unsigned long long + erase_query (database&, const query_base_type&); + + static const char persist_statement_name[]; + static const char find_statement_name[]; + static const char update_statement_name[]; + static const char erase_statement_name[]; + static const char query_statement_name[]; + static const char erase_query_statement_name[]; + + static const unsigned int persist_statement_types[]; + static const unsigned int find_statement_types[]; + static const unsigned int update_statement_types[]; + + public: + static bool + find_ (statements_type&, + const id_type*); + + static void + load_ (statements_type&, + object_type&, + bool reload); + }; + + template <> + class access::object_traits_impl< ::models::Agent, id_common >: + public access::object_traits_impl< ::models::Agent, id_pgsql > + { + }; + + // Agent + // +} + +#include "Agent-odb.ixx" + +#include + +#endif // AGENT_ODB_HXX diff --git a/db/test-schema-v1.2/generated-odb-source/postgre/Agent-odb.ixx b/db/test-schema-v1.2/generated-odb-source/postgre/Agent-odb.ixx new file mode 100644 index 0000000..437858b --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/postgre/Agent-odb.ixx @@ -0,0 +1,61 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +namespace odb +{ + // Agent + // + + inline + access::object_traits< ::models::Agent >::id_type + access::object_traits< ::models::Agent >:: + id (const object_type& o) + { + return o.id; + } + + inline + void access::object_traits< ::models::Agent >:: + callback (database& db, object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } + + inline + void access::object_traits< ::models::Agent >:: + callback (database& db, const object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } +} + +namespace odb +{ + // Agent + // + + inline + void access::object_traits_impl< ::models::Agent, id_pgsql >:: + erase (database& db, const object_type& obj) + { + callback (db, obj, callback_event::pre_erase); + erase (db, id (obj)); + callback (db, obj, callback_event::post_erase); + } + + inline + void access::object_traits_impl< ::models::Agent, id_pgsql >:: + load_ (statements_type& sts, + object_type& obj, + bool) + { + ODB_POTENTIALLY_UNUSED (sts); + ODB_POTENTIALLY_UNUSED (obj); + } +} + diff --git a/db/test-schema-v1.2/generated-odb-source/postgre/Agent.xml b/db/test-schema-v1.2/generated-odb-source/postgre/Agent.xml new file mode 100644 index 0000000..4c765e8 --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/postgre/Agent.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/db/test-schema-v1.2/generated-odb-source/postgre/GovernmentAddress-odb.cxx b/db/test-schema-v1.2/generated-odb-source/postgre/GovernmentAddress-odb.cxx new file mode 100644 index 0000000..b04f6f8 --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/postgre/GovernmentAddress-odb.cxx @@ -0,0 +1,774 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#include + +#include "GovernmentAddress-odb.hxx" + +#include +#include // std::memcpy + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace odb +{ + // GovernmentAddress + // + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + persist_statement_name[] = "persist_models_GovernmentAddress"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + find_statement_name[] = "find_models_GovernmentAddress"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + update_statement_name[] = "update_models_GovernmentAddress"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + erase_statement_name[] = "erase_models_GovernmentAddress"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + query_statement_name[] = "query_models_GovernmentAddress"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + erase_query_statement_name[] = "erase_query_models_GovernmentAddress"; + + const unsigned int access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + persist_statement_types[] = + { + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid + }; + + const unsigned int access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + find_statement_types[] = + { + pgsql::text_oid + }; + + const unsigned int access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + update_statement_types[] = + { + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid + }; + + struct access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::extra_statement_cache_type + { + extra_statement_cache_type ( + pgsql::connection&, + image_type&, + id_image_type&, + pgsql::binding&, + pgsql::binding&, + pgsql::native_binding&, + const unsigned int*) + { + } + }; + + access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::id_type + access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + id (const image_type& i) + { + pgsql::database* db (0); + ODB_POTENTIALLY_UNUSED (db); + + id_type id; + { + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + id, + i.id_value, + i.id_size, + i.id_null); + } + + return id; + } + + bool access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + grow (image_type& i, + bool* t) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (t); + + bool grew (false); + + // id + // + if (t[0UL]) + { + i.id_value.capacity (i.id_size); + grew = true; + } + + // addressLabel + // + if (t[1UL]) + { + i.addressLabel_value.capacity (i.addressLabel_size); + grew = true; + } + + // regionLookupKey + // + if (t[2UL]) + { + i.regionLookupKey_value.capacity (i.regionLookupKey_size); + grew = true; + } + + return grew; + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + bind (pgsql::bind* b, + image_type& i, + pgsql::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (sk); + + using namespace pgsql; + + std::size_t n (0); + + // id + // + if (sk != statement_update) + { + b[n].type = pgsql::bind::text; + b[n].buffer = i.id_value.data (); + b[n].capacity = i.id_value.capacity (); + b[n].size = &i.id_size; + b[n].is_null = &i.id_null; + n++; + } + + // addressLabel + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.addressLabel_value.data (); + b[n].capacity = i.addressLabel_value.capacity (); + b[n].size = &i.addressLabel_size; + b[n].is_null = &i.addressLabel_null; + n++; + + // regionLookupKey + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.regionLookupKey_value.data (); + b[n].capacity = i.regionLookupKey_value.capacity (); + b[n].size = &i.regionLookupKey_size; + b[n].is_null = &i.regionLookupKey_null; + n++; + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + bind (pgsql::bind* b, id_image_type& i) + { + std::size_t n (0); + b[n].type = pgsql::bind::text; + b[n].buffer = i.id_value.data (); + b[n].capacity = i.id_value.capacity (); + b[n].size = &i.id_size; + b[n].is_null = &i.id_null; + } + + bool access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + init (image_type& i, + const object_type& o, + pgsql::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (sk); + + using namespace pgsql; + + bool grew (false); + + // id + // + if (sk == statement_insert) + { + ::std::string const& v = + o.id; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.id_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.id_value, + size, + is_null, + v); + i.id_null = is_null; + i.id_size = size; + grew = grew || (cap != i.id_value.capacity ()); + } + + // addressLabel + // + { + ::std::string const& v = + o.addressLabel; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.addressLabel_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.addressLabel_value, + size, + is_null, + v); + i.addressLabel_null = is_null; + i.addressLabel_size = size; + grew = grew || (cap != i.addressLabel_value.capacity ()); + } + + // regionLookupKey + // + { + ::std::string const& v = + o.regionLookupKey; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.regionLookupKey_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.regionLookupKey_value, + size, + is_null, + v); + i.regionLookupKey_null = is_null; + i.regionLookupKey_size = size; + grew = grew || (cap != i.regionLookupKey_value.capacity ()); + } + + return grew; + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + init (object_type& o, + const image_type& i, + database* db) + { + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (db); + + // id + // + { + ::std::string& v = + o.id; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.id_value, + i.id_size, + i.id_null); + } + + // addressLabel + // + { + ::std::string& v = + o.addressLabel; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.addressLabel_value, + i.addressLabel_size, + i.addressLabel_null); + } + + // regionLookupKey + // + { + ::std::string& v = + o.regionLookupKey; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.regionLookupKey_value, + i.regionLookupKey_size, + i.regionLookupKey_null); + } + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + init (id_image_type& i, const id_type& id) + { + bool grew (false); + { + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.id_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.id_value, + size, + is_null, + id); + i.id_null = is_null; + i.id_size = size; + grew = grew || (cap != i.id_value.capacity ()); + } + + if (grew) + i.version++; + } + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::persist_statement[] = + "INSERT INTO \"GovernmentAddress\" " + "(\"id\", " + "\"addressLabel\", " + "\"regionLookupKey\") " + "VALUES " + "($1, $2, $3)"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::find_statement[] = + "SELECT " + "\"GovernmentAddress\".\"id\", " + "\"GovernmentAddress\".\"addressLabel\", " + "\"GovernmentAddress\".\"regionLookupKey\" " + "FROM \"GovernmentAddress\" " + "WHERE \"GovernmentAddress\".\"id\"=$1"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::update_statement[] = + "UPDATE \"GovernmentAddress\" " + "SET " + "\"addressLabel\"=$1, " + "\"regionLookupKey\"=$2 " + "WHERE \"id\"=$3"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::erase_statement[] = + "DELETE FROM \"GovernmentAddress\" " + "WHERE \"id\"=$1"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::query_statement[] = + "SELECT " + "\"GovernmentAddress\".\"id\", " + "\"GovernmentAddress\".\"addressLabel\", " + "\"GovernmentAddress\".\"regionLookupKey\" " + "FROM \"GovernmentAddress\""; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::erase_query_statement[] = + "DELETE FROM \"GovernmentAddress\""; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::table_name[] = + "\"GovernmentAddress\""; + + void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + persist (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + callback (db, + obj, + callback_event::pre_persist); + + image_type& im (sts.image ()); + binding& imb (sts.insert_image_binding ()); + + if (init (im, obj, statement_insert)) + im.version++; + + if (im.version != sts.insert_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_insert); + sts.insert_image_version (im.version); + imb.version++; + } + + insert_statement& st (sts.persist_statement ()); + if (!st.execute ()) + throw object_already_persistent (); + + callback (db, + obj, + callback_event::post_persist); + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + update (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace pgsql; + using pgsql::update_statement; + + callback (db, obj, callback_event::pre_update); + + pgsql::transaction& tr (pgsql::transaction::current ()); + pgsql::connection& conn (tr.connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + const id_type& id ( + obj.id); + id_image_type& idi (sts.id_image ()); + init (idi, id); + + image_type& im (sts.image ()); + if (init (im, obj, statement_update)) + im.version++; + + bool u (false); + binding& imb (sts.update_image_binding ()); + if (im.version != sts.update_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_update); + sts.update_image_version (im.version); + imb.version++; + u = true; + } + + binding& idb (sts.id_image_binding ()); + if (idi.version != sts.update_id_image_version () || + idb.version == 0) + { + if (idi.version != sts.id_image_version () || + idb.version == 0) + { + bind (idb.bind, idi); + sts.id_image_version (idi.version); + idb.version++; + } + + sts.update_id_image_version (idi.version); + + if (!u) + imb.version++; + } + + update_statement& st (sts.update_statement ()); + if (st.execute () == 0) + throw object_not_persistent (); + + callback (db, obj, callback_event::post_update); + pointer_cache_traits::update (db, obj); + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + erase (database& db, const id_type& id) + { + using namespace pgsql; + + ODB_POTENTIALLY_UNUSED (db); + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + id_image_type& i (sts.id_image ()); + init (i, id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + if (sts.erase_statement ().execute () != 1) + throw object_not_persistent (); + + pointer_cache_traits::erase (db, id); + } + + access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::pointer_type + access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + find (database& db, const id_type& id) + { + using namespace pgsql; + + { + pointer_type p (pointer_cache_traits::find (db, id)); + + if (!pointer_traits::null_ptr (p)) + return p; + } + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (l.locked ()) + { + if (!find_ (sts, &id)) + return pointer_type (); + } + + pointer_type p ( + access::object_factory::create ()); + pointer_traits::guard pg (p); + + pointer_cache_traits::insert_guard ig ( + pointer_cache_traits::insert (db, id, p)); + + object_type& obj (pointer_traits::get_ref (p)); + + if (l.locked ()) + { + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + pointer_cache_traits::load (ig.position ()); + } + else + sts.delay_load (id, obj, ig.position ()); + + ig.release (); + pg.release (); + return p; + } + + bool access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + find (database& db, const id_type& id, object_type& obj) + { + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + reference_cache_traits::position_type pos ( + reference_cache_traits::insert (db, id, obj)); + reference_cache_traits::insert_guard ig (pos); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + reference_cache_traits::load (pos); + ig.release (); + return true; + } + + bool access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + reload (database& db, object_type& obj) + { + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + const id_type& id ( + obj.id); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, true); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + return true; + } + + bool access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + find_ (statements_type& sts, + const id_type* id) + { + using namespace pgsql; + + id_image_type& i (sts.id_image ()); + init (i, *id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + select_statement& st (sts.find_statement ()); + + st.execute (); + auto_result ar (st); + select_statement::result r (st.fetch ()); + + if (r == select_statement::truncated) + { + if (grow (im, sts.select_image_truncated ())) + im.version++; + + if (im.version != sts.select_image_version ()) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + st.refetch (); + } + } + + return r != select_statement::no_data; + } + + result< access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::object_type > + access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + query (database&, const query_base_type& q) + { + using namespace pgsql; + using odb::details::shared; + using odb::details::shared_ptr; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + + statements_type& sts ( + conn.statement_cache ().find_object ()); + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + std::string text (query_statement); + if (!q.empty ()) + { + text += " "; + text += q.clause (); + } + + q.init_parameters (); + shared_ptr st ( + new (shared) select_statement ( + sts.connection (), + query_statement_name, + text, + false, + true, + q.parameter_types (), + q.parameter_count (), + q.parameters_binding (), + imb)); + + st->execute (); + st->deallocate (); + + shared_ptr< odb::object_result_impl > r ( + new (shared) pgsql::object_result_impl ( + q, st, sts, 0)); + + return result (r); + } + + unsigned long long access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + erase_query (database&, const query_base_type& q) + { + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + + std::string text (erase_query_statement); + if (!q.empty ()) + { + text += ' '; + text += q.clause (); + } + + q.init_parameters (); + delete_statement st ( + conn, + erase_query_statement_name, + text, + q.parameter_types (), + q.parameter_count (), + q.parameters_binding ()); + + return st.execute (); + } +} + +#include diff --git a/db/test-schema-v1.2/generated-odb-source/postgre/GovernmentAddress-odb.hxx b/db/test-schema-v1.2/generated-odb-source/postgre/GovernmentAddress-odb.hxx new file mode 100644 index 0000000..da22f67 --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/postgre/GovernmentAddress-odb.hxx @@ -0,0 +1,309 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#ifndef GOVERNMENT_ADDRESS_ODB_HXX +#define GOVERNMENT_ADDRESS_ODB_HXX + +#include + +#if (ODB_VERSION != 20400UL) +#error ODB runtime version mismatch +#endif + +#include + +#include "GovernmentAddress.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace odb +{ + // GovernmentAddress + // + template <> + struct class_traits< ::models::GovernmentAddress > + { + static const class_kind kind = class_object; + }; + + template <> + class access::object_traits< ::models::GovernmentAddress > + { + public: + typedef ::models::GovernmentAddress object_type; + typedef ::models::GovernmentAddress* pointer_type; + typedef odb::pointer_traits pointer_traits; + + static const bool polymorphic = false; + + typedef ::std::string id_type; + + static const bool auto_id = false; + + static const bool abstract = false; + + static id_type + id (const object_type&); + + typedef + no_op_pointer_cache_traits + pointer_cache_traits; + + typedef + no_op_reference_cache_traits + reference_cache_traits; + + static void + callback (database&, object_type&, callback_event); + + static void + callback (database&, const object_type&, callback_event); + }; +} + +#include + +#include +#include +#include +#include +#include + +namespace odb +{ + // GovernmentAddress + // + template + struct query_columns< ::models::GovernmentAddress, id_pgsql, A > + { + // id + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + id_type_; + + static const id_type_ id; + + // addressLabel + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + addressLabel_type_; + + static const addressLabel_type_ addressLabel; + + // regionLookupKey + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + regionLookupKey_type_; + + static const regionLookupKey_type_ regionLookupKey; + }; + + template + const typename query_columns< ::models::GovernmentAddress, id_pgsql, A >::id_type_ + query_columns< ::models::GovernmentAddress, id_pgsql, A >:: + id (A::table_name, "\"id\"", 0); + + template + const typename query_columns< ::models::GovernmentAddress, id_pgsql, A >::addressLabel_type_ + query_columns< ::models::GovernmentAddress, id_pgsql, A >:: + addressLabel (A::table_name, "\"addressLabel\"", 0); + + template + const typename query_columns< ::models::GovernmentAddress, id_pgsql, A >::regionLookupKey_type_ + query_columns< ::models::GovernmentAddress, id_pgsql, A >:: + regionLookupKey (A::table_name, "\"regionLookupKey\"", 0); + + template + struct pointer_query_columns< ::models::GovernmentAddress, id_pgsql, A >: + query_columns< ::models::GovernmentAddress, id_pgsql, A > + { + }; + + template <> + class access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >: + public access::object_traits< ::models::GovernmentAddress > + { + public: + struct id_image_type + { + details::buffer id_value; + std::size_t id_size; + bool id_null; + + std::size_t version; + }; + + struct image_type + { + // id + // + details::buffer id_value; + std::size_t id_size; + bool id_null; + + // addressLabel + // + details::buffer addressLabel_value; + std::size_t addressLabel_size; + bool addressLabel_null; + + // regionLookupKey + // + details::buffer regionLookupKey_value; + std::size_t regionLookupKey_size; + bool regionLookupKey_null; + + std::size_t version; + }; + + struct extra_statement_cache_type; + + using object_traits::id; + + static id_type + id (const image_type&); + + static bool + grow (image_type&, + bool*); + + static void + bind (pgsql::bind*, + image_type&, + pgsql::statement_kind); + + static void + bind (pgsql::bind*, id_image_type&); + + static bool + init (image_type&, + const object_type&, + pgsql::statement_kind); + + static void + init (object_type&, + const image_type&, + database*); + + static void + init (id_image_type&, const id_type&); + + typedef pgsql::object_statements statements_type; + + typedef pgsql::query_base query_base_type; + + static const std::size_t column_count = 3UL; + static const std::size_t id_column_count = 1UL; + static const std::size_t inverse_column_count = 0UL; + static const std::size_t readonly_column_count = 0UL; + static const std::size_t managed_optimistic_column_count = 0UL; + + static const std::size_t separate_load_column_count = 0UL; + static const std::size_t separate_update_column_count = 0UL; + + static const bool versioned = false; + + static const char persist_statement[]; + static const char find_statement[]; + static const char update_statement[]; + static const char erase_statement[]; + static const char query_statement[]; + static const char erase_query_statement[]; + + static const char table_name[]; + + static void + persist (database&, const object_type&); + + static pointer_type + find (database&, const id_type&); + + static bool + find (database&, const id_type&, object_type&); + + static bool + reload (database&, object_type&); + + static void + update (database&, const object_type&); + + static void + erase (database&, const id_type&); + + static void + erase (database&, const object_type&); + + static result + query (database&, const query_base_type&); + + static unsigned long long + erase_query (database&, const query_base_type&); + + static const char persist_statement_name[]; + static const char find_statement_name[]; + static const char update_statement_name[]; + static const char erase_statement_name[]; + static const char query_statement_name[]; + static const char erase_query_statement_name[]; + + static const unsigned int persist_statement_types[]; + static const unsigned int find_statement_types[]; + static const unsigned int update_statement_types[]; + + public: + static bool + find_ (statements_type&, + const id_type*); + + static void + load_ (statements_type&, + object_type&, + bool reload); + }; + + template <> + class access::object_traits_impl< ::models::GovernmentAddress, id_common >: + public access::object_traits_impl< ::models::GovernmentAddress, id_pgsql > + { + }; + + // GovernmentAddress + // +} + +#include "GovernmentAddress-odb.ixx" + +#include + +#endif // GOVERNMENT_ADDRESS_ODB_HXX diff --git a/db/test-schema-v1.2/generated-odb-source/postgre/GovernmentAddress-odb.ixx b/db/test-schema-v1.2/generated-odb-source/postgre/GovernmentAddress-odb.ixx new file mode 100644 index 0000000..f33d9f4 --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/postgre/GovernmentAddress-odb.ixx @@ -0,0 +1,61 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +namespace odb +{ + // GovernmentAddress + // + + inline + access::object_traits< ::models::GovernmentAddress >::id_type + access::object_traits< ::models::GovernmentAddress >:: + id (const object_type& o) + { + return o.id; + } + + inline + void access::object_traits< ::models::GovernmentAddress >:: + callback (database& db, object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } + + inline + void access::object_traits< ::models::GovernmentAddress >:: + callback (database& db, const object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } +} + +namespace odb +{ + // GovernmentAddress + // + + inline + void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + erase (database& db, const object_type& obj) + { + callback (db, obj, callback_event::pre_erase); + erase (db, id (obj)); + callback (db, obj, callback_event::post_erase); + } + + inline + void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + load_ (statements_type& sts, + object_type& obj, + bool) + { + ODB_POTENTIALLY_UNUSED (sts); + ODB_POTENTIALLY_UNUSED (obj); + } +} + diff --git a/db/test-schema-v1.2/generated-odb-source/postgre/GovernmentAddress.xml b/db/test-schema-v1.2/generated-odb-source/postgre/GovernmentAddress.xml new file mode 100644 index 0000000..833e958 --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/postgre/GovernmentAddress.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/db/test-schema-v1.2/generated-odb-source/postgre/TripAttemptResult-odb.cxx b/db/test-schema-v1.2/generated-odb-source/postgre/TripAttemptResult-odb.cxx new file mode 100644 index 0000000..9e43259 --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/postgre/TripAttemptResult-odb.cxx @@ -0,0 +1,1305 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#include + +#include "TripAttemptResult-odb.hxx" + +#include +#include // std::memcpy + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace odb +{ + // TripAttemptResult + // + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + persist_statement_name[] = "persist_models_TripAttemptResult"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + find_statement_name[] = "find_models_TripAttemptResult"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + update_statement_name[] = "update_models_TripAttemptResult"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + erase_statement_name[] = "erase_models_TripAttemptResult"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + query_statement_name[] = "query_models_TripAttemptResult"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + erase_query_statement_name[] = "erase_query_models_TripAttemptResult"; + + const unsigned int access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + persist_statement_types[] = + { + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid + }; + + const unsigned int access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + find_statement_types[] = + { + pgsql::text_oid + }; + + const unsigned int access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + update_statement_types[] = + { + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid + }; + + struct access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::extra_statement_cache_type + { + extra_statement_cache_type ( + pgsql::connection&, + image_type&, + id_image_type&, + pgsql::binding&, + pgsql::binding&, + pgsql::native_binding&, + const unsigned int*) + { + } + }; + + access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::id_type + access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + id (const image_type& i) + { + pgsql::database* db (0); + ODB_POTENTIALLY_UNUSED (db); + + id_type id; + { + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + id, + i.id_value, + i.id_size, + i.id_null); + } + + return id; + } + + bool access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + grow (image_type& i, + bool* t) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (t); + + bool grew (false); + + // id + // + if (t[0UL]) + { + i.id_value.capacity (i.id_size); + grew = true; + } + + // result + // + if (t[1UL]) + { + i.result_value.capacity (i.result_size); + grew = true; + } + + // retryReason + // + if (t[2UL]) + { + i.retryReason_value.capacity (i.retryReason_size); + grew = true; + } + + // governmentSuspensionReason + // + if (t[3UL]) + { + i.governmentSuspensionReason_value.capacity (i.governmentSuspensionReason_size); + grew = true; + } + + // governmentTerminationReason + // + if (t[4UL]) + { + i.governmentTerminationReason_value.capacity (i.governmentTerminationReason_size); + grew = true; + } + + // complianceSuspensionReason + // + if (t[5UL]) + { + i.complianceSuspensionReason_value.capacity (i.complianceSuspensionReason_size); + grew = true; + } + + // complianceTerminationReason + // + if (t[6UL]) + { + i.complianceTerminationReason_value.capacity (i.complianceTerminationReason_size); + grew = true; + } + + // policySuspensionReason + // + if (t[7UL]) + { + i.policySuspensionReason_value.capacity (i.policySuspensionReason_size); + grew = true; + } + + // policyTerminationReason + // + if (t[8UL]) + { + i.policyTerminationReason_value.capacity (i.policyTerminationReason_size); + grew = true; + } + + // cancelationReason + // + if (t[9UL]) + { + i.cancelationReason_value.capacity (i.cancelationReason_size); + grew = true; + } + + // failureReason + // + if (t[10UL]) + { + i.failureReason_value.capacity (i.failureReason_size); + grew = true; + } + + // details + // + if (t[11UL]) + { + i.details_value.capacity (i.details_size); + grew = true; + } + + return grew; + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + bind (pgsql::bind* b, + image_type& i, + pgsql::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (sk); + + using namespace pgsql; + + std::size_t n (0); + + // id + // + if (sk != statement_update) + { + b[n].type = pgsql::bind::text; + b[n].buffer = i.id_value.data (); + b[n].capacity = i.id_value.capacity (); + b[n].size = &i.id_size; + b[n].is_null = &i.id_null; + n++; + } + + // result + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.result_value.data (); + b[n].capacity = i.result_value.capacity (); + b[n].size = &i.result_size; + b[n].is_null = &i.result_null; + n++; + + // retryReason + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.retryReason_value.data (); + b[n].capacity = i.retryReason_value.capacity (); + b[n].size = &i.retryReason_size; + b[n].is_null = &i.retryReason_null; + n++; + + // governmentSuspensionReason + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.governmentSuspensionReason_value.data (); + b[n].capacity = i.governmentSuspensionReason_value.capacity (); + b[n].size = &i.governmentSuspensionReason_size; + b[n].is_null = &i.governmentSuspensionReason_null; + n++; + + // governmentTerminationReason + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.governmentTerminationReason_value.data (); + b[n].capacity = i.governmentTerminationReason_value.capacity (); + b[n].size = &i.governmentTerminationReason_size; + b[n].is_null = &i.governmentTerminationReason_null; + n++; + + // complianceSuspensionReason + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.complianceSuspensionReason_value.data (); + b[n].capacity = i.complianceSuspensionReason_value.capacity (); + b[n].size = &i.complianceSuspensionReason_size; + b[n].is_null = &i.complianceSuspensionReason_null; + n++; + + // complianceTerminationReason + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.complianceTerminationReason_value.data (); + b[n].capacity = i.complianceTerminationReason_value.capacity (); + b[n].size = &i.complianceTerminationReason_size; + b[n].is_null = &i.complianceTerminationReason_null; + n++; + + // policySuspensionReason + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.policySuspensionReason_value.data (); + b[n].capacity = i.policySuspensionReason_value.capacity (); + b[n].size = &i.policySuspensionReason_size; + b[n].is_null = &i.policySuspensionReason_null; + n++; + + // policyTerminationReason + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.policyTerminationReason_value.data (); + b[n].capacity = i.policyTerminationReason_value.capacity (); + b[n].size = &i.policyTerminationReason_size; + b[n].is_null = &i.policyTerminationReason_null; + n++; + + // cancelationReason + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.cancelationReason_value.data (); + b[n].capacity = i.cancelationReason_value.capacity (); + b[n].size = &i.cancelationReason_size; + b[n].is_null = &i.cancelationReason_null; + n++; + + // failureReason + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.failureReason_value.data (); + b[n].capacity = i.failureReason_value.capacity (); + b[n].size = &i.failureReason_size; + b[n].is_null = &i.failureReason_null; + n++; + + // details + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.details_value.data (); + b[n].capacity = i.details_value.capacity (); + b[n].size = &i.details_size; + b[n].is_null = &i.details_null; + n++; + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + bind (pgsql::bind* b, id_image_type& i) + { + std::size_t n (0); + b[n].type = pgsql::bind::text; + b[n].buffer = i.id_value.data (); + b[n].capacity = i.id_value.capacity (); + b[n].size = &i.id_size; + b[n].is_null = &i.id_null; + } + + bool access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + init (image_type& i, + const object_type& o, + pgsql::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (sk); + + using namespace pgsql; + + bool grew (false); + + // id + // + if (sk == statement_insert) + { + ::std::string const& v = + o.id; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.id_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.id_value, + size, + is_null, + v); + i.id_null = is_null; + i.id_size = size; + grew = grew || (cap != i.id_value.capacity ()); + } + + // result + // + { + ::std::string const& v = + o.result; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.result_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.result_value, + size, + is_null, + v); + i.result_null = is_null; + i.result_size = size; + grew = grew || (cap != i.result_value.capacity ()); + } + + // retryReason + // + { + ::std::string const& v = + o.retryReason; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.retryReason_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.retryReason_value, + size, + is_null, + v); + i.retryReason_null = is_null; + i.retryReason_size = size; + grew = grew || (cap != i.retryReason_value.capacity ()); + } + + // governmentSuspensionReason + // + { + ::std::string const& v = + o.governmentSuspensionReason; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.governmentSuspensionReason_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.governmentSuspensionReason_value, + size, + is_null, + v); + i.governmentSuspensionReason_null = is_null; + i.governmentSuspensionReason_size = size; + grew = grew || (cap != i.governmentSuspensionReason_value.capacity ()); + } + + // governmentTerminationReason + // + { + ::std::string const& v = + o.governmentTerminationReason; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.governmentTerminationReason_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.governmentTerminationReason_value, + size, + is_null, + v); + i.governmentTerminationReason_null = is_null; + i.governmentTerminationReason_size = size; + grew = grew || (cap != i.governmentTerminationReason_value.capacity ()); + } + + // complianceSuspensionReason + // + { + ::std::string const& v = + o.complianceSuspensionReason; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.complianceSuspensionReason_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.complianceSuspensionReason_value, + size, + is_null, + v); + i.complianceSuspensionReason_null = is_null; + i.complianceSuspensionReason_size = size; + grew = grew || (cap != i.complianceSuspensionReason_value.capacity ()); + } + + // complianceTerminationReason + // + { + ::std::string const& v = + o.complianceTerminationReason; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.complianceTerminationReason_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.complianceTerminationReason_value, + size, + is_null, + v); + i.complianceTerminationReason_null = is_null; + i.complianceTerminationReason_size = size; + grew = grew || (cap != i.complianceTerminationReason_value.capacity ()); + } + + // policySuspensionReason + // + { + ::std::string const& v = + o.policySuspensionReason; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.policySuspensionReason_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.policySuspensionReason_value, + size, + is_null, + v); + i.policySuspensionReason_null = is_null; + i.policySuspensionReason_size = size; + grew = grew || (cap != i.policySuspensionReason_value.capacity ()); + } + + // policyTerminationReason + // + { + ::std::string const& v = + o.policyTerminationReason; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.policyTerminationReason_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.policyTerminationReason_value, + size, + is_null, + v); + i.policyTerminationReason_null = is_null; + i.policyTerminationReason_size = size; + grew = grew || (cap != i.policyTerminationReason_value.capacity ()); + } + + // cancelationReason + // + { + ::std::string const& v = + o.cancelationReason; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.cancelationReason_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.cancelationReason_value, + size, + is_null, + v); + i.cancelationReason_null = is_null; + i.cancelationReason_size = size; + grew = grew || (cap != i.cancelationReason_value.capacity ()); + } + + // failureReason + // + { + ::std::string const& v = + o.failureReason; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.failureReason_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.failureReason_value, + size, + is_null, + v); + i.failureReason_null = is_null; + i.failureReason_size = size; + grew = grew || (cap != i.failureReason_value.capacity ()); + } + + // details + // + { + ::std::string const& v = + o.details; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.details_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.details_value, + size, + is_null, + v); + i.details_null = is_null; + i.details_size = size; + grew = grew || (cap != i.details_value.capacity ()); + } + + return grew; + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + init (object_type& o, + const image_type& i, + database* db) + { + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (db); + + // id + // + { + ::std::string& v = + o.id; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.id_value, + i.id_size, + i.id_null); + } + + // result + // + { + ::std::string& v = + o.result; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.result_value, + i.result_size, + i.result_null); + } + + // retryReason + // + { + ::std::string& v = + o.retryReason; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.retryReason_value, + i.retryReason_size, + i.retryReason_null); + } + + // governmentSuspensionReason + // + { + ::std::string& v = + o.governmentSuspensionReason; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.governmentSuspensionReason_value, + i.governmentSuspensionReason_size, + i.governmentSuspensionReason_null); + } + + // governmentTerminationReason + // + { + ::std::string& v = + o.governmentTerminationReason; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.governmentTerminationReason_value, + i.governmentTerminationReason_size, + i.governmentTerminationReason_null); + } + + // complianceSuspensionReason + // + { + ::std::string& v = + o.complianceSuspensionReason; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.complianceSuspensionReason_value, + i.complianceSuspensionReason_size, + i.complianceSuspensionReason_null); + } + + // complianceTerminationReason + // + { + ::std::string& v = + o.complianceTerminationReason; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.complianceTerminationReason_value, + i.complianceTerminationReason_size, + i.complianceTerminationReason_null); + } + + // policySuspensionReason + // + { + ::std::string& v = + o.policySuspensionReason; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.policySuspensionReason_value, + i.policySuspensionReason_size, + i.policySuspensionReason_null); + } + + // policyTerminationReason + // + { + ::std::string& v = + o.policyTerminationReason; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.policyTerminationReason_value, + i.policyTerminationReason_size, + i.policyTerminationReason_null); + } + + // cancelationReason + // + { + ::std::string& v = + o.cancelationReason; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.cancelationReason_value, + i.cancelationReason_size, + i.cancelationReason_null); + } + + // failureReason + // + { + ::std::string& v = + o.failureReason; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.failureReason_value, + i.failureReason_size, + i.failureReason_null); + } + + // details + // + { + ::std::string& v = + o.details; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.details_value, + i.details_size, + i.details_null); + } + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + init (id_image_type& i, const id_type& id) + { + bool grew (false); + { + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.id_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.id_value, + size, + is_null, + id); + i.id_null = is_null; + i.id_size = size; + grew = grew || (cap != i.id_value.capacity ()); + } + + if (grew) + i.version++; + } + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::persist_statement[] = + "INSERT INTO \"TripAttemptResult\" " + "(\"id\", " + "\"result\", " + "\"retryReason\", " + "\"governmentSuspensionReason\", " + "\"governmentTerminationReason\", " + "\"complianceSuspensionReason\", " + "\"complianceTerminationReason\", " + "\"policySuspensionReason\", " + "\"policyTerminationReason\", " + "\"cancelationReason\", " + "\"failureReason\", " + "\"details\") " + "VALUES " + "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::find_statement[] = + "SELECT " + "\"TripAttemptResult\".\"id\", " + "\"TripAttemptResult\".\"result\", " + "\"TripAttemptResult\".\"retryReason\", " + "\"TripAttemptResult\".\"governmentSuspensionReason\", " + "\"TripAttemptResult\".\"governmentTerminationReason\", " + "\"TripAttemptResult\".\"complianceSuspensionReason\", " + "\"TripAttemptResult\".\"complianceTerminationReason\", " + "\"TripAttemptResult\".\"policySuspensionReason\", " + "\"TripAttemptResult\".\"policyTerminationReason\", " + "\"TripAttemptResult\".\"cancelationReason\", " + "\"TripAttemptResult\".\"failureReason\", " + "\"TripAttemptResult\".\"details\" " + "FROM \"TripAttemptResult\" " + "WHERE \"TripAttemptResult\".\"id\"=$1"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::update_statement[] = + "UPDATE \"TripAttemptResult\" " + "SET " + "\"result\"=$1, " + "\"retryReason\"=$2, " + "\"governmentSuspensionReason\"=$3, " + "\"governmentTerminationReason\"=$4, " + "\"complianceSuspensionReason\"=$5, " + "\"complianceTerminationReason\"=$6, " + "\"policySuspensionReason\"=$7, " + "\"policyTerminationReason\"=$8, " + "\"cancelationReason\"=$9, " + "\"failureReason\"=$10, " + "\"details\"=$11 " + "WHERE \"id\"=$12"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::erase_statement[] = + "DELETE FROM \"TripAttemptResult\" " + "WHERE \"id\"=$1"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::query_statement[] = + "SELECT " + "\"TripAttemptResult\".\"id\", " + "\"TripAttemptResult\".\"result\", " + "\"TripAttemptResult\".\"retryReason\", " + "\"TripAttemptResult\".\"governmentSuspensionReason\", " + "\"TripAttemptResult\".\"governmentTerminationReason\", " + "\"TripAttemptResult\".\"complianceSuspensionReason\", " + "\"TripAttemptResult\".\"complianceTerminationReason\", " + "\"TripAttemptResult\".\"policySuspensionReason\", " + "\"TripAttemptResult\".\"policyTerminationReason\", " + "\"TripAttemptResult\".\"cancelationReason\", " + "\"TripAttemptResult\".\"failureReason\", " + "\"TripAttemptResult\".\"details\" " + "FROM \"TripAttemptResult\""; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::erase_query_statement[] = + "DELETE FROM \"TripAttemptResult\""; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::table_name[] = + "\"TripAttemptResult\""; + + void access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + persist (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + callback (db, + obj, + callback_event::pre_persist); + + image_type& im (sts.image ()); + binding& imb (sts.insert_image_binding ()); + + if (init (im, obj, statement_insert)) + im.version++; + + if (im.version != sts.insert_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_insert); + sts.insert_image_version (im.version); + imb.version++; + } + + insert_statement& st (sts.persist_statement ()); + if (!st.execute ()) + throw object_already_persistent (); + + callback (db, + obj, + callback_event::post_persist); + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + update (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace pgsql; + using pgsql::update_statement; + + callback (db, obj, callback_event::pre_update); + + pgsql::transaction& tr (pgsql::transaction::current ()); + pgsql::connection& conn (tr.connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + const id_type& id ( + obj.id); + id_image_type& idi (sts.id_image ()); + init (idi, id); + + image_type& im (sts.image ()); + if (init (im, obj, statement_update)) + im.version++; + + bool u (false); + binding& imb (sts.update_image_binding ()); + if (im.version != sts.update_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_update); + sts.update_image_version (im.version); + imb.version++; + u = true; + } + + binding& idb (sts.id_image_binding ()); + if (idi.version != sts.update_id_image_version () || + idb.version == 0) + { + if (idi.version != sts.id_image_version () || + idb.version == 0) + { + bind (idb.bind, idi); + sts.id_image_version (idi.version); + idb.version++; + } + + sts.update_id_image_version (idi.version); + + if (!u) + imb.version++; + } + + update_statement& st (sts.update_statement ()); + if (st.execute () == 0) + throw object_not_persistent (); + + callback (db, obj, callback_event::post_update); + pointer_cache_traits::update (db, obj); + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + erase (database& db, const id_type& id) + { + using namespace pgsql; + + ODB_POTENTIALLY_UNUSED (db); + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + id_image_type& i (sts.id_image ()); + init (i, id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + if (sts.erase_statement ().execute () != 1) + throw object_not_persistent (); + + pointer_cache_traits::erase (db, id); + } + + access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::pointer_type + access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + find (database& db, const id_type& id) + { + using namespace pgsql; + + { + pointer_type p (pointer_cache_traits::find (db, id)); + + if (!pointer_traits::null_ptr (p)) + return p; + } + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (l.locked ()) + { + if (!find_ (sts, &id)) + return pointer_type (); + } + + pointer_type p ( + access::object_factory::create ()); + pointer_traits::guard pg (p); + + pointer_cache_traits::insert_guard ig ( + pointer_cache_traits::insert (db, id, p)); + + object_type& obj (pointer_traits::get_ref (p)); + + if (l.locked ()) + { + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + pointer_cache_traits::load (ig.position ()); + } + else + sts.delay_load (id, obj, ig.position ()); + + ig.release (); + pg.release (); + return p; + } + + bool access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + find (database& db, const id_type& id, object_type& obj) + { + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + reference_cache_traits::position_type pos ( + reference_cache_traits::insert (db, id, obj)); + reference_cache_traits::insert_guard ig (pos); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + reference_cache_traits::load (pos); + ig.release (); + return true; + } + + bool access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + reload (database& db, object_type& obj) + { + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + const id_type& id ( + obj.id); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, true); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + return true; + } + + bool access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + find_ (statements_type& sts, + const id_type* id) + { + using namespace pgsql; + + id_image_type& i (sts.id_image ()); + init (i, *id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + select_statement& st (sts.find_statement ()); + + st.execute (); + auto_result ar (st); + select_statement::result r (st.fetch ()); + + if (r == select_statement::truncated) + { + if (grow (im, sts.select_image_truncated ())) + im.version++; + + if (im.version != sts.select_image_version ()) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + st.refetch (); + } + } + + return r != select_statement::no_data; + } + + result< access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::object_type > + access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + query (database&, const query_base_type& q) + { + using namespace pgsql; + using odb::details::shared; + using odb::details::shared_ptr; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + + statements_type& sts ( + conn.statement_cache ().find_object ()); + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + std::string text (query_statement); + if (!q.empty ()) + { + text += " "; + text += q.clause (); + } + + q.init_parameters (); + shared_ptr st ( + new (shared) select_statement ( + sts.connection (), + query_statement_name, + text, + false, + true, + q.parameter_types (), + q.parameter_count (), + q.parameters_binding (), + imb)); + + st->execute (); + st->deallocate (); + + shared_ptr< odb::object_result_impl > r ( + new (shared) pgsql::object_result_impl ( + q, st, sts, 0)); + + return result (r); + } + + unsigned long long access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + erase_query (database&, const query_base_type& q) + { + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + + std::string text (erase_query_statement); + if (!q.empty ()) + { + text += ' '; + text += q.clause (); + } + + q.init_parameters (); + delete_statement st ( + conn, + erase_query_statement_name, + text, + q.parameter_types (), + q.parameter_count (), + q.parameters_binding ()); + + return st.execute (); + } +} + +#include diff --git a/db/test-schema-v1.2/generated-odb-source/postgre/TripAttemptResult-odb.hxx b/db/test-schema-v1.2/generated-odb-source/postgre/TripAttemptResult-odb.hxx new file mode 100644 index 0000000..0bb9327 --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/postgre/TripAttemptResult-odb.hxx @@ -0,0 +1,516 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#ifndef TRIP_ATTEMPT_RESULT_ODB_HXX +#define TRIP_ATTEMPT_RESULT_ODB_HXX + +#include + +#if (ODB_VERSION != 20400UL) +#error ODB runtime version mismatch +#endif + +#include + +#include "TripAttemptResult.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace odb +{ + // TripAttemptResult + // + template <> + struct class_traits< ::models::TripAttemptResult > + { + static const class_kind kind = class_object; + }; + + template <> + class access::object_traits< ::models::TripAttemptResult > + { + public: + typedef ::models::TripAttemptResult object_type; + typedef ::models::TripAttemptResult* pointer_type; + typedef odb::pointer_traits pointer_traits; + + static const bool polymorphic = false; + + typedef ::std::string id_type; + + static const bool auto_id = false; + + static const bool abstract = false; + + static id_type + id (const object_type&); + + typedef + no_op_pointer_cache_traits + pointer_cache_traits; + + typedef + no_op_reference_cache_traits + reference_cache_traits; + + static void + callback (database&, object_type&, callback_event); + + static void + callback (database&, const object_type&, callback_event); + }; +} + +#include + +#include +#include +#include +#include +#include + +namespace odb +{ + // TripAttemptResult + // + template + struct query_columns< ::models::TripAttemptResult, id_pgsql, A > + { + // id + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + id_type_; + + static const id_type_ id; + + // result + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + result_type_; + + static const result_type_ result; + + // retryReason + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + retryReason_type_; + + static const retryReason_type_ retryReason; + + // governmentSuspensionReason + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + governmentSuspensionReason_type_; + + static const governmentSuspensionReason_type_ governmentSuspensionReason; + + // governmentTerminationReason + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + governmentTerminationReason_type_; + + static const governmentTerminationReason_type_ governmentTerminationReason; + + // complianceSuspensionReason + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + complianceSuspensionReason_type_; + + static const complianceSuspensionReason_type_ complianceSuspensionReason; + + // complianceTerminationReason + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + complianceTerminationReason_type_; + + static const complianceTerminationReason_type_ complianceTerminationReason; + + // policySuspensionReason + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + policySuspensionReason_type_; + + static const policySuspensionReason_type_ policySuspensionReason; + + // policyTerminationReason + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + policyTerminationReason_type_; + + static const policyTerminationReason_type_ policyTerminationReason; + + // cancelationReason + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + cancelationReason_type_; + + static const cancelationReason_type_ cancelationReason; + + // failureReason + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + failureReason_type_; + + static const failureReason_type_ failureReason; + + // details + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + details_type_; + + static const details_type_ details; + }; + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::id_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + id (A::table_name, "\"id\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::result_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + result (A::table_name, "\"result\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::retryReason_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + retryReason (A::table_name, "\"retryReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::governmentSuspensionReason_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + governmentSuspensionReason (A::table_name, "\"governmentSuspensionReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::governmentTerminationReason_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + governmentTerminationReason (A::table_name, "\"governmentTerminationReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::complianceSuspensionReason_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + complianceSuspensionReason (A::table_name, "\"complianceSuspensionReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::complianceTerminationReason_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + complianceTerminationReason (A::table_name, "\"complianceTerminationReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::policySuspensionReason_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + policySuspensionReason (A::table_name, "\"policySuspensionReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::policyTerminationReason_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + policyTerminationReason (A::table_name, "\"policyTerminationReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::cancelationReason_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + cancelationReason (A::table_name, "\"cancelationReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::failureReason_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + failureReason (A::table_name, "\"failureReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::details_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + details (A::table_name, "\"details\"", 0); + + template + struct pointer_query_columns< ::models::TripAttemptResult, id_pgsql, A >: + query_columns< ::models::TripAttemptResult, id_pgsql, A > + { + }; + + template <> + class access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >: + public access::object_traits< ::models::TripAttemptResult > + { + public: + struct id_image_type + { + details::buffer id_value; + std::size_t id_size; + bool id_null; + + std::size_t version; + }; + + struct image_type + { + // id + // + details::buffer id_value; + std::size_t id_size; + bool id_null; + + // result + // + details::buffer result_value; + std::size_t result_size; + bool result_null; + + // retryReason + // + details::buffer retryReason_value; + std::size_t retryReason_size; + bool retryReason_null; + + // governmentSuspensionReason + // + details::buffer governmentSuspensionReason_value; + std::size_t governmentSuspensionReason_size; + bool governmentSuspensionReason_null; + + // governmentTerminationReason + // + details::buffer governmentTerminationReason_value; + std::size_t governmentTerminationReason_size; + bool governmentTerminationReason_null; + + // complianceSuspensionReason + // + details::buffer complianceSuspensionReason_value; + std::size_t complianceSuspensionReason_size; + bool complianceSuspensionReason_null; + + // complianceTerminationReason + // + details::buffer complianceTerminationReason_value; + std::size_t complianceTerminationReason_size; + bool complianceTerminationReason_null; + + // policySuspensionReason + // + details::buffer policySuspensionReason_value; + std::size_t policySuspensionReason_size; + bool policySuspensionReason_null; + + // policyTerminationReason + // + details::buffer policyTerminationReason_value; + std::size_t policyTerminationReason_size; + bool policyTerminationReason_null; + + // cancelationReason + // + details::buffer cancelationReason_value; + std::size_t cancelationReason_size; + bool cancelationReason_null; + + // failureReason + // + details::buffer failureReason_value; + std::size_t failureReason_size; + bool failureReason_null; + + // details + // + details::buffer details_value; + std::size_t details_size; + bool details_null; + + std::size_t version; + }; + + struct extra_statement_cache_type; + + using object_traits::id; + + static id_type + id (const image_type&); + + static bool + grow (image_type&, + bool*); + + static void + bind (pgsql::bind*, + image_type&, + pgsql::statement_kind); + + static void + bind (pgsql::bind*, id_image_type&); + + static bool + init (image_type&, + const object_type&, + pgsql::statement_kind); + + static void + init (object_type&, + const image_type&, + database*); + + static void + init (id_image_type&, const id_type&); + + typedef pgsql::object_statements statements_type; + + typedef pgsql::query_base query_base_type; + + static const std::size_t column_count = 12UL; + static const std::size_t id_column_count = 1UL; + static const std::size_t inverse_column_count = 0UL; + static const std::size_t readonly_column_count = 0UL; + static const std::size_t managed_optimistic_column_count = 0UL; + + static const std::size_t separate_load_column_count = 0UL; + static const std::size_t separate_update_column_count = 0UL; + + static const bool versioned = false; + + static const char persist_statement[]; + static const char find_statement[]; + static const char update_statement[]; + static const char erase_statement[]; + static const char query_statement[]; + static const char erase_query_statement[]; + + static const char table_name[]; + + static void + persist (database&, const object_type&); + + static pointer_type + find (database&, const id_type&); + + static bool + find (database&, const id_type&, object_type&); + + static bool + reload (database&, object_type&); + + static void + update (database&, const object_type&); + + static void + erase (database&, const id_type&); + + static void + erase (database&, const object_type&); + + static result + query (database&, const query_base_type&); + + static unsigned long long + erase_query (database&, const query_base_type&); + + static const char persist_statement_name[]; + static const char find_statement_name[]; + static const char update_statement_name[]; + static const char erase_statement_name[]; + static const char query_statement_name[]; + static const char erase_query_statement_name[]; + + static const unsigned int persist_statement_types[]; + static const unsigned int find_statement_types[]; + static const unsigned int update_statement_types[]; + + public: + static bool + find_ (statements_type&, + const id_type*); + + static void + load_ (statements_type&, + object_type&, + bool reload); + }; + + template <> + class access::object_traits_impl< ::models::TripAttemptResult, id_common >: + public access::object_traits_impl< ::models::TripAttemptResult, id_pgsql > + { + }; + + // TripAttemptResult + // +} + +#include "TripAttemptResult-odb.ixx" + +#include + +#endif // TRIP_ATTEMPT_RESULT_ODB_HXX diff --git a/db/test-schema-v1.2/generated-odb-source/postgre/TripAttemptResult-odb.ixx b/db/test-schema-v1.2/generated-odb-source/postgre/TripAttemptResult-odb.ixx new file mode 100644 index 0000000..e51e168 --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/postgre/TripAttemptResult-odb.ixx @@ -0,0 +1,61 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +namespace odb +{ + // TripAttemptResult + // + + inline + access::object_traits< ::models::TripAttemptResult >::id_type + access::object_traits< ::models::TripAttemptResult >:: + id (const object_type& o) + { + return o.id; + } + + inline + void access::object_traits< ::models::TripAttemptResult >:: + callback (database& db, object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } + + inline + void access::object_traits< ::models::TripAttemptResult >:: + callback (database& db, const object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } +} + +namespace odb +{ + // TripAttemptResult + // + + inline + void access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + erase (database& db, const object_type& obj) + { + callback (db, obj, callback_event::pre_erase); + erase (db, id (obj)); + callback (db, obj, callback_event::post_erase); + } + + inline + void access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + load_ (statements_type& sts, + object_type& obj, + bool) + { + ODB_POTENTIALLY_UNUSED (sts); + ODB_POTENTIALLY_UNUSED (obj); + } +} + diff --git a/db/test-schema-v1.2/generated-odb-source/postgre/TripAttemptResult.xml b/db/test-schema-v1.2/generated-odb-source/postgre/TripAttemptResult.xml new file mode 100644 index 0000000..d04d5e5 --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/postgre/TripAttemptResult.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/db/test-schema-v1.2/generated-odb-source/sqlite/Agent-odb.cxx b/db/test-schema-v1.2/generated-odb-source/sqlite/Agent-odb.cxx new file mode 100644 index 0000000..4da4886 --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/sqlite/Agent-odb.cxx @@ -0,0 +1,815 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#include + +#include "Agent-odb.hxx" + +#include +#include // std::memcpy + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace odb +{ + // Agent + // + + struct access::object_traits_impl< ::models::Agent, id_sqlite >::extra_statement_cache_type + { + extra_statement_cache_type ( + sqlite::connection&, + image_type&, + id_image_type&, + sqlite::binding&, + sqlite::binding&) + { + } + }; + + access::object_traits_impl< ::models::Agent, id_sqlite >::id_type + access::object_traits_impl< ::models::Agent, id_sqlite >:: + id (const image_type& i) + { + sqlite::database* db (0); + ODB_POTENTIALLY_UNUSED (db); + + id_type id; + { + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + id, + i.id_value, + i.id_size, + i.id_null); + } + + return id; + } + + bool access::object_traits_impl< ::models::Agent, id_sqlite >:: + grow (image_type& i, + bool* t) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (t); + + bool grew (false); + + // id + // + if (t[0UL]) + { + i.id_value.capacity (i.id_size); + grew = true; + } + + // role + // + if (t[1UL]) + { + i.role_value.capacity (i.role_size); + grew = true; + } + + // persistent + // + t[2UL] = false; + + // displayName + // + if (t[3UL]) + { + i.displayName_value.capacity (i.displayName_size); + grew = true; + } + + // trustScore + // + t[4UL] = false; + + return grew; + } + + void access::object_traits_impl< ::models::Agent, id_sqlite >:: + bind (sqlite::bind* b, + image_type& i, + sqlite::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (sk); + + using namespace sqlite; + + std::size_t n (0); + + // id + // + if (sk != statement_update) + { + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.id_value.data (); + b[n].size = &i.id_size; + b[n].capacity = i.id_value.capacity (); + b[n].is_null = &i.id_null; + n++; + } + + // role + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.role_value.data (); + b[n].size = &i.role_size; + b[n].capacity = i.role_value.capacity (); + b[n].is_null = &i.role_null; + n++; + + // persistent + // + b[n].type = sqlite::bind::integer; + b[n].buffer = &i.persistent_value; + b[n].is_null = &i.persistent_null; + n++; + + // displayName + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.displayName_value.data (); + b[n].size = &i.displayName_size; + b[n].capacity = i.displayName_value.capacity (); + b[n].is_null = &i.displayName_null; + n++; + + // trustScore + // + b[n].type = sqlite::bind::integer; + b[n].buffer = &i.trustScore_value; + b[n].is_null = &i.trustScore_null; + n++; + } + + void access::object_traits_impl< ::models::Agent, id_sqlite >:: + bind (sqlite::bind* b, id_image_type& i) + { + std::size_t n (0); + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.id_value.data (); + b[n].size = &i.id_size; + b[n].capacity = i.id_value.capacity (); + b[n].is_null = &i.id_null; + } + + bool access::object_traits_impl< ::models::Agent, id_sqlite >:: + init (image_type& i, + const object_type& o, + sqlite::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (sk); + + using namespace sqlite; + + bool grew (false); + + // id + // + if (sk == statement_insert) + { + ::std::string const& v = + o.id; + + bool is_null (false); + std::size_t cap (i.id_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.id_value, + i.id_size, + is_null, + v); + i.id_null = is_null; + grew = grew || (cap != i.id_value.capacity ()); + } + + // role + // + { + ::std::string const& v = + o.role; + + bool is_null (false); + std::size_t cap (i.role_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.role_value, + i.role_size, + is_null, + v); + i.role_null = is_null; + grew = grew || (cap != i.role_value.capacity ()); + } + + // persistent + // + { + bool const& v = + o.persistent; + + bool is_null (false); + sqlite::value_traits< + bool, + sqlite::id_integer >::set_image ( + i.persistent_value, + is_null, + v); + i.persistent_null = is_null; + } + + // displayName + // + { + ::std::string const& v = + o.displayName; + + bool is_null (false); + std::size_t cap (i.displayName_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.displayName_value, + i.displayName_size, + is_null, + v); + i.displayName_null = is_null; + grew = grew || (cap != i.displayName_value.capacity ()); + } + + // trustScore + // + { + ::int32_t const& v = + o.trustScore; + + bool is_null (false); + sqlite::value_traits< + ::int32_t, + sqlite::id_integer >::set_image ( + i.trustScore_value, + is_null, + v); + i.trustScore_null = is_null; + } + + return grew; + } + + void access::object_traits_impl< ::models::Agent, id_sqlite >:: + init (object_type& o, + const image_type& i, + database* db) + { + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (db); + + // id + // + { + ::std::string& v = + o.id; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.id_value, + i.id_size, + i.id_null); + } + + // role + // + { + ::std::string& v = + o.role; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.role_value, + i.role_size, + i.role_null); + } + + // persistent + // + { + bool& v = + o.persistent; + + sqlite::value_traits< + bool, + sqlite::id_integer >::set_value ( + v, + i.persistent_value, + i.persistent_null); + } + + // displayName + // + { + ::std::string& v = + o.displayName; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.displayName_value, + i.displayName_size, + i.displayName_null); + } + + // trustScore + // + { + ::int32_t& v = + o.trustScore; + + sqlite::value_traits< + ::int32_t, + sqlite::id_integer >::set_value ( + v, + i.trustScore_value, + i.trustScore_null); + } + } + + void access::object_traits_impl< ::models::Agent, id_sqlite >:: + init (id_image_type& i, const id_type& id) + { + bool grew (false); + { + bool is_null (false); + std::size_t cap (i.id_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.id_value, + i.id_size, + is_null, + id); + i.id_null = is_null; + grew = grew || (cap != i.id_value.capacity ()); + } + + if (grew) + i.version++; + } + + const char access::object_traits_impl< ::models::Agent, id_sqlite >::persist_statement[] = + "INSERT INTO \"Agent\" " + "(\"id\", " + "\"role\", " + "\"persistent\", " + "\"displayName\", " + "\"trustScore\") " + "VALUES " + "(?, ?, ?, ?, ?)"; + + const char access::object_traits_impl< ::models::Agent, id_sqlite >::find_statement[] = + "SELECT " + "\"Agent\".\"id\", " + "\"Agent\".\"role\", " + "\"Agent\".\"persistent\", " + "\"Agent\".\"displayName\", " + "\"Agent\".\"trustScore\" " + "FROM \"Agent\" " + "WHERE \"Agent\".\"id\"=?"; + + const char access::object_traits_impl< ::models::Agent, id_sqlite >::update_statement[] = + "UPDATE \"Agent\" " + "SET " + "\"role\"=?, " + "\"persistent\"=?, " + "\"displayName\"=?, " + "\"trustScore\"=? " + "WHERE \"id\"=?"; + + const char access::object_traits_impl< ::models::Agent, id_sqlite >::erase_statement[] = + "DELETE FROM \"Agent\" " + "WHERE \"id\"=?"; + + const char access::object_traits_impl< ::models::Agent, id_sqlite >::query_statement[] = + "SELECT " + "\"Agent\".\"id\", " + "\"Agent\".\"role\", " + "\"Agent\".\"persistent\", " + "\"Agent\".\"displayName\", " + "\"Agent\".\"trustScore\" " + "FROM \"Agent\""; + + const char access::object_traits_impl< ::models::Agent, id_sqlite >::erase_query_statement[] = + "DELETE FROM \"Agent\""; + + const char access::object_traits_impl< ::models::Agent, id_sqlite >::table_name[] = + "\"Agent\""; + + void access::object_traits_impl< ::models::Agent, id_sqlite >:: + persist (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + callback (db, + obj, + callback_event::pre_persist); + + image_type& im (sts.image ()); + binding& imb (sts.insert_image_binding ()); + + if (init (im, obj, statement_insert)) + im.version++; + + if (im.version != sts.insert_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_insert); + sts.insert_image_version (im.version); + imb.version++; + } + + insert_statement& st (sts.persist_statement ()); + if (!st.execute ()) + throw object_already_persistent (); + + callback (db, + obj, + callback_event::post_persist); + } + + void access::object_traits_impl< ::models::Agent, id_sqlite >:: + update (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace sqlite; + using sqlite::update_statement; + + callback (db, obj, callback_event::pre_update); + + sqlite::transaction& tr (sqlite::transaction::current ()); + sqlite::connection& conn (tr.connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + const id_type& id ( + obj.id); + id_image_type& idi (sts.id_image ()); + init (idi, id); + + image_type& im (sts.image ()); + if (init (im, obj, statement_update)) + im.version++; + + bool u (false); + binding& imb (sts.update_image_binding ()); + if (im.version != sts.update_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_update); + sts.update_image_version (im.version); + imb.version++; + u = true; + } + + binding& idb (sts.id_image_binding ()); + if (idi.version != sts.update_id_image_version () || + idb.version == 0) + { + if (idi.version != sts.id_image_version () || + idb.version == 0) + { + bind (idb.bind, idi); + sts.id_image_version (idi.version); + idb.version++; + } + + sts.update_id_image_version (idi.version); + + if (!u) + imb.version++; + } + + update_statement& st (sts.update_statement ()); + if (st.execute () == 0) + throw object_not_persistent (); + + callback (db, obj, callback_event::post_update); + pointer_cache_traits::update (db, obj); + } + + void access::object_traits_impl< ::models::Agent, id_sqlite >:: + erase (database& db, const id_type& id) + { + using namespace sqlite; + + ODB_POTENTIALLY_UNUSED (db); + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + id_image_type& i (sts.id_image ()); + init (i, id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + if (sts.erase_statement ().execute () != 1) + throw object_not_persistent (); + + pointer_cache_traits::erase (db, id); + } + + access::object_traits_impl< ::models::Agent, id_sqlite >::pointer_type + access::object_traits_impl< ::models::Agent, id_sqlite >:: + find (database& db, const id_type& id) + { + using namespace sqlite; + + { + pointer_type p (pointer_cache_traits::find (db, id)); + + if (!pointer_traits::null_ptr (p)) + return p; + } + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (l.locked ()) + { + if (!find_ (sts, &id)) + return pointer_type (); + } + + pointer_type p ( + access::object_factory::create ()); + pointer_traits::guard pg (p); + + pointer_cache_traits::insert_guard ig ( + pointer_cache_traits::insert (db, id, p)); + + object_type& obj (pointer_traits::get_ref (p)); + + if (l.locked ()) + { + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + pointer_cache_traits::load (ig.position ()); + } + else + sts.delay_load (id, obj, ig.position ()); + + ig.release (); + pg.release (); + return p; + } + + bool access::object_traits_impl< ::models::Agent, id_sqlite >:: + find (database& db, const id_type& id, object_type& obj) + { + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + reference_cache_traits::position_type pos ( + reference_cache_traits::insert (db, id, obj)); + reference_cache_traits::insert_guard ig (pos); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + reference_cache_traits::load (pos); + ig.release (); + return true; + } + + bool access::object_traits_impl< ::models::Agent, id_sqlite >:: + reload (database& db, object_type& obj) + { + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + const id_type& id ( + obj.id); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, true); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + return true; + } + + bool access::object_traits_impl< ::models::Agent, id_sqlite >:: + find_ (statements_type& sts, + const id_type* id) + { + using namespace sqlite; + + id_image_type& i (sts.id_image ()); + init (i, *id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + select_statement& st (sts.find_statement ()); + + st.execute (); + auto_result ar (st); + select_statement::result r (st.fetch ()); + + if (r == select_statement::truncated) + { + if (grow (im, sts.select_image_truncated ())) + im.version++; + + if (im.version != sts.select_image_version ()) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + st.refetch (); + } + } + + return r != select_statement::no_data; + } + + result< access::object_traits_impl< ::models::Agent, id_sqlite >::object_type > + access::object_traits_impl< ::models::Agent, id_sqlite >:: + query (database&, const query_base_type& q) + { + using namespace sqlite; + using odb::details::shared; + using odb::details::shared_ptr; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + + statements_type& sts ( + conn.statement_cache ().find_object ()); + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + std::string text (query_statement); + if (!q.empty ()) + { + text += " "; + text += q.clause (); + } + + q.init_parameters (); + shared_ptr st ( + new (shared) select_statement ( + conn, + text, + false, + true, + q.parameters_binding (), + imb)); + + st->execute (); + + shared_ptr< odb::object_result_impl > r ( + new (shared) sqlite::object_result_impl ( + q, st, sts, 0)); + + return result (r); + } + + unsigned long long access::object_traits_impl< ::models::Agent, id_sqlite >:: + erase_query (database&, const query_base_type& q) + { + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + + std::string text (erase_query_statement); + if (!q.empty ()) + { + text += ' '; + text += q.clause (); + } + + q.init_parameters (); + delete_statement st ( + conn, + text, + q.parameters_binding ()); + + return st.execute (); + } +} + +#include diff --git a/db/test-schema-v1.2/generated-odb-source/sqlite/Agent-odb.hxx b/db/test-schema-v1.2/generated-odb-source/sqlite/Agent-odb.hxx new file mode 100644 index 0000000..08008ee --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/sqlite/Agent-odb.hxx @@ -0,0 +1,342 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#ifndef AGENT_ODB_HXX +#define AGENT_ODB_HXX + +#include + +#if (ODB_VERSION != 20400UL) +#error ODB runtime version mismatch +#endif + +#include + +#include "Agent.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace odb +{ + // Agent + // + template <> + struct class_traits< ::models::Agent > + { + static const class_kind kind = class_object; + }; + + template <> + class access::object_traits< ::models::Agent > + { + public: + typedef ::models::Agent object_type; + typedef ::models::Agent* pointer_type; + typedef odb::pointer_traits pointer_traits; + + static const bool polymorphic = false; + + typedef ::std::string id_type; + + static const bool auto_id = false; + + static const bool abstract = false; + + static id_type + id (const object_type&); + + typedef + no_op_pointer_cache_traits + pointer_cache_traits; + + typedef + no_op_reference_cache_traits + reference_cache_traits; + + static void + callback (database&, object_type&, callback_event); + + static void + callback (database&, const object_type&, callback_event); + }; +} + +#include + +#include +#include +#include +#include +#include + +namespace odb +{ + // Agent + // + template + struct query_columns< ::models::Agent, id_sqlite, A > + { + // id + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + id_type_; + + static const id_type_ id; + + // role + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + role_type_; + + static const role_type_ role; + + // persistent + // + typedef + sqlite::query_column< + sqlite::value_traits< + bool, + sqlite::id_integer >::query_type, + sqlite::id_integer > + persistent_type_; + + static const persistent_type_ persistent; + + // displayName + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + displayName_type_; + + static const displayName_type_ displayName; + + // trustScore + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::int32_t, + sqlite::id_integer >::query_type, + sqlite::id_integer > + trustScore_type_; + + static const trustScore_type_ trustScore; + }; + + template + const typename query_columns< ::models::Agent, id_sqlite, A >::id_type_ + query_columns< ::models::Agent, id_sqlite, A >:: + id (A::table_name, "\"id\"", 0); + + template + const typename query_columns< ::models::Agent, id_sqlite, A >::role_type_ + query_columns< ::models::Agent, id_sqlite, A >:: + role (A::table_name, "\"role\"", 0); + + template + const typename query_columns< ::models::Agent, id_sqlite, A >::persistent_type_ + query_columns< ::models::Agent, id_sqlite, A >:: + persistent (A::table_name, "\"persistent\"", 0); + + template + const typename query_columns< ::models::Agent, id_sqlite, A >::displayName_type_ + query_columns< ::models::Agent, id_sqlite, A >:: + displayName (A::table_name, "\"displayName\"", 0); + + template + const typename query_columns< ::models::Agent, id_sqlite, A >::trustScore_type_ + query_columns< ::models::Agent, id_sqlite, A >:: + trustScore (A::table_name, "\"trustScore\"", 0); + + template + struct pointer_query_columns< ::models::Agent, id_sqlite, A >: + query_columns< ::models::Agent, id_sqlite, A > + { + }; + + template <> + class access::object_traits_impl< ::models::Agent, id_sqlite >: + public access::object_traits< ::models::Agent > + { + public: + struct id_image_type + { + details::buffer id_value; + std::size_t id_size; + bool id_null; + + std::size_t version; + }; + + struct image_type + { + // id + // + details::buffer id_value; + std::size_t id_size; + bool id_null; + + // role + // + details::buffer role_value; + std::size_t role_size; + bool role_null; + + // persistent + // + long long persistent_value; + bool persistent_null; + + // displayName + // + details::buffer displayName_value; + std::size_t displayName_size; + bool displayName_null; + + // trustScore + // + long long trustScore_value; + bool trustScore_null; + + std::size_t version; + }; + + struct extra_statement_cache_type; + + using object_traits::id; + + static id_type + id (const image_type&); + + static bool + grow (image_type&, + bool*); + + static void + bind (sqlite::bind*, + image_type&, + sqlite::statement_kind); + + static void + bind (sqlite::bind*, id_image_type&); + + static bool + init (image_type&, + const object_type&, + sqlite::statement_kind); + + static void + init (object_type&, + const image_type&, + database*); + + static void + init (id_image_type&, const id_type&); + + typedef sqlite::object_statements statements_type; + + typedef sqlite::query_base query_base_type; + + static const std::size_t column_count = 5UL; + static const std::size_t id_column_count = 1UL; + static const std::size_t inverse_column_count = 0UL; + static const std::size_t readonly_column_count = 0UL; + static const std::size_t managed_optimistic_column_count = 0UL; + + static const std::size_t separate_load_column_count = 0UL; + static const std::size_t separate_update_column_count = 0UL; + + static const bool versioned = false; + + static const char persist_statement[]; + static const char find_statement[]; + static const char update_statement[]; + static const char erase_statement[]; + static const char query_statement[]; + static const char erase_query_statement[]; + + static const char table_name[]; + + static void + persist (database&, const object_type&); + + static pointer_type + find (database&, const id_type&); + + static bool + find (database&, const id_type&, object_type&); + + static bool + reload (database&, object_type&); + + static void + update (database&, const object_type&); + + static void + erase (database&, const id_type&); + + static void + erase (database&, const object_type&); + + static result + query (database&, const query_base_type&); + + static unsigned long long + erase_query (database&, const query_base_type&); + + public: + static bool + find_ (statements_type&, + const id_type*); + + static void + load_ (statements_type&, + object_type&, + bool reload); + }; + + template <> + class access::object_traits_impl< ::models::Agent, id_common >: + public access::object_traits_impl< ::models::Agent, id_sqlite > + { + }; + + // Agent + // +} + +#include "Agent-odb.ixx" + +#include + +#endif // AGENT_ODB_HXX diff --git a/db/test-schema-v1.2/generated-odb-source/sqlite/Agent-odb.ixx b/db/test-schema-v1.2/generated-odb-source/sqlite/Agent-odb.ixx new file mode 100644 index 0000000..8f2b5e1 --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/sqlite/Agent-odb.ixx @@ -0,0 +1,61 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +namespace odb +{ + // Agent + // + + inline + access::object_traits< ::models::Agent >::id_type + access::object_traits< ::models::Agent >:: + id (const object_type& o) + { + return o.id; + } + + inline + void access::object_traits< ::models::Agent >:: + callback (database& db, object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } + + inline + void access::object_traits< ::models::Agent >:: + callback (database& db, const object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } +} + +namespace odb +{ + // Agent + // + + inline + void access::object_traits_impl< ::models::Agent, id_sqlite >:: + erase (database& db, const object_type& obj) + { + callback (db, obj, callback_event::pre_erase); + erase (db, id (obj)); + callback (db, obj, callback_event::post_erase); + } + + inline + void access::object_traits_impl< ::models::Agent, id_sqlite >:: + load_ (statements_type& sts, + object_type& obj, + bool) + { + ODB_POTENTIALLY_UNUSED (sts); + ODB_POTENTIALLY_UNUSED (obj); + } +} + diff --git a/db/test-schema-v1.2/generated-odb-source/sqlite/Agent.xml b/db/test-schema-v1.2/generated-odb-source/sqlite/Agent.xml new file mode 100644 index 0000000..47c12cb --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/sqlite/Agent.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/db/test-schema-v1.2/generated-odb-source/sqlite/GovernmentAddress-odb.cxx b/db/test-schema-v1.2/generated-odb-source/sqlite/GovernmentAddress-odb.cxx new file mode 100644 index 0000000..f5c1a1a --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/sqlite/GovernmentAddress-odb.cxx @@ -0,0 +1,725 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#include + +#include "GovernmentAddress-odb.hxx" + +#include +#include // std::memcpy + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace odb +{ + // GovernmentAddress + // + + struct access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::extra_statement_cache_type + { + extra_statement_cache_type ( + sqlite::connection&, + image_type&, + id_image_type&, + sqlite::binding&, + sqlite::binding&) + { + } + }; + + access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::id_type + access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + id (const image_type& i) + { + sqlite::database* db (0); + ODB_POTENTIALLY_UNUSED (db); + + id_type id; + { + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + id, + i.id_value, + i.id_size, + i.id_null); + } + + return id; + } + + bool access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + grow (image_type& i, + bool* t) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (t); + + bool grew (false); + + // id + // + if (t[0UL]) + { + i.id_value.capacity (i.id_size); + grew = true; + } + + // addressLabel + // + if (t[1UL]) + { + i.addressLabel_value.capacity (i.addressLabel_size); + grew = true; + } + + // regionLookupKey + // + if (t[2UL]) + { + i.regionLookupKey_value.capacity (i.regionLookupKey_size); + grew = true; + } + + return grew; + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + bind (sqlite::bind* b, + image_type& i, + sqlite::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (sk); + + using namespace sqlite; + + std::size_t n (0); + + // id + // + if (sk != statement_update) + { + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.id_value.data (); + b[n].size = &i.id_size; + b[n].capacity = i.id_value.capacity (); + b[n].is_null = &i.id_null; + n++; + } + + // addressLabel + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.addressLabel_value.data (); + b[n].size = &i.addressLabel_size; + b[n].capacity = i.addressLabel_value.capacity (); + b[n].is_null = &i.addressLabel_null; + n++; + + // regionLookupKey + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.regionLookupKey_value.data (); + b[n].size = &i.regionLookupKey_size; + b[n].capacity = i.regionLookupKey_value.capacity (); + b[n].is_null = &i.regionLookupKey_null; + n++; + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + bind (sqlite::bind* b, id_image_type& i) + { + std::size_t n (0); + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.id_value.data (); + b[n].size = &i.id_size; + b[n].capacity = i.id_value.capacity (); + b[n].is_null = &i.id_null; + } + + bool access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + init (image_type& i, + const object_type& o, + sqlite::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (sk); + + using namespace sqlite; + + bool grew (false); + + // id + // + if (sk == statement_insert) + { + ::std::string const& v = + o.id; + + bool is_null (false); + std::size_t cap (i.id_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.id_value, + i.id_size, + is_null, + v); + i.id_null = is_null; + grew = grew || (cap != i.id_value.capacity ()); + } + + // addressLabel + // + { + ::std::string const& v = + o.addressLabel; + + bool is_null (false); + std::size_t cap (i.addressLabel_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.addressLabel_value, + i.addressLabel_size, + is_null, + v); + i.addressLabel_null = is_null; + grew = grew || (cap != i.addressLabel_value.capacity ()); + } + + // regionLookupKey + // + { + ::std::string const& v = + o.regionLookupKey; + + bool is_null (false); + std::size_t cap (i.regionLookupKey_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.regionLookupKey_value, + i.regionLookupKey_size, + is_null, + v); + i.regionLookupKey_null = is_null; + grew = grew || (cap != i.regionLookupKey_value.capacity ()); + } + + return grew; + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + init (object_type& o, + const image_type& i, + database* db) + { + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (db); + + // id + // + { + ::std::string& v = + o.id; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.id_value, + i.id_size, + i.id_null); + } + + // addressLabel + // + { + ::std::string& v = + o.addressLabel; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.addressLabel_value, + i.addressLabel_size, + i.addressLabel_null); + } + + // regionLookupKey + // + { + ::std::string& v = + o.regionLookupKey; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.regionLookupKey_value, + i.regionLookupKey_size, + i.regionLookupKey_null); + } + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + init (id_image_type& i, const id_type& id) + { + bool grew (false); + { + bool is_null (false); + std::size_t cap (i.id_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.id_value, + i.id_size, + is_null, + id); + i.id_null = is_null; + grew = grew || (cap != i.id_value.capacity ()); + } + + if (grew) + i.version++; + } + + const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::persist_statement[] = + "INSERT INTO \"GovernmentAddress\" " + "(\"id\", " + "\"addressLabel\", " + "\"regionLookupKey\") " + "VALUES " + "(?, ?, ?)"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::find_statement[] = + "SELECT " + "\"GovernmentAddress\".\"id\", " + "\"GovernmentAddress\".\"addressLabel\", " + "\"GovernmentAddress\".\"regionLookupKey\" " + "FROM \"GovernmentAddress\" " + "WHERE \"GovernmentAddress\".\"id\"=?"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::update_statement[] = + "UPDATE \"GovernmentAddress\" " + "SET " + "\"addressLabel\"=?, " + "\"regionLookupKey\"=? " + "WHERE \"id\"=?"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::erase_statement[] = + "DELETE FROM \"GovernmentAddress\" " + "WHERE \"id\"=?"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::query_statement[] = + "SELECT " + "\"GovernmentAddress\".\"id\", " + "\"GovernmentAddress\".\"addressLabel\", " + "\"GovernmentAddress\".\"regionLookupKey\" " + "FROM \"GovernmentAddress\""; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::erase_query_statement[] = + "DELETE FROM \"GovernmentAddress\""; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::table_name[] = + "\"GovernmentAddress\""; + + void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + persist (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + callback (db, + obj, + callback_event::pre_persist); + + image_type& im (sts.image ()); + binding& imb (sts.insert_image_binding ()); + + if (init (im, obj, statement_insert)) + im.version++; + + if (im.version != sts.insert_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_insert); + sts.insert_image_version (im.version); + imb.version++; + } + + insert_statement& st (sts.persist_statement ()); + if (!st.execute ()) + throw object_already_persistent (); + + callback (db, + obj, + callback_event::post_persist); + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + update (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace sqlite; + using sqlite::update_statement; + + callback (db, obj, callback_event::pre_update); + + sqlite::transaction& tr (sqlite::transaction::current ()); + sqlite::connection& conn (tr.connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + const id_type& id ( + obj.id); + id_image_type& idi (sts.id_image ()); + init (idi, id); + + image_type& im (sts.image ()); + if (init (im, obj, statement_update)) + im.version++; + + bool u (false); + binding& imb (sts.update_image_binding ()); + if (im.version != sts.update_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_update); + sts.update_image_version (im.version); + imb.version++; + u = true; + } + + binding& idb (sts.id_image_binding ()); + if (idi.version != sts.update_id_image_version () || + idb.version == 0) + { + if (idi.version != sts.id_image_version () || + idb.version == 0) + { + bind (idb.bind, idi); + sts.id_image_version (idi.version); + idb.version++; + } + + sts.update_id_image_version (idi.version); + + if (!u) + imb.version++; + } + + update_statement& st (sts.update_statement ()); + if (st.execute () == 0) + throw object_not_persistent (); + + callback (db, obj, callback_event::post_update); + pointer_cache_traits::update (db, obj); + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + erase (database& db, const id_type& id) + { + using namespace sqlite; + + ODB_POTENTIALLY_UNUSED (db); + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + id_image_type& i (sts.id_image ()); + init (i, id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + if (sts.erase_statement ().execute () != 1) + throw object_not_persistent (); + + pointer_cache_traits::erase (db, id); + } + + access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::pointer_type + access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + find (database& db, const id_type& id) + { + using namespace sqlite; + + { + pointer_type p (pointer_cache_traits::find (db, id)); + + if (!pointer_traits::null_ptr (p)) + return p; + } + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (l.locked ()) + { + if (!find_ (sts, &id)) + return pointer_type (); + } + + pointer_type p ( + access::object_factory::create ()); + pointer_traits::guard pg (p); + + pointer_cache_traits::insert_guard ig ( + pointer_cache_traits::insert (db, id, p)); + + object_type& obj (pointer_traits::get_ref (p)); + + if (l.locked ()) + { + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + pointer_cache_traits::load (ig.position ()); + } + else + sts.delay_load (id, obj, ig.position ()); + + ig.release (); + pg.release (); + return p; + } + + bool access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + find (database& db, const id_type& id, object_type& obj) + { + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + reference_cache_traits::position_type pos ( + reference_cache_traits::insert (db, id, obj)); + reference_cache_traits::insert_guard ig (pos); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + reference_cache_traits::load (pos); + ig.release (); + return true; + } + + bool access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + reload (database& db, object_type& obj) + { + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + const id_type& id ( + obj.id); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, true); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + return true; + } + + bool access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + find_ (statements_type& sts, + const id_type* id) + { + using namespace sqlite; + + id_image_type& i (sts.id_image ()); + init (i, *id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + select_statement& st (sts.find_statement ()); + + st.execute (); + auto_result ar (st); + select_statement::result r (st.fetch ()); + + if (r == select_statement::truncated) + { + if (grow (im, sts.select_image_truncated ())) + im.version++; + + if (im.version != sts.select_image_version ()) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + st.refetch (); + } + } + + return r != select_statement::no_data; + } + + result< access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::object_type > + access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + query (database&, const query_base_type& q) + { + using namespace sqlite; + using odb::details::shared; + using odb::details::shared_ptr; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + + statements_type& sts ( + conn.statement_cache ().find_object ()); + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + std::string text (query_statement); + if (!q.empty ()) + { + text += " "; + text += q.clause (); + } + + q.init_parameters (); + shared_ptr st ( + new (shared) select_statement ( + conn, + text, + false, + true, + q.parameters_binding (), + imb)); + + st->execute (); + + shared_ptr< odb::object_result_impl > r ( + new (shared) sqlite::object_result_impl ( + q, st, sts, 0)); + + return result (r); + } + + unsigned long long access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + erase_query (database&, const query_base_type& q) + { + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + + std::string text (erase_query_statement); + if (!q.empty ()) + { + text += ' '; + text += q.clause (); + } + + q.init_parameters (); + delete_statement st ( + conn, + text, + q.parameters_binding ()); + + return st.execute (); + } +} + +#include diff --git a/db/test-schema-v1.2/generated-odb-source/sqlite/GovernmentAddress-odb.hxx b/db/test-schema-v1.2/generated-odb-source/sqlite/GovernmentAddress-odb.hxx new file mode 100644 index 0000000..52d8158 --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/sqlite/GovernmentAddress-odb.hxx @@ -0,0 +1,298 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#ifndef GOVERNMENT_ADDRESS_ODB_HXX +#define GOVERNMENT_ADDRESS_ODB_HXX + +#include + +#if (ODB_VERSION != 20400UL) +#error ODB runtime version mismatch +#endif + +#include + +#include "GovernmentAddress.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace odb +{ + // GovernmentAddress + // + template <> + struct class_traits< ::models::GovernmentAddress > + { + static const class_kind kind = class_object; + }; + + template <> + class access::object_traits< ::models::GovernmentAddress > + { + public: + typedef ::models::GovernmentAddress object_type; + typedef ::models::GovernmentAddress* pointer_type; + typedef odb::pointer_traits pointer_traits; + + static const bool polymorphic = false; + + typedef ::std::string id_type; + + static const bool auto_id = false; + + static const bool abstract = false; + + static id_type + id (const object_type&); + + typedef + no_op_pointer_cache_traits + pointer_cache_traits; + + typedef + no_op_reference_cache_traits + reference_cache_traits; + + static void + callback (database&, object_type&, callback_event); + + static void + callback (database&, const object_type&, callback_event); + }; +} + +#include + +#include +#include +#include +#include +#include + +namespace odb +{ + // GovernmentAddress + // + template + struct query_columns< ::models::GovernmentAddress, id_sqlite, A > + { + // id + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + id_type_; + + static const id_type_ id; + + // addressLabel + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + addressLabel_type_; + + static const addressLabel_type_ addressLabel; + + // regionLookupKey + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + regionLookupKey_type_; + + static const regionLookupKey_type_ regionLookupKey; + }; + + template + const typename query_columns< ::models::GovernmentAddress, id_sqlite, A >::id_type_ + query_columns< ::models::GovernmentAddress, id_sqlite, A >:: + id (A::table_name, "\"id\"", 0); + + template + const typename query_columns< ::models::GovernmentAddress, id_sqlite, A >::addressLabel_type_ + query_columns< ::models::GovernmentAddress, id_sqlite, A >:: + addressLabel (A::table_name, "\"addressLabel\"", 0); + + template + const typename query_columns< ::models::GovernmentAddress, id_sqlite, A >::regionLookupKey_type_ + query_columns< ::models::GovernmentAddress, id_sqlite, A >:: + regionLookupKey (A::table_name, "\"regionLookupKey\"", 0); + + template + struct pointer_query_columns< ::models::GovernmentAddress, id_sqlite, A >: + query_columns< ::models::GovernmentAddress, id_sqlite, A > + { + }; + + template <> + class access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >: + public access::object_traits< ::models::GovernmentAddress > + { + public: + struct id_image_type + { + details::buffer id_value; + std::size_t id_size; + bool id_null; + + std::size_t version; + }; + + struct image_type + { + // id + // + details::buffer id_value; + std::size_t id_size; + bool id_null; + + // addressLabel + // + details::buffer addressLabel_value; + std::size_t addressLabel_size; + bool addressLabel_null; + + // regionLookupKey + // + details::buffer regionLookupKey_value; + std::size_t regionLookupKey_size; + bool regionLookupKey_null; + + std::size_t version; + }; + + struct extra_statement_cache_type; + + using object_traits::id; + + static id_type + id (const image_type&); + + static bool + grow (image_type&, + bool*); + + static void + bind (sqlite::bind*, + image_type&, + sqlite::statement_kind); + + static void + bind (sqlite::bind*, id_image_type&); + + static bool + init (image_type&, + const object_type&, + sqlite::statement_kind); + + static void + init (object_type&, + const image_type&, + database*); + + static void + init (id_image_type&, const id_type&); + + typedef sqlite::object_statements statements_type; + + typedef sqlite::query_base query_base_type; + + static const std::size_t column_count = 3UL; + static const std::size_t id_column_count = 1UL; + static const std::size_t inverse_column_count = 0UL; + static const std::size_t readonly_column_count = 0UL; + static const std::size_t managed_optimistic_column_count = 0UL; + + static const std::size_t separate_load_column_count = 0UL; + static const std::size_t separate_update_column_count = 0UL; + + static const bool versioned = false; + + static const char persist_statement[]; + static const char find_statement[]; + static const char update_statement[]; + static const char erase_statement[]; + static const char query_statement[]; + static const char erase_query_statement[]; + + static const char table_name[]; + + static void + persist (database&, const object_type&); + + static pointer_type + find (database&, const id_type&); + + static bool + find (database&, const id_type&, object_type&); + + static bool + reload (database&, object_type&); + + static void + update (database&, const object_type&); + + static void + erase (database&, const id_type&); + + static void + erase (database&, const object_type&); + + static result + query (database&, const query_base_type&); + + static unsigned long long + erase_query (database&, const query_base_type&); + + public: + static bool + find_ (statements_type&, + const id_type*); + + static void + load_ (statements_type&, + object_type&, + bool reload); + }; + + template <> + class access::object_traits_impl< ::models::GovernmentAddress, id_common >: + public access::object_traits_impl< ::models::GovernmentAddress, id_sqlite > + { + }; + + // GovernmentAddress + // +} + +#include "GovernmentAddress-odb.ixx" + +#include + +#endif // GOVERNMENT_ADDRESS_ODB_HXX diff --git a/db/test-schema-v1.2/generated-odb-source/sqlite/GovernmentAddress-odb.ixx b/db/test-schema-v1.2/generated-odb-source/sqlite/GovernmentAddress-odb.ixx new file mode 100644 index 0000000..932bbcf --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/sqlite/GovernmentAddress-odb.ixx @@ -0,0 +1,61 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +namespace odb +{ + // GovernmentAddress + // + + inline + access::object_traits< ::models::GovernmentAddress >::id_type + access::object_traits< ::models::GovernmentAddress >:: + id (const object_type& o) + { + return o.id; + } + + inline + void access::object_traits< ::models::GovernmentAddress >:: + callback (database& db, object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } + + inline + void access::object_traits< ::models::GovernmentAddress >:: + callback (database& db, const object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } +} + +namespace odb +{ + // GovernmentAddress + // + + inline + void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + erase (database& db, const object_type& obj) + { + callback (db, obj, callback_event::pre_erase); + erase (db, id (obj)); + callback (db, obj, callback_event::post_erase); + } + + inline + void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + load_ (statements_type& sts, + object_type& obj, + bool) + { + ODB_POTENTIALLY_UNUSED (sts); + ODB_POTENTIALLY_UNUSED (obj); + } +} + diff --git a/db/test-schema-v1.2/generated-odb-source/sqlite/GovernmentAddress.xml b/db/test-schema-v1.2/generated-odb-source/sqlite/GovernmentAddress.xml new file mode 100644 index 0000000..ee6c6c8 --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/sqlite/GovernmentAddress.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/db/test-schema-v1.2/generated-odb-source/sqlite/TripAttemptResult-odb.cxx b/db/test-schema-v1.2/generated-odb-source/sqlite/TripAttemptResult-odb.cxx new file mode 100644 index 0000000..44e4bfc --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/sqlite/TripAttemptResult-odb.cxx @@ -0,0 +1,1238 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#include + +#include "TripAttemptResult-odb.hxx" + +#include +#include // std::memcpy + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace odb +{ + // TripAttemptResult + // + + struct access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::extra_statement_cache_type + { + extra_statement_cache_type ( + sqlite::connection&, + image_type&, + id_image_type&, + sqlite::binding&, + sqlite::binding&) + { + } + }; + + access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::id_type + access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + id (const image_type& i) + { + sqlite::database* db (0); + ODB_POTENTIALLY_UNUSED (db); + + id_type id; + { + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + id, + i.id_value, + i.id_size, + i.id_null); + } + + return id; + } + + bool access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + grow (image_type& i, + bool* t) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (t); + + bool grew (false); + + // id + // + if (t[0UL]) + { + i.id_value.capacity (i.id_size); + grew = true; + } + + // result + // + if (t[1UL]) + { + i.result_value.capacity (i.result_size); + grew = true; + } + + // retryReason + // + if (t[2UL]) + { + i.retryReason_value.capacity (i.retryReason_size); + grew = true; + } + + // governmentSuspensionReason + // + if (t[3UL]) + { + i.governmentSuspensionReason_value.capacity (i.governmentSuspensionReason_size); + grew = true; + } + + // governmentTerminationReason + // + if (t[4UL]) + { + i.governmentTerminationReason_value.capacity (i.governmentTerminationReason_size); + grew = true; + } + + // complianceSuspensionReason + // + if (t[5UL]) + { + i.complianceSuspensionReason_value.capacity (i.complianceSuspensionReason_size); + grew = true; + } + + // complianceTerminationReason + // + if (t[6UL]) + { + i.complianceTerminationReason_value.capacity (i.complianceTerminationReason_size); + grew = true; + } + + // policySuspensionReason + // + if (t[7UL]) + { + i.policySuspensionReason_value.capacity (i.policySuspensionReason_size); + grew = true; + } + + // policyTerminationReason + // + if (t[8UL]) + { + i.policyTerminationReason_value.capacity (i.policyTerminationReason_size); + grew = true; + } + + // cancelationReason + // + if (t[9UL]) + { + i.cancelationReason_value.capacity (i.cancelationReason_size); + grew = true; + } + + // failureReason + // + if (t[10UL]) + { + i.failureReason_value.capacity (i.failureReason_size); + grew = true; + } + + // details + // + if (t[11UL]) + { + i.details_value.capacity (i.details_size); + grew = true; + } + + return grew; + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + bind (sqlite::bind* b, + image_type& i, + sqlite::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (sk); + + using namespace sqlite; + + std::size_t n (0); + + // id + // + if (sk != statement_update) + { + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.id_value.data (); + b[n].size = &i.id_size; + b[n].capacity = i.id_value.capacity (); + b[n].is_null = &i.id_null; + n++; + } + + // result + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.result_value.data (); + b[n].size = &i.result_size; + b[n].capacity = i.result_value.capacity (); + b[n].is_null = &i.result_null; + n++; + + // retryReason + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.retryReason_value.data (); + b[n].size = &i.retryReason_size; + b[n].capacity = i.retryReason_value.capacity (); + b[n].is_null = &i.retryReason_null; + n++; + + // governmentSuspensionReason + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.governmentSuspensionReason_value.data (); + b[n].size = &i.governmentSuspensionReason_size; + b[n].capacity = i.governmentSuspensionReason_value.capacity (); + b[n].is_null = &i.governmentSuspensionReason_null; + n++; + + // governmentTerminationReason + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.governmentTerminationReason_value.data (); + b[n].size = &i.governmentTerminationReason_size; + b[n].capacity = i.governmentTerminationReason_value.capacity (); + b[n].is_null = &i.governmentTerminationReason_null; + n++; + + // complianceSuspensionReason + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.complianceSuspensionReason_value.data (); + b[n].size = &i.complianceSuspensionReason_size; + b[n].capacity = i.complianceSuspensionReason_value.capacity (); + b[n].is_null = &i.complianceSuspensionReason_null; + n++; + + // complianceTerminationReason + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.complianceTerminationReason_value.data (); + b[n].size = &i.complianceTerminationReason_size; + b[n].capacity = i.complianceTerminationReason_value.capacity (); + b[n].is_null = &i.complianceTerminationReason_null; + n++; + + // policySuspensionReason + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.policySuspensionReason_value.data (); + b[n].size = &i.policySuspensionReason_size; + b[n].capacity = i.policySuspensionReason_value.capacity (); + b[n].is_null = &i.policySuspensionReason_null; + n++; + + // policyTerminationReason + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.policyTerminationReason_value.data (); + b[n].size = &i.policyTerminationReason_size; + b[n].capacity = i.policyTerminationReason_value.capacity (); + b[n].is_null = &i.policyTerminationReason_null; + n++; + + // cancelationReason + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.cancelationReason_value.data (); + b[n].size = &i.cancelationReason_size; + b[n].capacity = i.cancelationReason_value.capacity (); + b[n].is_null = &i.cancelationReason_null; + n++; + + // failureReason + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.failureReason_value.data (); + b[n].size = &i.failureReason_size; + b[n].capacity = i.failureReason_value.capacity (); + b[n].is_null = &i.failureReason_null; + n++; + + // details + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.details_value.data (); + b[n].size = &i.details_size; + b[n].capacity = i.details_value.capacity (); + b[n].is_null = &i.details_null; + n++; + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + bind (sqlite::bind* b, id_image_type& i) + { + std::size_t n (0); + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.id_value.data (); + b[n].size = &i.id_size; + b[n].capacity = i.id_value.capacity (); + b[n].is_null = &i.id_null; + } + + bool access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + init (image_type& i, + const object_type& o, + sqlite::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (sk); + + using namespace sqlite; + + bool grew (false); + + // id + // + if (sk == statement_insert) + { + ::std::string const& v = + o.id; + + bool is_null (false); + std::size_t cap (i.id_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.id_value, + i.id_size, + is_null, + v); + i.id_null = is_null; + grew = grew || (cap != i.id_value.capacity ()); + } + + // result + // + { + ::std::string const& v = + o.result; + + bool is_null (false); + std::size_t cap (i.result_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.result_value, + i.result_size, + is_null, + v); + i.result_null = is_null; + grew = grew || (cap != i.result_value.capacity ()); + } + + // retryReason + // + { + ::std::string const& v = + o.retryReason; + + bool is_null (false); + std::size_t cap (i.retryReason_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.retryReason_value, + i.retryReason_size, + is_null, + v); + i.retryReason_null = is_null; + grew = grew || (cap != i.retryReason_value.capacity ()); + } + + // governmentSuspensionReason + // + { + ::std::string const& v = + o.governmentSuspensionReason; + + bool is_null (false); + std::size_t cap (i.governmentSuspensionReason_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.governmentSuspensionReason_value, + i.governmentSuspensionReason_size, + is_null, + v); + i.governmentSuspensionReason_null = is_null; + grew = grew || (cap != i.governmentSuspensionReason_value.capacity ()); + } + + // governmentTerminationReason + // + { + ::std::string const& v = + o.governmentTerminationReason; + + bool is_null (false); + std::size_t cap (i.governmentTerminationReason_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.governmentTerminationReason_value, + i.governmentTerminationReason_size, + is_null, + v); + i.governmentTerminationReason_null = is_null; + grew = grew || (cap != i.governmentTerminationReason_value.capacity ()); + } + + // complianceSuspensionReason + // + { + ::std::string const& v = + o.complianceSuspensionReason; + + bool is_null (false); + std::size_t cap (i.complianceSuspensionReason_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.complianceSuspensionReason_value, + i.complianceSuspensionReason_size, + is_null, + v); + i.complianceSuspensionReason_null = is_null; + grew = grew || (cap != i.complianceSuspensionReason_value.capacity ()); + } + + // complianceTerminationReason + // + { + ::std::string const& v = + o.complianceTerminationReason; + + bool is_null (false); + std::size_t cap (i.complianceTerminationReason_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.complianceTerminationReason_value, + i.complianceTerminationReason_size, + is_null, + v); + i.complianceTerminationReason_null = is_null; + grew = grew || (cap != i.complianceTerminationReason_value.capacity ()); + } + + // policySuspensionReason + // + { + ::std::string const& v = + o.policySuspensionReason; + + bool is_null (false); + std::size_t cap (i.policySuspensionReason_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.policySuspensionReason_value, + i.policySuspensionReason_size, + is_null, + v); + i.policySuspensionReason_null = is_null; + grew = grew || (cap != i.policySuspensionReason_value.capacity ()); + } + + // policyTerminationReason + // + { + ::std::string const& v = + o.policyTerminationReason; + + bool is_null (false); + std::size_t cap (i.policyTerminationReason_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.policyTerminationReason_value, + i.policyTerminationReason_size, + is_null, + v); + i.policyTerminationReason_null = is_null; + grew = grew || (cap != i.policyTerminationReason_value.capacity ()); + } + + // cancelationReason + // + { + ::std::string const& v = + o.cancelationReason; + + bool is_null (false); + std::size_t cap (i.cancelationReason_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.cancelationReason_value, + i.cancelationReason_size, + is_null, + v); + i.cancelationReason_null = is_null; + grew = grew || (cap != i.cancelationReason_value.capacity ()); + } + + // failureReason + // + { + ::std::string const& v = + o.failureReason; + + bool is_null (false); + std::size_t cap (i.failureReason_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.failureReason_value, + i.failureReason_size, + is_null, + v); + i.failureReason_null = is_null; + grew = grew || (cap != i.failureReason_value.capacity ()); + } + + // details + // + { + ::std::string const& v = + o.details; + + bool is_null (false); + std::size_t cap (i.details_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.details_value, + i.details_size, + is_null, + v); + i.details_null = is_null; + grew = grew || (cap != i.details_value.capacity ()); + } + + return grew; + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + init (object_type& o, + const image_type& i, + database* db) + { + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (db); + + // id + // + { + ::std::string& v = + o.id; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.id_value, + i.id_size, + i.id_null); + } + + // result + // + { + ::std::string& v = + o.result; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.result_value, + i.result_size, + i.result_null); + } + + // retryReason + // + { + ::std::string& v = + o.retryReason; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.retryReason_value, + i.retryReason_size, + i.retryReason_null); + } + + // governmentSuspensionReason + // + { + ::std::string& v = + o.governmentSuspensionReason; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.governmentSuspensionReason_value, + i.governmentSuspensionReason_size, + i.governmentSuspensionReason_null); + } + + // governmentTerminationReason + // + { + ::std::string& v = + o.governmentTerminationReason; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.governmentTerminationReason_value, + i.governmentTerminationReason_size, + i.governmentTerminationReason_null); + } + + // complianceSuspensionReason + // + { + ::std::string& v = + o.complianceSuspensionReason; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.complianceSuspensionReason_value, + i.complianceSuspensionReason_size, + i.complianceSuspensionReason_null); + } + + // complianceTerminationReason + // + { + ::std::string& v = + o.complianceTerminationReason; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.complianceTerminationReason_value, + i.complianceTerminationReason_size, + i.complianceTerminationReason_null); + } + + // policySuspensionReason + // + { + ::std::string& v = + o.policySuspensionReason; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.policySuspensionReason_value, + i.policySuspensionReason_size, + i.policySuspensionReason_null); + } + + // policyTerminationReason + // + { + ::std::string& v = + o.policyTerminationReason; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.policyTerminationReason_value, + i.policyTerminationReason_size, + i.policyTerminationReason_null); + } + + // cancelationReason + // + { + ::std::string& v = + o.cancelationReason; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.cancelationReason_value, + i.cancelationReason_size, + i.cancelationReason_null); + } + + // failureReason + // + { + ::std::string& v = + o.failureReason; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.failureReason_value, + i.failureReason_size, + i.failureReason_null); + } + + // details + // + { + ::std::string& v = + o.details; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.details_value, + i.details_size, + i.details_null); + } + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + init (id_image_type& i, const id_type& id) + { + bool grew (false); + { + bool is_null (false); + std::size_t cap (i.id_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.id_value, + i.id_size, + is_null, + id); + i.id_null = is_null; + grew = grew || (cap != i.id_value.capacity ()); + } + + if (grew) + i.version++; + } + + const char access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::persist_statement[] = + "INSERT INTO \"TripAttemptResult\" " + "(\"id\", " + "\"result\", " + "\"retryReason\", " + "\"governmentSuspensionReason\", " + "\"governmentTerminationReason\", " + "\"complianceSuspensionReason\", " + "\"complianceTerminationReason\", " + "\"policySuspensionReason\", " + "\"policyTerminationReason\", " + "\"cancelationReason\", " + "\"failureReason\", " + "\"details\") " + "VALUES " + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::find_statement[] = + "SELECT " + "\"TripAttemptResult\".\"id\", " + "\"TripAttemptResult\".\"result\", " + "\"TripAttemptResult\".\"retryReason\", " + "\"TripAttemptResult\".\"governmentSuspensionReason\", " + "\"TripAttemptResult\".\"governmentTerminationReason\", " + "\"TripAttemptResult\".\"complianceSuspensionReason\", " + "\"TripAttemptResult\".\"complianceTerminationReason\", " + "\"TripAttemptResult\".\"policySuspensionReason\", " + "\"TripAttemptResult\".\"policyTerminationReason\", " + "\"TripAttemptResult\".\"cancelationReason\", " + "\"TripAttemptResult\".\"failureReason\", " + "\"TripAttemptResult\".\"details\" " + "FROM \"TripAttemptResult\" " + "WHERE \"TripAttemptResult\".\"id\"=?"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::update_statement[] = + "UPDATE \"TripAttemptResult\" " + "SET " + "\"result\"=?, " + "\"retryReason\"=?, " + "\"governmentSuspensionReason\"=?, " + "\"governmentTerminationReason\"=?, " + "\"complianceSuspensionReason\"=?, " + "\"complianceTerminationReason\"=?, " + "\"policySuspensionReason\"=?, " + "\"policyTerminationReason\"=?, " + "\"cancelationReason\"=?, " + "\"failureReason\"=?, " + "\"details\"=? " + "WHERE \"id\"=?"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::erase_statement[] = + "DELETE FROM \"TripAttemptResult\" " + "WHERE \"id\"=?"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::query_statement[] = + "SELECT " + "\"TripAttemptResult\".\"id\", " + "\"TripAttemptResult\".\"result\", " + "\"TripAttemptResult\".\"retryReason\", " + "\"TripAttemptResult\".\"governmentSuspensionReason\", " + "\"TripAttemptResult\".\"governmentTerminationReason\", " + "\"TripAttemptResult\".\"complianceSuspensionReason\", " + "\"TripAttemptResult\".\"complianceTerminationReason\", " + "\"TripAttemptResult\".\"policySuspensionReason\", " + "\"TripAttemptResult\".\"policyTerminationReason\", " + "\"TripAttemptResult\".\"cancelationReason\", " + "\"TripAttemptResult\".\"failureReason\", " + "\"TripAttemptResult\".\"details\" " + "FROM \"TripAttemptResult\""; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::erase_query_statement[] = + "DELETE FROM \"TripAttemptResult\""; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::table_name[] = + "\"TripAttemptResult\""; + + void access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + persist (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + callback (db, + obj, + callback_event::pre_persist); + + image_type& im (sts.image ()); + binding& imb (sts.insert_image_binding ()); + + if (init (im, obj, statement_insert)) + im.version++; + + if (im.version != sts.insert_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_insert); + sts.insert_image_version (im.version); + imb.version++; + } + + insert_statement& st (sts.persist_statement ()); + if (!st.execute ()) + throw object_already_persistent (); + + callback (db, + obj, + callback_event::post_persist); + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + update (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace sqlite; + using sqlite::update_statement; + + callback (db, obj, callback_event::pre_update); + + sqlite::transaction& tr (sqlite::transaction::current ()); + sqlite::connection& conn (tr.connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + const id_type& id ( + obj.id); + id_image_type& idi (sts.id_image ()); + init (idi, id); + + image_type& im (sts.image ()); + if (init (im, obj, statement_update)) + im.version++; + + bool u (false); + binding& imb (sts.update_image_binding ()); + if (im.version != sts.update_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_update); + sts.update_image_version (im.version); + imb.version++; + u = true; + } + + binding& idb (sts.id_image_binding ()); + if (idi.version != sts.update_id_image_version () || + idb.version == 0) + { + if (idi.version != sts.id_image_version () || + idb.version == 0) + { + bind (idb.bind, idi); + sts.id_image_version (idi.version); + idb.version++; + } + + sts.update_id_image_version (idi.version); + + if (!u) + imb.version++; + } + + update_statement& st (sts.update_statement ()); + if (st.execute () == 0) + throw object_not_persistent (); + + callback (db, obj, callback_event::post_update); + pointer_cache_traits::update (db, obj); + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + erase (database& db, const id_type& id) + { + using namespace sqlite; + + ODB_POTENTIALLY_UNUSED (db); + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + id_image_type& i (sts.id_image ()); + init (i, id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + if (sts.erase_statement ().execute () != 1) + throw object_not_persistent (); + + pointer_cache_traits::erase (db, id); + } + + access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::pointer_type + access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + find (database& db, const id_type& id) + { + using namespace sqlite; + + { + pointer_type p (pointer_cache_traits::find (db, id)); + + if (!pointer_traits::null_ptr (p)) + return p; + } + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (l.locked ()) + { + if (!find_ (sts, &id)) + return pointer_type (); + } + + pointer_type p ( + access::object_factory::create ()); + pointer_traits::guard pg (p); + + pointer_cache_traits::insert_guard ig ( + pointer_cache_traits::insert (db, id, p)); + + object_type& obj (pointer_traits::get_ref (p)); + + if (l.locked ()) + { + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + pointer_cache_traits::load (ig.position ()); + } + else + sts.delay_load (id, obj, ig.position ()); + + ig.release (); + pg.release (); + return p; + } + + bool access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + find (database& db, const id_type& id, object_type& obj) + { + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + reference_cache_traits::position_type pos ( + reference_cache_traits::insert (db, id, obj)); + reference_cache_traits::insert_guard ig (pos); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + reference_cache_traits::load (pos); + ig.release (); + return true; + } + + bool access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + reload (database& db, object_type& obj) + { + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + const id_type& id ( + obj.id); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, true); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + return true; + } + + bool access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + find_ (statements_type& sts, + const id_type* id) + { + using namespace sqlite; + + id_image_type& i (sts.id_image ()); + init (i, *id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + select_statement& st (sts.find_statement ()); + + st.execute (); + auto_result ar (st); + select_statement::result r (st.fetch ()); + + if (r == select_statement::truncated) + { + if (grow (im, sts.select_image_truncated ())) + im.version++; + + if (im.version != sts.select_image_version ()) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + st.refetch (); + } + } + + return r != select_statement::no_data; + } + + result< access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::object_type > + access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + query (database&, const query_base_type& q) + { + using namespace sqlite; + using odb::details::shared; + using odb::details::shared_ptr; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + + statements_type& sts ( + conn.statement_cache ().find_object ()); + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + std::string text (query_statement); + if (!q.empty ()) + { + text += " "; + text += q.clause (); + } + + q.init_parameters (); + shared_ptr st ( + new (shared) select_statement ( + conn, + text, + false, + true, + q.parameters_binding (), + imb)); + + st->execute (); + + shared_ptr< odb::object_result_impl > r ( + new (shared) sqlite::object_result_impl ( + q, st, sts, 0)); + + return result (r); + } + + unsigned long long access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + erase_query (database&, const query_base_type& q) + { + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + + std::string text (erase_query_statement); + if (!q.empty ()) + { + text += ' '; + text += q.clause (); + } + + q.init_parameters (); + delete_statement st ( + conn, + text, + q.parameters_binding ()); + + return st.execute (); + } +} + +#include diff --git a/db/test-schema-v1.2/generated-odb-source/sqlite/TripAttemptResult-odb.hxx b/db/test-schema-v1.2/generated-odb-source/sqlite/TripAttemptResult-odb.hxx new file mode 100644 index 0000000..e43bfa6 --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/sqlite/TripAttemptResult-odb.hxx @@ -0,0 +1,505 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#ifndef TRIP_ATTEMPT_RESULT_ODB_HXX +#define TRIP_ATTEMPT_RESULT_ODB_HXX + +#include + +#if (ODB_VERSION != 20400UL) +#error ODB runtime version mismatch +#endif + +#include + +#include "TripAttemptResult.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace odb +{ + // TripAttemptResult + // + template <> + struct class_traits< ::models::TripAttemptResult > + { + static const class_kind kind = class_object; + }; + + template <> + class access::object_traits< ::models::TripAttemptResult > + { + public: + typedef ::models::TripAttemptResult object_type; + typedef ::models::TripAttemptResult* pointer_type; + typedef odb::pointer_traits pointer_traits; + + static const bool polymorphic = false; + + typedef ::std::string id_type; + + static const bool auto_id = false; + + static const bool abstract = false; + + static id_type + id (const object_type&); + + typedef + no_op_pointer_cache_traits + pointer_cache_traits; + + typedef + no_op_reference_cache_traits + reference_cache_traits; + + static void + callback (database&, object_type&, callback_event); + + static void + callback (database&, const object_type&, callback_event); + }; +} + +#include + +#include +#include +#include +#include +#include + +namespace odb +{ + // TripAttemptResult + // + template + struct query_columns< ::models::TripAttemptResult, id_sqlite, A > + { + // id + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + id_type_; + + static const id_type_ id; + + // result + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + result_type_; + + static const result_type_ result; + + // retryReason + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + retryReason_type_; + + static const retryReason_type_ retryReason; + + // governmentSuspensionReason + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + governmentSuspensionReason_type_; + + static const governmentSuspensionReason_type_ governmentSuspensionReason; + + // governmentTerminationReason + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + governmentTerminationReason_type_; + + static const governmentTerminationReason_type_ governmentTerminationReason; + + // complianceSuspensionReason + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + complianceSuspensionReason_type_; + + static const complianceSuspensionReason_type_ complianceSuspensionReason; + + // complianceTerminationReason + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + complianceTerminationReason_type_; + + static const complianceTerminationReason_type_ complianceTerminationReason; + + // policySuspensionReason + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + policySuspensionReason_type_; + + static const policySuspensionReason_type_ policySuspensionReason; + + // policyTerminationReason + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + policyTerminationReason_type_; + + static const policyTerminationReason_type_ policyTerminationReason; + + // cancelationReason + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + cancelationReason_type_; + + static const cancelationReason_type_ cancelationReason; + + // failureReason + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + failureReason_type_; + + static const failureReason_type_ failureReason; + + // details + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + details_type_; + + static const details_type_ details; + }; + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::id_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + id (A::table_name, "\"id\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::result_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + result (A::table_name, "\"result\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::retryReason_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + retryReason (A::table_name, "\"retryReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::governmentSuspensionReason_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + governmentSuspensionReason (A::table_name, "\"governmentSuspensionReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::governmentTerminationReason_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + governmentTerminationReason (A::table_name, "\"governmentTerminationReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::complianceSuspensionReason_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + complianceSuspensionReason (A::table_name, "\"complianceSuspensionReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::complianceTerminationReason_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + complianceTerminationReason (A::table_name, "\"complianceTerminationReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::policySuspensionReason_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + policySuspensionReason (A::table_name, "\"policySuspensionReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::policyTerminationReason_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + policyTerminationReason (A::table_name, "\"policyTerminationReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::cancelationReason_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + cancelationReason (A::table_name, "\"cancelationReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::failureReason_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + failureReason (A::table_name, "\"failureReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::details_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + details (A::table_name, "\"details\"", 0); + + template + struct pointer_query_columns< ::models::TripAttemptResult, id_sqlite, A >: + query_columns< ::models::TripAttemptResult, id_sqlite, A > + { + }; + + template <> + class access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >: + public access::object_traits< ::models::TripAttemptResult > + { + public: + struct id_image_type + { + details::buffer id_value; + std::size_t id_size; + bool id_null; + + std::size_t version; + }; + + struct image_type + { + // id + // + details::buffer id_value; + std::size_t id_size; + bool id_null; + + // result + // + details::buffer result_value; + std::size_t result_size; + bool result_null; + + // retryReason + // + details::buffer retryReason_value; + std::size_t retryReason_size; + bool retryReason_null; + + // governmentSuspensionReason + // + details::buffer governmentSuspensionReason_value; + std::size_t governmentSuspensionReason_size; + bool governmentSuspensionReason_null; + + // governmentTerminationReason + // + details::buffer governmentTerminationReason_value; + std::size_t governmentTerminationReason_size; + bool governmentTerminationReason_null; + + // complianceSuspensionReason + // + details::buffer complianceSuspensionReason_value; + std::size_t complianceSuspensionReason_size; + bool complianceSuspensionReason_null; + + // complianceTerminationReason + // + details::buffer complianceTerminationReason_value; + std::size_t complianceTerminationReason_size; + bool complianceTerminationReason_null; + + // policySuspensionReason + // + details::buffer policySuspensionReason_value; + std::size_t policySuspensionReason_size; + bool policySuspensionReason_null; + + // policyTerminationReason + // + details::buffer policyTerminationReason_value; + std::size_t policyTerminationReason_size; + bool policyTerminationReason_null; + + // cancelationReason + // + details::buffer cancelationReason_value; + std::size_t cancelationReason_size; + bool cancelationReason_null; + + // failureReason + // + details::buffer failureReason_value; + std::size_t failureReason_size; + bool failureReason_null; + + // details + // + details::buffer details_value; + std::size_t details_size; + bool details_null; + + std::size_t version; + }; + + struct extra_statement_cache_type; + + using object_traits::id; + + static id_type + id (const image_type&); + + static bool + grow (image_type&, + bool*); + + static void + bind (sqlite::bind*, + image_type&, + sqlite::statement_kind); + + static void + bind (sqlite::bind*, id_image_type&); + + static bool + init (image_type&, + const object_type&, + sqlite::statement_kind); + + static void + init (object_type&, + const image_type&, + database*); + + static void + init (id_image_type&, const id_type&); + + typedef sqlite::object_statements statements_type; + + typedef sqlite::query_base query_base_type; + + static const std::size_t column_count = 12UL; + static const std::size_t id_column_count = 1UL; + static const std::size_t inverse_column_count = 0UL; + static const std::size_t readonly_column_count = 0UL; + static const std::size_t managed_optimistic_column_count = 0UL; + + static const std::size_t separate_load_column_count = 0UL; + static const std::size_t separate_update_column_count = 0UL; + + static const bool versioned = false; + + static const char persist_statement[]; + static const char find_statement[]; + static const char update_statement[]; + static const char erase_statement[]; + static const char query_statement[]; + static const char erase_query_statement[]; + + static const char table_name[]; + + static void + persist (database&, const object_type&); + + static pointer_type + find (database&, const id_type&); + + static bool + find (database&, const id_type&, object_type&); + + static bool + reload (database&, object_type&); + + static void + update (database&, const object_type&); + + static void + erase (database&, const id_type&); + + static void + erase (database&, const object_type&); + + static result + query (database&, const query_base_type&); + + static unsigned long long + erase_query (database&, const query_base_type&); + + public: + static bool + find_ (statements_type&, + const id_type*); + + static void + load_ (statements_type&, + object_type&, + bool reload); + }; + + template <> + class access::object_traits_impl< ::models::TripAttemptResult, id_common >: + public access::object_traits_impl< ::models::TripAttemptResult, id_sqlite > + { + }; + + // TripAttemptResult + // +} + +#include "TripAttemptResult-odb.ixx" + +#include + +#endif // TRIP_ATTEMPT_RESULT_ODB_HXX diff --git a/db/test-schema-v1.2/generated-odb-source/sqlite/TripAttemptResult-odb.ixx b/db/test-schema-v1.2/generated-odb-source/sqlite/TripAttemptResult-odb.ixx new file mode 100644 index 0000000..ac500cc --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/sqlite/TripAttemptResult-odb.ixx @@ -0,0 +1,61 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +namespace odb +{ + // TripAttemptResult + // + + inline + access::object_traits< ::models::TripAttemptResult >::id_type + access::object_traits< ::models::TripAttemptResult >:: + id (const object_type& o) + { + return o.id; + } + + inline + void access::object_traits< ::models::TripAttemptResult >:: + callback (database& db, object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } + + inline + void access::object_traits< ::models::TripAttemptResult >:: + callback (database& db, const object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } +} + +namespace odb +{ + // TripAttemptResult + // + + inline + void access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + erase (database& db, const object_type& obj) + { + callback (db, obj, callback_event::pre_erase); + erase (db, id (obj)); + callback (db, obj, callback_event::post_erase); + } + + inline + void access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + load_ (statements_type& sts, + object_type& obj, + bool) + { + ODB_POTENTIALLY_UNUSED (sts); + ODB_POTENTIALLY_UNUSED (obj); + } +} + diff --git a/db/test-schema-v1.2/generated-odb-source/sqlite/TripAttemptResult.xml b/db/test-schema-v1.2/generated-odb-source/sqlite/TripAttemptResult.xml new file mode 100644 index 0000000..ad5336b --- /dev/null +++ b/db/test-schema-v1.2/generated-odb-source/sqlite/TripAttemptResult.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/db/test-schema-v1.2/generated-sql-ddl/postgre/Agent-002-post.sql b/db/test-schema-v1.2/generated-sql-ddl/postgre/Agent-002-post.sql new file mode 100644 index 0000000..2424f4d --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/postgre/Agent-002-post.sql @@ -0,0 +1,8 @@ +/* This file was generated by ODB, object-relational mapping (ORM) + * compiler for C++. + */ + +UPDATE "schema_version" + SET "migration" = FALSE + WHERE "name" = ''; + diff --git a/db/test-schema-v1.2/generated-sql-ddl/postgre/Agent-002-pre.sql b/db/test-schema-v1.2/generated-sql-ddl/postgre/Agent-002-pre.sql new file mode 100644 index 0000000..4919b84 --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/postgre/Agent-002-pre.sql @@ -0,0 +1,15 @@ +/* This file was generated by ODB, object-relational mapping (ORM) + * compiler for C++. + */ + +CREATE TABLE "Agent" ( + "id" TEXT NOT NULL PRIMARY KEY, + "role" TEXT NOT NULL, + "persistent" BOOLEAN NOT NULL, + "displayName" TEXT NOT NULL, + "trustScore" INTEGER NOT NULL); + +UPDATE "schema_version" + SET "version" = 2, "migration" = TRUE + WHERE "name" = ''; + diff --git a/db/test-schema-v1.2/generated-sql-ddl/postgre/Agent-odb.cxx b/db/test-schema-v1.2/generated-sql-ddl/postgre/Agent-odb.cxx new file mode 100644 index 0000000..904486b --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/postgre/Agent-odb.cxx @@ -0,0 +1,864 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#include + +#include "Agent-odb.hxx" + +#include +#include // std::memcpy + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace odb +{ + // Agent + // + + const char access::object_traits_impl< ::models::Agent, id_pgsql >:: + persist_statement_name[] = "persist_models_Agent"; + + const char access::object_traits_impl< ::models::Agent, id_pgsql >:: + find_statement_name[] = "find_models_Agent"; + + const char access::object_traits_impl< ::models::Agent, id_pgsql >:: + update_statement_name[] = "update_models_Agent"; + + const char access::object_traits_impl< ::models::Agent, id_pgsql >:: + erase_statement_name[] = "erase_models_Agent"; + + const char access::object_traits_impl< ::models::Agent, id_pgsql >:: + query_statement_name[] = "query_models_Agent"; + + const char access::object_traits_impl< ::models::Agent, id_pgsql >:: + erase_query_statement_name[] = "erase_query_models_Agent"; + + const unsigned int access::object_traits_impl< ::models::Agent, id_pgsql >:: + persist_statement_types[] = + { + pgsql::text_oid, + pgsql::text_oid, + pgsql::bool_oid, + pgsql::text_oid, + pgsql::int4_oid + }; + + const unsigned int access::object_traits_impl< ::models::Agent, id_pgsql >:: + find_statement_types[] = + { + pgsql::text_oid + }; + + const unsigned int access::object_traits_impl< ::models::Agent, id_pgsql >:: + update_statement_types[] = + { + pgsql::text_oid, + pgsql::bool_oid, + pgsql::text_oid, + pgsql::int4_oid, + pgsql::text_oid + }; + + struct access::object_traits_impl< ::models::Agent, id_pgsql >::extra_statement_cache_type + { + extra_statement_cache_type ( + pgsql::connection&, + image_type&, + id_image_type&, + pgsql::binding&, + pgsql::binding&, + pgsql::native_binding&, + const unsigned int*) + { + } + }; + + access::object_traits_impl< ::models::Agent, id_pgsql >::id_type + access::object_traits_impl< ::models::Agent, id_pgsql >:: + id (const image_type& i) + { + pgsql::database* db (0); + ODB_POTENTIALLY_UNUSED (db); + + id_type id; + { + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + id, + i.id_value, + i.id_size, + i.id_null); + } + + return id; + } + + bool access::object_traits_impl< ::models::Agent, id_pgsql >:: + grow (image_type& i, + bool* t) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (t); + + bool grew (false); + + // id + // + if (t[0UL]) + { + i.id_value.capacity (i.id_size); + grew = true; + } + + // role + // + if (t[1UL]) + { + i.role_value.capacity (i.role_size); + grew = true; + } + + // persistent + // + t[2UL] = 0; + + // displayName + // + if (t[3UL]) + { + i.displayName_value.capacity (i.displayName_size); + grew = true; + } + + // trustScore + // + t[4UL] = 0; + + return grew; + } + + void access::object_traits_impl< ::models::Agent, id_pgsql >:: + bind (pgsql::bind* b, + image_type& i, + pgsql::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (sk); + + using namespace pgsql; + + std::size_t n (0); + + // id + // + if (sk != statement_update) + { + b[n].type = pgsql::bind::text; + b[n].buffer = i.id_value.data (); + b[n].capacity = i.id_value.capacity (); + b[n].size = &i.id_size; + b[n].is_null = &i.id_null; + n++; + } + + // role + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.role_value.data (); + b[n].capacity = i.role_value.capacity (); + b[n].size = &i.role_size; + b[n].is_null = &i.role_null; + n++; + + // persistent + // + b[n].type = pgsql::bind::boolean_; + b[n].buffer = &i.persistent_value; + b[n].is_null = &i.persistent_null; + n++; + + // displayName + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.displayName_value.data (); + b[n].capacity = i.displayName_value.capacity (); + b[n].size = &i.displayName_size; + b[n].is_null = &i.displayName_null; + n++; + + // trustScore + // + b[n].type = pgsql::bind::integer; + b[n].buffer = &i.trustScore_value; + b[n].is_null = &i.trustScore_null; + n++; + } + + void access::object_traits_impl< ::models::Agent, id_pgsql >:: + bind (pgsql::bind* b, id_image_type& i) + { + std::size_t n (0); + b[n].type = pgsql::bind::text; + b[n].buffer = i.id_value.data (); + b[n].capacity = i.id_value.capacity (); + b[n].size = &i.id_size; + b[n].is_null = &i.id_null; + } + + bool access::object_traits_impl< ::models::Agent, id_pgsql >:: + init (image_type& i, + const object_type& o, + pgsql::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (sk); + + using namespace pgsql; + + bool grew (false); + + // id + // + if (sk == statement_insert) + { + ::std::string const& v = + o.id; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.id_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.id_value, + size, + is_null, + v); + i.id_null = is_null; + i.id_size = size; + grew = grew || (cap != i.id_value.capacity ()); + } + + // role + // + { + ::std::string const& v = + o.role; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.role_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.role_value, + size, + is_null, + v); + i.role_null = is_null; + i.role_size = size; + grew = grew || (cap != i.role_value.capacity ()); + } + + // persistent + // + { + bool const& v = + o.persistent; + + bool is_null (false); + pgsql::value_traits< + bool, + pgsql::id_boolean >::set_image ( + i.persistent_value, is_null, v); + i.persistent_null = is_null; + } + + // displayName + // + { + ::std::string const& v = + o.displayName; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.displayName_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.displayName_value, + size, + is_null, + v); + i.displayName_null = is_null; + i.displayName_size = size; + grew = grew || (cap != i.displayName_value.capacity ()); + } + + // trustScore + // + { + ::int32_t const& v = + o.trustScore; + + bool is_null (false); + pgsql::value_traits< + ::int32_t, + pgsql::id_integer >::set_image ( + i.trustScore_value, is_null, v); + i.trustScore_null = is_null; + } + + return grew; + } + + void access::object_traits_impl< ::models::Agent, id_pgsql >:: + init (object_type& o, + const image_type& i, + database* db) + { + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (db); + + // id + // + { + ::std::string& v = + o.id; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.id_value, + i.id_size, + i.id_null); + } + + // role + // + { + ::std::string& v = + o.role; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.role_value, + i.role_size, + i.role_null); + } + + // persistent + // + { + bool& v = + o.persistent; + + pgsql::value_traits< + bool, + pgsql::id_boolean >::set_value ( + v, + i.persistent_value, + i.persistent_null); + } + + // displayName + // + { + ::std::string& v = + o.displayName; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.displayName_value, + i.displayName_size, + i.displayName_null); + } + + // trustScore + // + { + ::int32_t& v = + o.trustScore; + + pgsql::value_traits< + ::int32_t, + pgsql::id_integer >::set_value ( + v, + i.trustScore_value, + i.trustScore_null); + } + } + + void access::object_traits_impl< ::models::Agent, id_pgsql >:: + init (id_image_type& i, const id_type& id) + { + bool grew (false); + { + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.id_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.id_value, + size, + is_null, + id); + i.id_null = is_null; + i.id_size = size; + grew = grew || (cap != i.id_value.capacity ()); + } + + if (grew) + i.version++; + } + + const char access::object_traits_impl< ::models::Agent, id_pgsql >::persist_statement[] = + "INSERT INTO \"Agent\" " + "(\"id\", " + "\"role\", " + "\"persistent\", " + "\"displayName\", " + "\"trustScore\") " + "VALUES " + "($1, $2, $3, $4, $5)"; + + const char access::object_traits_impl< ::models::Agent, id_pgsql >::find_statement[] = + "SELECT " + "\"Agent\".\"id\", " + "\"Agent\".\"role\", " + "\"Agent\".\"persistent\", " + "\"Agent\".\"displayName\", " + "\"Agent\".\"trustScore\" " + "FROM \"Agent\" " + "WHERE \"Agent\".\"id\"=$1"; + + const char access::object_traits_impl< ::models::Agent, id_pgsql >::update_statement[] = + "UPDATE \"Agent\" " + "SET " + "\"role\"=$1, " + "\"persistent\"=$2, " + "\"displayName\"=$3, " + "\"trustScore\"=$4 " + "WHERE \"id\"=$5"; + + const char access::object_traits_impl< ::models::Agent, id_pgsql >::erase_statement[] = + "DELETE FROM \"Agent\" " + "WHERE \"id\"=$1"; + + const char access::object_traits_impl< ::models::Agent, id_pgsql >::query_statement[] = + "SELECT " + "\"Agent\".\"id\", " + "\"Agent\".\"role\", " + "\"Agent\".\"persistent\", " + "\"Agent\".\"displayName\", " + "\"Agent\".\"trustScore\" " + "FROM \"Agent\""; + + const char access::object_traits_impl< ::models::Agent, id_pgsql >::erase_query_statement[] = + "DELETE FROM \"Agent\""; + + const char access::object_traits_impl< ::models::Agent, id_pgsql >::table_name[] = + "\"Agent\""; + + void access::object_traits_impl< ::models::Agent, id_pgsql >:: + persist (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + callback (db, + obj, + callback_event::pre_persist); + + image_type& im (sts.image ()); + binding& imb (sts.insert_image_binding ()); + + if (init (im, obj, statement_insert)) + im.version++; + + if (im.version != sts.insert_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_insert); + sts.insert_image_version (im.version); + imb.version++; + } + + insert_statement& st (sts.persist_statement ()); + if (!st.execute ()) + throw object_already_persistent (); + + callback (db, + obj, + callback_event::post_persist); + } + + void access::object_traits_impl< ::models::Agent, id_pgsql >:: + update (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace pgsql; + using pgsql::update_statement; + + callback (db, obj, callback_event::pre_update); + + pgsql::transaction& tr (pgsql::transaction::current ()); + pgsql::connection& conn (tr.connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + const id_type& id ( + obj.id); + id_image_type& idi (sts.id_image ()); + init (idi, id); + + image_type& im (sts.image ()); + if (init (im, obj, statement_update)) + im.version++; + + bool u (false); + binding& imb (sts.update_image_binding ()); + if (im.version != sts.update_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_update); + sts.update_image_version (im.version); + imb.version++; + u = true; + } + + binding& idb (sts.id_image_binding ()); + if (idi.version != sts.update_id_image_version () || + idb.version == 0) + { + if (idi.version != sts.id_image_version () || + idb.version == 0) + { + bind (idb.bind, idi); + sts.id_image_version (idi.version); + idb.version++; + } + + sts.update_id_image_version (idi.version); + + if (!u) + imb.version++; + } + + update_statement& st (sts.update_statement ()); + if (st.execute () == 0) + throw object_not_persistent (); + + callback (db, obj, callback_event::post_update); + pointer_cache_traits::update (db, obj); + } + + void access::object_traits_impl< ::models::Agent, id_pgsql >:: + erase (database& db, const id_type& id) + { + using namespace pgsql; + + ODB_POTENTIALLY_UNUSED (db); + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + id_image_type& i (sts.id_image ()); + init (i, id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + if (sts.erase_statement ().execute () != 1) + throw object_not_persistent (); + + pointer_cache_traits::erase (db, id); + } + + access::object_traits_impl< ::models::Agent, id_pgsql >::pointer_type + access::object_traits_impl< ::models::Agent, id_pgsql >:: + find (database& db, const id_type& id) + { + using namespace pgsql; + + { + pointer_type p (pointer_cache_traits::find (db, id)); + + if (!pointer_traits::null_ptr (p)) + return p; + } + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (l.locked ()) + { + if (!find_ (sts, &id)) + return pointer_type (); + } + + pointer_type p ( + access::object_factory::create ()); + pointer_traits::guard pg (p); + + pointer_cache_traits::insert_guard ig ( + pointer_cache_traits::insert (db, id, p)); + + object_type& obj (pointer_traits::get_ref (p)); + + if (l.locked ()) + { + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + pointer_cache_traits::load (ig.position ()); + } + else + sts.delay_load (id, obj, ig.position ()); + + ig.release (); + pg.release (); + return p; + } + + bool access::object_traits_impl< ::models::Agent, id_pgsql >:: + find (database& db, const id_type& id, object_type& obj) + { + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + reference_cache_traits::position_type pos ( + reference_cache_traits::insert (db, id, obj)); + reference_cache_traits::insert_guard ig (pos); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + reference_cache_traits::load (pos); + ig.release (); + return true; + } + + bool access::object_traits_impl< ::models::Agent, id_pgsql >:: + reload (database& db, object_type& obj) + { + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + const id_type& id ( + obj.id); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, true); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + return true; + } + + bool access::object_traits_impl< ::models::Agent, id_pgsql >:: + find_ (statements_type& sts, + const id_type* id) + { + using namespace pgsql; + + id_image_type& i (sts.id_image ()); + init (i, *id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + select_statement& st (sts.find_statement ()); + + st.execute (); + auto_result ar (st); + select_statement::result r (st.fetch ()); + + if (r == select_statement::truncated) + { + if (grow (im, sts.select_image_truncated ())) + im.version++; + + if (im.version != sts.select_image_version ()) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + st.refetch (); + } + } + + return r != select_statement::no_data; + } + + result< access::object_traits_impl< ::models::Agent, id_pgsql >::object_type > + access::object_traits_impl< ::models::Agent, id_pgsql >:: + query (database&, const query_base_type& q) + { + using namespace pgsql; + using odb::details::shared; + using odb::details::shared_ptr; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + + statements_type& sts ( + conn.statement_cache ().find_object ()); + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + std::string text (query_statement); + if (!q.empty ()) + { + text += " "; + text += q.clause (); + } + + q.init_parameters (); + shared_ptr st ( + new (shared) select_statement ( + sts.connection (), + query_statement_name, + text, + false, + true, + q.parameter_types (), + q.parameter_count (), + q.parameters_binding (), + imb)); + + st->execute (); + st->deallocate (); + + shared_ptr< odb::object_result_impl > r ( + new (shared) pgsql::object_result_impl ( + q, st, sts, 0)); + + return result (r); + } + + unsigned long long access::object_traits_impl< ::models::Agent, id_pgsql >:: + erase_query (database&, const query_base_type& q) + { + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + + std::string text (erase_query_statement); + if (!q.empty ()) + { + text += ' '; + text += q.clause (); + } + + q.init_parameters (); + delete_statement st ( + conn, + erase_query_statement_name, + text, + q.parameter_types (), + q.parameter_count (), + q.parameters_binding ()); + + return st.execute (); + } +} + +#include diff --git a/db/test-schema-v1.2/generated-sql-ddl/postgre/Agent-odb.hxx b/db/test-schema-v1.2/generated-sql-ddl/postgre/Agent-odb.hxx new file mode 100644 index 0000000..fa096c2 --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/postgre/Agent-odb.hxx @@ -0,0 +1,353 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#ifndef AGENT_ODB_HXX +#define AGENT_ODB_HXX + +#include + +#if (ODB_VERSION != 20400UL) +#error ODB runtime version mismatch +#endif + +#include + +#include "Agent.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace odb +{ + // Agent + // + template <> + struct class_traits< ::models::Agent > + { + static const class_kind kind = class_object; + }; + + template <> + class access::object_traits< ::models::Agent > + { + public: + typedef ::models::Agent object_type; + typedef ::models::Agent* pointer_type; + typedef odb::pointer_traits pointer_traits; + + static const bool polymorphic = false; + + typedef ::std::string id_type; + + static const bool auto_id = false; + + static const bool abstract = false; + + static id_type + id (const object_type&); + + typedef + no_op_pointer_cache_traits + pointer_cache_traits; + + typedef + no_op_reference_cache_traits + reference_cache_traits; + + static void + callback (database&, object_type&, callback_event); + + static void + callback (database&, const object_type&, callback_event); + }; +} + +#include + +#include +#include +#include +#include +#include + +namespace odb +{ + // Agent + // + template + struct query_columns< ::models::Agent, id_pgsql, A > + { + // id + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + id_type_; + + static const id_type_ id; + + // role + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + role_type_; + + static const role_type_ role; + + // persistent + // + typedef + pgsql::query_column< + pgsql::value_traits< + bool, + pgsql::id_boolean >::query_type, + pgsql::id_boolean > + persistent_type_; + + static const persistent_type_ persistent; + + // displayName + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + displayName_type_; + + static const displayName_type_ displayName; + + // trustScore + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::int32_t, + pgsql::id_integer >::query_type, + pgsql::id_integer > + trustScore_type_; + + static const trustScore_type_ trustScore; + }; + + template + const typename query_columns< ::models::Agent, id_pgsql, A >::id_type_ + query_columns< ::models::Agent, id_pgsql, A >:: + id (A::table_name, "\"id\"", 0); + + template + const typename query_columns< ::models::Agent, id_pgsql, A >::role_type_ + query_columns< ::models::Agent, id_pgsql, A >:: + role (A::table_name, "\"role\"", 0); + + template + const typename query_columns< ::models::Agent, id_pgsql, A >::persistent_type_ + query_columns< ::models::Agent, id_pgsql, A >:: + persistent (A::table_name, "\"persistent\"", 0); + + template + const typename query_columns< ::models::Agent, id_pgsql, A >::displayName_type_ + query_columns< ::models::Agent, id_pgsql, A >:: + displayName (A::table_name, "\"displayName\"", 0); + + template + const typename query_columns< ::models::Agent, id_pgsql, A >::trustScore_type_ + query_columns< ::models::Agent, id_pgsql, A >:: + trustScore (A::table_name, "\"trustScore\"", 0); + + template + struct pointer_query_columns< ::models::Agent, id_pgsql, A >: + query_columns< ::models::Agent, id_pgsql, A > + { + }; + + template <> + class access::object_traits_impl< ::models::Agent, id_pgsql >: + public access::object_traits< ::models::Agent > + { + public: + struct id_image_type + { + details::buffer id_value; + std::size_t id_size; + bool id_null; + + std::size_t version; + }; + + struct image_type + { + // id + // + details::buffer id_value; + std::size_t id_size; + bool id_null; + + // role + // + details::buffer role_value; + std::size_t role_size; + bool role_null; + + // persistent + // + bool persistent_value; + bool persistent_null; + + // displayName + // + details::buffer displayName_value; + std::size_t displayName_size; + bool displayName_null; + + // trustScore + // + int trustScore_value; + bool trustScore_null; + + std::size_t version; + }; + + struct extra_statement_cache_type; + + using object_traits::id; + + static id_type + id (const image_type&); + + static bool + grow (image_type&, + bool*); + + static void + bind (pgsql::bind*, + image_type&, + pgsql::statement_kind); + + static void + bind (pgsql::bind*, id_image_type&); + + static bool + init (image_type&, + const object_type&, + pgsql::statement_kind); + + static void + init (object_type&, + const image_type&, + database*); + + static void + init (id_image_type&, const id_type&); + + typedef pgsql::object_statements statements_type; + + typedef pgsql::query_base query_base_type; + + static const std::size_t column_count = 5UL; + static const std::size_t id_column_count = 1UL; + static const std::size_t inverse_column_count = 0UL; + static const std::size_t readonly_column_count = 0UL; + static const std::size_t managed_optimistic_column_count = 0UL; + + static const std::size_t separate_load_column_count = 0UL; + static const std::size_t separate_update_column_count = 0UL; + + static const bool versioned = false; + + static const char persist_statement[]; + static const char find_statement[]; + static const char update_statement[]; + static const char erase_statement[]; + static const char query_statement[]; + static const char erase_query_statement[]; + + static const char table_name[]; + + static void + persist (database&, const object_type&); + + static pointer_type + find (database&, const id_type&); + + static bool + find (database&, const id_type&, object_type&); + + static bool + reload (database&, object_type&); + + static void + update (database&, const object_type&); + + static void + erase (database&, const id_type&); + + static void + erase (database&, const object_type&); + + static result + query (database&, const query_base_type&); + + static unsigned long long + erase_query (database&, const query_base_type&); + + static const char persist_statement_name[]; + static const char find_statement_name[]; + static const char update_statement_name[]; + static const char erase_statement_name[]; + static const char query_statement_name[]; + static const char erase_query_statement_name[]; + + static const unsigned int persist_statement_types[]; + static const unsigned int find_statement_types[]; + static const unsigned int update_statement_types[]; + + public: + static bool + find_ (statements_type&, + const id_type*); + + static void + load_ (statements_type&, + object_type&, + bool reload); + }; + + template <> + class access::object_traits_impl< ::models::Agent, id_common >: + public access::object_traits_impl< ::models::Agent, id_pgsql > + { + }; + + // Agent + // +} + +#include "Agent-odb.ixx" + +#include + +#endif // AGENT_ODB_HXX diff --git a/db/test-schema-v1.2/generated-sql-ddl/postgre/Agent-odb.ixx b/db/test-schema-v1.2/generated-sql-ddl/postgre/Agent-odb.ixx new file mode 100644 index 0000000..437858b --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/postgre/Agent-odb.ixx @@ -0,0 +1,61 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +namespace odb +{ + // Agent + // + + inline + access::object_traits< ::models::Agent >::id_type + access::object_traits< ::models::Agent >:: + id (const object_type& o) + { + return o.id; + } + + inline + void access::object_traits< ::models::Agent >:: + callback (database& db, object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } + + inline + void access::object_traits< ::models::Agent >:: + callback (database& db, const object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } +} + +namespace odb +{ + // Agent + // + + inline + void access::object_traits_impl< ::models::Agent, id_pgsql >:: + erase (database& db, const object_type& obj) + { + callback (db, obj, callback_event::pre_erase); + erase (db, id (obj)); + callback (db, obj, callback_event::post_erase); + } + + inline + void access::object_traits_impl< ::models::Agent, id_pgsql >:: + load_ (statements_type& sts, + object_type& obj, + bool) + { + ODB_POTENTIALLY_UNUSED (sts); + ODB_POTENTIALLY_UNUSED (obj); + } +} + diff --git a/db/test-schema-v1.2/generated-sql-ddl/postgre/Agent.sql b/db/test-schema-v1.2/generated-sql-ddl/postgre/Agent.sql new file mode 100644 index 0000000..287943d --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/postgre/Agent.sql @@ -0,0 +1,24 @@ +/* This file was generated by ODB, object-relational mapping (ORM) + * compiler for C++. + */ + +DROP TABLE IF EXISTS "Agent" CASCADE; + +DROP TABLE IF EXISTS "schema_version"; + +CREATE TABLE "Agent" ( + "id" TEXT NOT NULL PRIMARY KEY, + "role" TEXT NOT NULL, + "persistent" BOOLEAN NOT NULL, + "displayName" TEXT NOT NULL, + "trustScore" INTEGER NOT NULL); + +CREATE TABLE "schema_version" ( + "name" TEXT NOT NULL PRIMARY KEY, + "version" BIGINT NOT NULL, + "migration" BOOLEAN NOT NULL); + +INSERT INTO "schema_version" ( + "name", "version", "migration") + VALUES ('', 2, FALSE); + diff --git a/db/test-schema-v1.2/generated-sql-ddl/postgre/GovernmentAddress-002-post.sql b/db/test-schema-v1.2/generated-sql-ddl/postgre/GovernmentAddress-002-post.sql new file mode 100644 index 0000000..2424f4d --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/postgre/GovernmentAddress-002-post.sql @@ -0,0 +1,8 @@ +/* This file was generated by ODB, object-relational mapping (ORM) + * compiler for C++. + */ + +UPDATE "schema_version" + SET "migration" = FALSE + WHERE "name" = ''; + diff --git a/db/test-schema-v1.2/generated-sql-ddl/postgre/GovernmentAddress-002-pre.sql b/db/test-schema-v1.2/generated-sql-ddl/postgre/GovernmentAddress-002-pre.sql new file mode 100644 index 0000000..209b6e2 --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/postgre/GovernmentAddress-002-pre.sql @@ -0,0 +1,13 @@ +/* This file was generated by ODB, object-relational mapping (ORM) + * compiler for C++. + */ + +CREATE TABLE "GovernmentAddress" ( + "id" TEXT NOT NULL PRIMARY KEY, + "addressLabel" TEXT NOT NULL, + "regionLookupKey" TEXT NOT NULL); + +UPDATE "schema_version" + SET "version" = 2, "migration" = TRUE + WHERE "name" = ''; + diff --git a/db/test-schema-v1.2/generated-sql-ddl/postgre/GovernmentAddress-odb.cxx b/db/test-schema-v1.2/generated-sql-ddl/postgre/GovernmentAddress-odb.cxx new file mode 100644 index 0000000..b04f6f8 --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/postgre/GovernmentAddress-odb.cxx @@ -0,0 +1,774 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#include + +#include "GovernmentAddress-odb.hxx" + +#include +#include // std::memcpy + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace odb +{ + // GovernmentAddress + // + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + persist_statement_name[] = "persist_models_GovernmentAddress"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + find_statement_name[] = "find_models_GovernmentAddress"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + update_statement_name[] = "update_models_GovernmentAddress"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + erase_statement_name[] = "erase_models_GovernmentAddress"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + query_statement_name[] = "query_models_GovernmentAddress"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + erase_query_statement_name[] = "erase_query_models_GovernmentAddress"; + + const unsigned int access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + persist_statement_types[] = + { + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid + }; + + const unsigned int access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + find_statement_types[] = + { + pgsql::text_oid + }; + + const unsigned int access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + update_statement_types[] = + { + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid + }; + + struct access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::extra_statement_cache_type + { + extra_statement_cache_type ( + pgsql::connection&, + image_type&, + id_image_type&, + pgsql::binding&, + pgsql::binding&, + pgsql::native_binding&, + const unsigned int*) + { + } + }; + + access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::id_type + access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + id (const image_type& i) + { + pgsql::database* db (0); + ODB_POTENTIALLY_UNUSED (db); + + id_type id; + { + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + id, + i.id_value, + i.id_size, + i.id_null); + } + + return id; + } + + bool access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + grow (image_type& i, + bool* t) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (t); + + bool grew (false); + + // id + // + if (t[0UL]) + { + i.id_value.capacity (i.id_size); + grew = true; + } + + // addressLabel + // + if (t[1UL]) + { + i.addressLabel_value.capacity (i.addressLabel_size); + grew = true; + } + + // regionLookupKey + // + if (t[2UL]) + { + i.regionLookupKey_value.capacity (i.regionLookupKey_size); + grew = true; + } + + return grew; + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + bind (pgsql::bind* b, + image_type& i, + pgsql::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (sk); + + using namespace pgsql; + + std::size_t n (0); + + // id + // + if (sk != statement_update) + { + b[n].type = pgsql::bind::text; + b[n].buffer = i.id_value.data (); + b[n].capacity = i.id_value.capacity (); + b[n].size = &i.id_size; + b[n].is_null = &i.id_null; + n++; + } + + // addressLabel + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.addressLabel_value.data (); + b[n].capacity = i.addressLabel_value.capacity (); + b[n].size = &i.addressLabel_size; + b[n].is_null = &i.addressLabel_null; + n++; + + // regionLookupKey + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.regionLookupKey_value.data (); + b[n].capacity = i.regionLookupKey_value.capacity (); + b[n].size = &i.regionLookupKey_size; + b[n].is_null = &i.regionLookupKey_null; + n++; + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + bind (pgsql::bind* b, id_image_type& i) + { + std::size_t n (0); + b[n].type = pgsql::bind::text; + b[n].buffer = i.id_value.data (); + b[n].capacity = i.id_value.capacity (); + b[n].size = &i.id_size; + b[n].is_null = &i.id_null; + } + + bool access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + init (image_type& i, + const object_type& o, + pgsql::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (sk); + + using namespace pgsql; + + bool grew (false); + + // id + // + if (sk == statement_insert) + { + ::std::string const& v = + o.id; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.id_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.id_value, + size, + is_null, + v); + i.id_null = is_null; + i.id_size = size; + grew = grew || (cap != i.id_value.capacity ()); + } + + // addressLabel + // + { + ::std::string const& v = + o.addressLabel; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.addressLabel_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.addressLabel_value, + size, + is_null, + v); + i.addressLabel_null = is_null; + i.addressLabel_size = size; + grew = grew || (cap != i.addressLabel_value.capacity ()); + } + + // regionLookupKey + // + { + ::std::string const& v = + o.regionLookupKey; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.regionLookupKey_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.regionLookupKey_value, + size, + is_null, + v); + i.regionLookupKey_null = is_null; + i.regionLookupKey_size = size; + grew = grew || (cap != i.regionLookupKey_value.capacity ()); + } + + return grew; + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + init (object_type& o, + const image_type& i, + database* db) + { + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (db); + + // id + // + { + ::std::string& v = + o.id; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.id_value, + i.id_size, + i.id_null); + } + + // addressLabel + // + { + ::std::string& v = + o.addressLabel; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.addressLabel_value, + i.addressLabel_size, + i.addressLabel_null); + } + + // regionLookupKey + // + { + ::std::string& v = + o.regionLookupKey; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.regionLookupKey_value, + i.regionLookupKey_size, + i.regionLookupKey_null); + } + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + init (id_image_type& i, const id_type& id) + { + bool grew (false); + { + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.id_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.id_value, + size, + is_null, + id); + i.id_null = is_null; + i.id_size = size; + grew = grew || (cap != i.id_value.capacity ()); + } + + if (grew) + i.version++; + } + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::persist_statement[] = + "INSERT INTO \"GovernmentAddress\" " + "(\"id\", " + "\"addressLabel\", " + "\"regionLookupKey\") " + "VALUES " + "($1, $2, $3)"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::find_statement[] = + "SELECT " + "\"GovernmentAddress\".\"id\", " + "\"GovernmentAddress\".\"addressLabel\", " + "\"GovernmentAddress\".\"regionLookupKey\" " + "FROM \"GovernmentAddress\" " + "WHERE \"GovernmentAddress\".\"id\"=$1"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::update_statement[] = + "UPDATE \"GovernmentAddress\" " + "SET " + "\"addressLabel\"=$1, " + "\"regionLookupKey\"=$2 " + "WHERE \"id\"=$3"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::erase_statement[] = + "DELETE FROM \"GovernmentAddress\" " + "WHERE \"id\"=$1"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::query_statement[] = + "SELECT " + "\"GovernmentAddress\".\"id\", " + "\"GovernmentAddress\".\"addressLabel\", " + "\"GovernmentAddress\".\"regionLookupKey\" " + "FROM \"GovernmentAddress\""; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::erase_query_statement[] = + "DELETE FROM \"GovernmentAddress\""; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::table_name[] = + "\"GovernmentAddress\""; + + void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + persist (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + callback (db, + obj, + callback_event::pre_persist); + + image_type& im (sts.image ()); + binding& imb (sts.insert_image_binding ()); + + if (init (im, obj, statement_insert)) + im.version++; + + if (im.version != sts.insert_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_insert); + sts.insert_image_version (im.version); + imb.version++; + } + + insert_statement& st (sts.persist_statement ()); + if (!st.execute ()) + throw object_already_persistent (); + + callback (db, + obj, + callback_event::post_persist); + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + update (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace pgsql; + using pgsql::update_statement; + + callback (db, obj, callback_event::pre_update); + + pgsql::transaction& tr (pgsql::transaction::current ()); + pgsql::connection& conn (tr.connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + const id_type& id ( + obj.id); + id_image_type& idi (sts.id_image ()); + init (idi, id); + + image_type& im (sts.image ()); + if (init (im, obj, statement_update)) + im.version++; + + bool u (false); + binding& imb (sts.update_image_binding ()); + if (im.version != sts.update_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_update); + sts.update_image_version (im.version); + imb.version++; + u = true; + } + + binding& idb (sts.id_image_binding ()); + if (idi.version != sts.update_id_image_version () || + idb.version == 0) + { + if (idi.version != sts.id_image_version () || + idb.version == 0) + { + bind (idb.bind, idi); + sts.id_image_version (idi.version); + idb.version++; + } + + sts.update_id_image_version (idi.version); + + if (!u) + imb.version++; + } + + update_statement& st (sts.update_statement ()); + if (st.execute () == 0) + throw object_not_persistent (); + + callback (db, obj, callback_event::post_update); + pointer_cache_traits::update (db, obj); + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + erase (database& db, const id_type& id) + { + using namespace pgsql; + + ODB_POTENTIALLY_UNUSED (db); + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + id_image_type& i (sts.id_image ()); + init (i, id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + if (sts.erase_statement ().execute () != 1) + throw object_not_persistent (); + + pointer_cache_traits::erase (db, id); + } + + access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::pointer_type + access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + find (database& db, const id_type& id) + { + using namespace pgsql; + + { + pointer_type p (pointer_cache_traits::find (db, id)); + + if (!pointer_traits::null_ptr (p)) + return p; + } + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (l.locked ()) + { + if (!find_ (sts, &id)) + return pointer_type (); + } + + pointer_type p ( + access::object_factory::create ()); + pointer_traits::guard pg (p); + + pointer_cache_traits::insert_guard ig ( + pointer_cache_traits::insert (db, id, p)); + + object_type& obj (pointer_traits::get_ref (p)); + + if (l.locked ()) + { + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + pointer_cache_traits::load (ig.position ()); + } + else + sts.delay_load (id, obj, ig.position ()); + + ig.release (); + pg.release (); + return p; + } + + bool access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + find (database& db, const id_type& id, object_type& obj) + { + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + reference_cache_traits::position_type pos ( + reference_cache_traits::insert (db, id, obj)); + reference_cache_traits::insert_guard ig (pos); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + reference_cache_traits::load (pos); + ig.release (); + return true; + } + + bool access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + reload (database& db, object_type& obj) + { + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + const id_type& id ( + obj.id); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, true); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + return true; + } + + bool access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + find_ (statements_type& sts, + const id_type* id) + { + using namespace pgsql; + + id_image_type& i (sts.id_image ()); + init (i, *id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + select_statement& st (sts.find_statement ()); + + st.execute (); + auto_result ar (st); + select_statement::result r (st.fetch ()); + + if (r == select_statement::truncated) + { + if (grow (im, sts.select_image_truncated ())) + im.version++; + + if (im.version != sts.select_image_version ()) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + st.refetch (); + } + } + + return r != select_statement::no_data; + } + + result< access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >::object_type > + access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + query (database&, const query_base_type& q) + { + using namespace pgsql; + using odb::details::shared; + using odb::details::shared_ptr; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + + statements_type& sts ( + conn.statement_cache ().find_object ()); + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + std::string text (query_statement); + if (!q.empty ()) + { + text += " "; + text += q.clause (); + } + + q.init_parameters (); + shared_ptr st ( + new (shared) select_statement ( + sts.connection (), + query_statement_name, + text, + false, + true, + q.parameter_types (), + q.parameter_count (), + q.parameters_binding (), + imb)); + + st->execute (); + st->deallocate (); + + shared_ptr< odb::object_result_impl > r ( + new (shared) pgsql::object_result_impl ( + q, st, sts, 0)); + + return result (r); + } + + unsigned long long access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + erase_query (database&, const query_base_type& q) + { + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + + std::string text (erase_query_statement); + if (!q.empty ()) + { + text += ' '; + text += q.clause (); + } + + q.init_parameters (); + delete_statement st ( + conn, + erase_query_statement_name, + text, + q.parameter_types (), + q.parameter_count (), + q.parameters_binding ()); + + return st.execute (); + } +} + +#include diff --git a/db/test-schema-v1.2/generated-sql-ddl/postgre/GovernmentAddress-odb.hxx b/db/test-schema-v1.2/generated-sql-ddl/postgre/GovernmentAddress-odb.hxx new file mode 100644 index 0000000..da22f67 --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/postgre/GovernmentAddress-odb.hxx @@ -0,0 +1,309 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#ifndef GOVERNMENT_ADDRESS_ODB_HXX +#define GOVERNMENT_ADDRESS_ODB_HXX + +#include + +#if (ODB_VERSION != 20400UL) +#error ODB runtime version mismatch +#endif + +#include + +#include "GovernmentAddress.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace odb +{ + // GovernmentAddress + // + template <> + struct class_traits< ::models::GovernmentAddress > + { + static const class_kind kind = class_object; + }; + + template <> + class access::object_traits< ::models::GovernmentAddress > + { + public: + typedef ::models::GovernmentAddress object_type; + typedef ::models::GovernmentAddress* pointer_type; + typedef odb::pointer_traits pointer_traits; + + static const bool polymorphic = false; + + typedef ::std::string id_type; + + static const bool auto_id = false; + + static const bool abstract = false; + + static id_type + id (const object_type&); + + typedef + no_op_pointer_cache_traits + pointer_cache_traits; + + typedef + no_op_reference_cache_traits + reference_cache_traits; + + static void + callback (database&, object_type&, callback_event); + + static void + callback (database&, const object_type&, callback_event); + }; +} + +#include + +#include +#include +#include +#include +#include + +namespace odb +{ + // GovernmentAddress + // + template + struct query_columns< ::models::GovernmentAddress, id_pgsql, A > + { + // id + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + id_type_; + + static const id_type_ id; + + // addressLabel + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + addressLabel_type_; + + static const addressLabel_type_ addressLabel; + + // regionLookupKey + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + regionLookupKey_type_; + + static const regionLookupKey_type_ regionLookupKey; + }; + + template + const typename query_columns< ::models::GovernmentAddress, id_pgsql, A >::id_type_ + query_columns< ::models::GovernmentAddress, id_pgsql, A >:: + id (A::table_name, "\"id\"", 0); + + template + const typename query_columns< ::models::GovernmentAddress, id_pgsql, A >::addressLabel_type_ + query_columns< ::models::GovernmentAddress, id_pgsql, A >:: + addressLabel (A::table_name, "\"addressLabel\"", 0); + + template + const typename query_columns< ::models::GovernmentAddress, id_pgsql, A >::regionLookupKey_type_ + query_columns< ::models::GovernmentAddress, id_pgsql, A >:: + regionLookupKey (A::table_name, "\"regionLookupKey\"", 0); + + template + struct pointer_query_columns< ::models::GovernmentAddress, id_pgsql, A >: + query_columns< ::models::GovernmentAddress, id_pgsql, A > + { + }; + + template <> + class access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >: + public access::object_traits< ::models::GovernmentAddress > + { + public: + struct id_image_type + { + details::buffer id_value; + std::size_t id_size; + bool id_null; + + std::size_t version; + }; + + struct image_type + { + // id + // + details::buffer id_value; + std::size_t id_size; + bool id_null; + + // addressLabel + // + details::buffer addressLabel_value; + std::size_t addressLabel_size; + bool addressLabel_null; + + // regionLookupKey + // + details::buffer regionLookupKey_value; + std::size_t regionLookupKey_size; + bool regionLookupKey_null; + + std::size_t version; + }; + + struct extra_statement_cache_type; + + using object_traits::id; + + static id_type + id (const image_type&); + + static bool + grow (image_type&, + bool*); + + static void + bind (pgsql::bind*, + image_type&, + pgsql::statement_kind); + + static void + bind (pgsql::bind*, id_image_type&); + + static bool + init (image_type&, + const object_type&, + pgsql::statement_kind); + + static void + init (object_type&, + const image_type&, + database*); + + static void + init (id_image_type&, const id_type&); + + typedef pgsql::object_statements statements_type; + + typedef pgsql::query_base query_base_type; + + static const std::size_t column_count = 3UL; + static const std::size_t id_column_count = 1UL; + static const std::size_t inverse_column_count = 0UL; + static const std::size_t readonly_column_count = 0UL; + static const std::size_t managed_optimistic_column_count = 0UL; + + static const std::size_t separate_load_column_count = 0UL; + static const std::size_t separate_update_column_count = 0UL; + + static const bool versioned = false; + + static const char persist_statement[]; + static const char find_statement[]; + static const char update_statement[]; + static const char erase_statement[]; + static const char query_statement[]; + static const char erase_query_statement[]; + + static const char table_name[]; + + static void + persist (database&, const object_type&); + + static pointer_type + find (database&, const id_type&); + + static bool + find (database&, const id_type&, object_type&); + + static bool + reload (database&, object_type&); + + static void + update (database&, const object_type&); + + static void + erase (database&, const id_type&); + + static void + erase (database&, const object_type&); + + static result + query (database&, const query_base_type&); + + static unsigned long long + erase_query (database&, const query_base_type&); + + static const char persist_statement_name[]; + static const char find_statement_name[]; + static const char update_statement_name[]; + static const char erase_statement_name[]; + static const char query_statement_name[]; + static const char erase_query_statement_name[]; + + static const unsigned int persist_statement_types[]; + static const unsigned int find_statement_types[]; + static const unsigned int update_statement_types[]; + + public: + static bool + find_ (statements_type&, + const id_type*); + + static void + load_ (statements_type&, + object_type&, + bool reload); + }; + + template <> + class access::object_traits_impl< ::models::GovernmentAddress, id_common >: + public access::object_traits_impl< ::models::GovernmentAddress, id_pgsql > + { + }; + + // GovernmentAddress + // +} + +#include "GovernmentAddress-odb.ixx" + +#include + +#endif // GOVERNMENT_ADDRESS_ODB_HXX diff --git a/db/test-schema-v1.2/generated-sql-ddl/postgre/GovernmentAddress-odb.ixx b/db/test-schema-v1.2/generated-sql-ddl/postgre/GovernmentAddress-odb.ixx new file mode 100644 index 0000000..f33d9f4 --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/postgre/GovernmentAddress-odb.ixx @@ -0,0 +1,61 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +namespace odb +{ + // GovernmentAddress + // + + inline + access::object_traits< ::models::GovernmentAddress >::id_type + access::object_traits< ::models::GovernmentAddress >:: + id (const object_type& o) + { + return o.id; + } + + inline + void access::object_traits< ::models::GovernmentAddress >:: + callback (database& db, object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } + + inline + void access::object_traits< ::models::GovernmentAddress >:: + callback (database& db, const object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } +} + +namespace odb +{ + // GovernmentAddress + // + + inline + void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + erase (database& db, const object_type& obj) + { + callback (db, obj, callback_event::pre_erase); + erase (db, id (obj)); + callback (db, obj, callback_event::post_erase); + } + + inline + void access::object_traits_impl< ::models::GovernmentAddress, id_pgsql >:: + load_ (statements_type& sts, + object_type& obj, + bool) + { + ODB_POTENTIALLY_UNUSED (sts); + ODB_POTENTIALLY_UNUSED (obj); + } +} + diff --git a/db/test-schema-v1.2/generated-sql-ddl/postgre/GovernmentAddress.sql b/db/test-schema-v1.2/generated-sql-ddl/postgre/GovernmentAddress.sql new file mode 100644 index 0000000..9f4ea19 --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/postgre/GovernmentAddress.sql @@ -0,0 +1,22 @@ +/* This file was generated by ODB, object-relational mapping (ORM) + * compiler for C++. + */ + +DROP TABLE IF EXISTS "GovernmentAddress" CASCADE; + +DROP TABLE IF EXISTS "schema_version"; + +CREATE TABLE "GovernmentAddress" ( + "id" TEXT NOT NULL PRIMARY KEY, + "addressLabel" TEXT NOT NULL, + "regionLookupKey" TEXT NOT NULL); + +CREATE TABLE "schema_version" ( + "name" TEXT NOT NULL PRIMARY KEY, + "version" BIGINT NOT NULL, + "migration" BOOLEAN NOT NULL); + +INSERT INTO "schema_version" ( + "name", "version", "migration") + VALUES ('', 2, FALSE); + diff --git a/db/test-schema-v1.2/generated-sql-ddl/postgre/TripAttemptResult-002-post.sql b/db/test-schema-v1.2/generated-sql-ddl/postgre/TripAttemptResult-002-post.sql new file mode 100644 index 0000000..2424f4d --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/postgre/TripAttemptResult-002-post.sql @@ -0,0 +1,8 @@ +/* This file was generated by ODB, object-relational mapping (ORM) + * compiler for C++. + */ + +UPDATE "schema_version" + SET "migration" = FALSE + WHERE "name" = ''; + diff --git a/db/test-schema-v1.2/generated-sql-ddl/postgre/TripAttemptResult-002-pre.sql b/db/test-schema-v1.2/generated-sql-ddl/postgre/TripAttemptResult-002-pre.sql new file mode 100644 index 0000000..a090f6c --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/postgre/TripAttemptResult-002-pre.sql @@ -0,0 +1,22 @@ +/* This file was generated by ODB, object-relational mapping (ORM) + * compiler for C++. + */ + +CREATE TABLE "TripAttemptResult" ( + "id" TEXT NOT NULL PRIMARY KEY, + "result" TEXT NOT NULL, + "retryReason" TEXT NOT NULL, + "governmentSuspensionReason" TEXT NOT NULL, + "governmentTerminationReason" TEXT NOT NULL, + "complianceSuspensionReason" TEXT NOT NULL, + "complianceTerminationReason" TEXT NOT NULL, + "policySuspensionReason" TEXT NOT NULL, + "policyTerminationReason" TEXT NOT NULL, + "cancelationReason" TEXT NOT NULL, + "failureReason" TEXT NOT NULL, + "details" TEXT NOT NULL); + +UPDATE "schema_version" + SET "version" = 2, "migration" = TRUE + WHERE "name" = ''; + diff --git a/db/test-schema-v1.2/generated-sql-ddl/postgre/TripAttemptResult-odb.cxx b/db/test-schema-v1.2/generated-sql-ddl/postgre/TripAttemptResult-odb.cxx new file mode 100644 index 0000000..9e43259 --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/postgre/TripAttemptResult-odb.cxx @@ -0,0 +1,1305 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#include + +#include "TripAttemptResult-odb.hxx" + +#include +#include // std::memcpy + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace odb +{ + // TripAttemptResult + // + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + persist_statement_name[] = "persist_models_TripAttemptResult"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + find_statement_name[] = "find_models_TripAttemptResult"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + update_statement_name[] = "update_models_TripAttemptResult"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + erase_statement_name[] = "erase_models_TripAttemptResult"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + query_statement_name[] = "query_models_TripAttemptResult"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + erase_query_statement_name[] = "erase_query_models_TripAttemptResult"; + + const unsigned int access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + persist_statement_types[] = + { + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid + }; + + const unsigned int access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + find_statement_types[] = + { + pgsql::text_oid + }; + + const unsigned int access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + update_statement_types[] = + { + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid, + pgsql::text_oid + }; + + struct access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::extra_statement_cache_type + { + extra_statement_cache_type ( + pgsql::connection&, + image_type&, + id_image_type&, + pgsql::binding&, + pgsql::binding&, + pgsql::native_binding&, + const unsigned int*) + { + } + }; + + access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::id_type + access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + id (const image_type& i) + { + pgsql::database* db (0); + ODB_POTENTIALLY_UNUSED (db); + + id_type id; + { + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + id, + i.id_value, + i.id_size, + i.id_null); + } + + return id; + } + + bool access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + grow (image_type& i, + bool* t) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (t); + + bool grew (false); + + // id + // + if (t[0UL]) + { + i.id_value.capacity (i.id_size); + grew = true; + } + + // result + // + if (t[1UL]) + { + i.result_value.capacity (i.result_size); + grew = true; + } + + // retryReason + // + if (t[2UL]) + { + i.retryReason_value.capacity (i.retryReason_size); + grew = true; + } + + // governmentSuspensionReason + // + if (t[3UL]) + { + i.governmentSuspensionReason_value.capacity (i.governmentSuspensionReason_size); + grew = true; + } + + // governmentTerminationReason + // + if (t[4UL]) + { + i.governmentTerminationReason_value.capacity (i.governmentTerminationReason_size); + grew = true; + } + + // complianceSuspensionReason + // + if (t[5UL]) + { + i.complianceSuspensionReason_value.capacity (i.complianceSuspensionReason_size); + grew = true; + } + + // complianceTerminationReason + // + if (t[6UL]) + { + i.complianceTerminationReason_value.capacity (i.complianceTerminationReason_size); + grew = true; + } + + // policySuspensionReason + // + if (t[7UL]) + { + i.policySuspensionReason_value.capacity (i.policySuspensionReason_size); + grew = true; + } + + // policyTerminationReason + // + if (t[8UL]) + { + i.policyTerminationReason_value.capacity (i.policyTerminationReason_size); + grew = true; + } + + // cancelationReason + // + if (t[9UL]) + { + i.cancelationReason_value.capacity (i.cancelationReason_size); + grew = true; + } + + // failureReason + // + if (t[10UL]) + { + i.failureReason_value.capacity (i.failureReason_size); + grew = true; + } + + // details + // + if (t[11UL]) + { + i.details_value.capacity (i.details_size); + grew = true; + } + + return grew; + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + bind (pgsql::bind* b, + image_type& i, + pgsql::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (sk); + + using namespace pgsql; + + std::size_t n (0); + + // id + // + if (sk != statement_update) + { + b[n].type = pgsql::bind::text; + b[n].buffer = i.id_value.data (); + b[n].capacity = i.id_value.capacity (); + b[n].size = &i.id_size; + b[n].is_null = &i.id_null; + n++; + } + + // result + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.result_value.data (); + b[n].capacity = i.result_value.capacity (); + b[n].size = &i.result_size; + b[n].is_null = &i.result_null; + n++; + + // retryReason + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.retryReason_value.data (); + b[n].capacity = i.retryReason_value.capacity (); + b[n].size = &i.retryReason_size; + b[n].is_null = &i.retryReason_null; + n++; + + // governmentSuspensionReason + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.governmentSuspensionReason_value.data (); + b[n].capacity = i.governmentSuspensionReason_value.capacity (); + b[n].size = &i.governmentSuspensionReason_size; + b[n].is_null = &i.governmentSuspensionReason_null; + n++; + + // governmentTerminationReason + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.governmentTerminationReason_value.data (); + b[n].capacity = i.governmentTerminationReason_value.capacity (); + b[n].size = &i.governmentTerminationReason_size; + b[n].is_null = &i.governmentTerminationReason_null; + n++; + + // complianceSuspensionReason + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.complianceSuspensionReason_value.data (); + b[n].capacity = i.complianceSuspensionReason_value.capacity (); + b[n].size = &i.complianceSuspensionReason_size; + b[n].is_null = &i.complianceSuspensionReason_null; + n++; + + // complianceTerminationReason + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.complianceTerminationReason_value.data (); + b[n].capacity = i.complianceTerminationReason_value.capacity (); + b[n].size = &i.complianceTerminationReason_size; + b[n].is_null = &i.complianceTerminationReason_null; + n++; + + // policySuspensionReason + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.policySuspensionReason_value.data (); + b[n].capacity = i.policySuspensionReason_value.capacity (); + b[n].size = &i.policySuspensionReason_size; + b[n].is_null = &i.policySuspensionReason_null; + n++; + + // policyTerminationReason + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.policyTerminationReason_value.data (); + b[n].capacity = i.policyTerminationReason_value.capacity (); + b[n].size = &i.policyTerminationReason_size; + b[n].is_null = &i.policyTerminationReason_null; + n++; + + // cancelationReason + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.cancelationReason_value.data (); + b[n].capacity = i.cancelationReason_value.capacity (); + b[n].size = &i.cancelationReason_size; + b[n].is_null = &i.cancelationReason_null; + n++; + + // failureReason + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.failureReason_value.data (); + b[n].capacity = i.failureReason_value.capacity (); + b[n].size = &i.failureReason_size; + b[n].is_null = &i.failureReason_null; + n++; + + // details + // + b[n].type = pgsql::bind::text; + b[n].buffer = i.details_value.data (); + b[n].capacity = i.details_value.capacity (); + b[n].size = &i.details_size; + b[n].is_null = &i.details_null; + n++; + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + bind (pgsql::bind* b, id_image_type& i) + { + std::size_t n (0); + b[n].type = pgsql::bind::text; + b[n].buffer = i.id_value.data (); + b[n].capacity = i.id_value.capacity (); + b[n].size = &i.id_size; + b[n].is_null = &i.id_null; + } + + bool access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + init (image_type& i, + const object_type& o, + pgsql::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (sk); + + using namespace pgsql; + + bool grew (false); + + // id + // + if (sk == statement_insert) + { + ::std::string const& v = + o.id; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.id_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.id_value, + size, + is_null, + v); + i.id_null = is_null; + i.id_size = size; + grew = grew || (cap != i.id_value.capacity ()); + } + + // result + // + { + ::std::string const& v = + o.result; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.result_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.result_value, + size, + is_null, + v); + i.result_null = is_null; + i.result_size = size; + grew = grew || (cap != i.result_value.capacity ()); + } + + // retryReason + // + { + ::std::string const& v = + o.retryReason; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.retryReason_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.retryReason_value, + size, + is_null, + v); + i.retryReason_null = is_null; + i.retryReason_size = size; + grew = grew || (cap != i.retryReason_value.capacity ()); + } + + // governmentSuspensionReason + // + { + ::std::string const& v = + o.governmentSuspensionReason; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.governmentSuspensionReason_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.governmentSuspensionReason_value, + size, + is_null, + v); + i.governmentSuspensionReason_null = is_null; + i.governmentSuspensionReason_size = size; + grew = grew || (cap != i.governmentSuspensionReason_value.capacity ()); + } + + // governmentTerminationReason + // + { + ::std::string const& v = + o.governmentTerminationReason; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.governmentTerminationReason_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.governmentTerminationReason_value, + size, + is_null, + v); + i.governmentTerminationReason_null = is_null; + i.governmentTerminationReason_size = size; + grew = grew || (cap != i.governmentTerminationReason_value.capacity ()); + } + + // complianceSuspensionReason + // + { + ::std::string const& v = + o.complianceSuspensionReason; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.complianceSuspensionReason_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.complianceSuspensionReason_value, + size, + is_null, + v); + i.complianceSuspensionReason_null = is_null; + i.complianceSuspensionReason_size = size; + grew = grew || (cap != i.complianceSuspensionReason_value.capacity ()); + } + + // complianceTerminationReason + // + { + ::std::string const& v = + o.complianceTerminationReason; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.complianceTerminationReason_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.complianceTerminationReason_value, + size, + is_null, + v); + i.complianceTerminationReason_null = is_null; + i.complianceTerminationReason_size = size; + grew = grew || (cap != i.complianceTerminationReason_value.capacity ()); + } + + // policySuspensionReason + // + { + ::std::string const& v = + o.policySuspensionReason; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.policySuspensionReason_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.policySuspensionReason_value, + size, + is_null, + v); + i.policySuspensionReason_null = is_null; + i.policySuspensionReason_size = size; + grew = grew || (cap != i.policySuspensionReason_value.capacity ()); + } + + // policyTerminationReason + // + { + ::std::string const& v = + o.policyTerminationReason; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.policyTerminationReason_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.policyTerminationReason_value, + size, + is_null, + v); + i.policyTerminationReason_null = is_null; + i.policyTerminationReason_size = size; + grew = grew || (cap != i.policyTerminationReason_value.capacity ()); + } + + // cancelationReason + // + { + ::std::string const& v = + o.cancelationReason; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.cancelationReason_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.cancelationReason_value, + size, + is_null, + v); + i.cancelationReason_null = is_null; + i.cancelationReason_size = size; + grew = grew || (cap != i.cancelationReason_value.capacity ()); + } + + // failureReason + // + { + ::std::string const& v = + o.failureReason; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.failureReason_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.failureReason_value, + size, + is_null, + v); + i.failureReason_null = is_null; + i.failureReason_size = size; + grew = grew || (cap != i.failureReason_value.capacity ()); + } + + // details + // + { + ::std::string const& v = + o.details; + + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.details_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.details_value, + size, + is_null, + v); + i.details_null = is_null; + i.details_size = size; + grew = grew || (cap != i.details_value.capacity ()); + } + + return grew; + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + init (object_type& o, + const image_type& i, + database* db) + { + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (db); + + // id + // + { + ::std::string& v = + o.id; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.id_value, + i.id_size, + i.id_null); + } + + // result + // + { + ::std::string& v = + o.result; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.result_value, + i.result_size, + i.result_null); + } + + // retryReason + // + { + ::std::string& v = + o.retryReason; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.retryReason_value, + i.retryReason_size, + i.retryReason_null); + } + + // governmentSuspensionReason + // + { + ::std::string& v = + o.governmentSuspensionReason; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.governmentSuspensionReason_value, + i.governmentSuspensionReason_size, + i.governmentSuspensionReason_null); + } + + // governmentTerminationReason + // + { + ::std::string& v = + o.governmentTerminationReason; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.governmentTerminationReason_value, + i.governmentTerminationReason_size, + i.governmentTerminationReason_null); + } + + // complianceSuspensionReason + // + { + ::std::string& v = + o.complianceSuspensionReason; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.complianceSuspensionReason_value, + i.complianceSuspensionReason_size, + i.complianceSuspensionReason_null); + } + + // complianceTerminationReason + // + { + ::std::string& v = + o.complianceTerminationReason; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.complianceTerminationReason_value, + i.complianceTerminationReason_size, + i.complianceTerminationReason_null); + } + + // policySuspensionReason + // + { + ::std::string& v = + o.policySuspensionReason; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.policySuspensionReason_value, + i.policySuspensionReason_size, + i.policySuspensionReason_null); + } + + // policyTerminationReason + // + { + ::std::string& v = + o.policyTerminationReason; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.policyTerminationReason_value, + i.policyTerminationReason_size, + i.policyTerminationReason_null); + } + + // cancelationReason + // + { + ::std::string& v = + o.cancelationReason; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.cancelationReason_value, + i.cancelationReason_size, + i.cancelationReason_null); + } + + // failureReason + // + { + ::std::string& v = + o.failureReason; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.failureReason_value, + i.failureReason_size, + i.failureReason_null); + } + + // details + // + { + ::std::string& v = + o.details; + + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_value ( + v, + i.details_value, + i.details_size, + i.details_null); + } + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + init (id_image_type& i, const id_type& id) + { + bool grew (false); + { + bool is_null (false); + std::size_t size (0); + std::size_t cap (i.id_value.capacity ()); + pgsql::value_traits< + ::std::string, + pgsql::id_string >::set_image ( + i.id_value, + size, + is_null, + id); + i.id_null = is_null; + i.id_size = size; + grew = grew || (cap != i.id_value.capacity ()); + } + + if (grew) + i.version++; + } + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::persist_statement[] = + "INSERT INTO \"TripAttemptResult\" " + "(\"id\", " + "\"result\", " + "\"retryReason\", " + "\"governmentSuspensionReason\", " + "\"governmentTerminationReason\", " + "\"complianceSuspensionReason\", " + "\"complianceTerminationReason\", " + "\"policySuspensionReason\", " + "\"policyTerminationReason\", " + "\"cancelationReason\", " + "\"failureReason\", " + "\"details\") " + "VALUES " + "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::find_statement[] = + "SELECT " + "\"TripAttemptResult\".\"id\", " + "\"TripAttemptResult\".\"result\", " + "\"TripAttemptResult\".\"retryReason\", " + "\"TripAttemptResult\".\"governmentSuspensionReason\", " + "\"TripAttemptResult\".\"governmentTerminationReason\", " + "\"TripAttemptResult\".\"complianceSuspensionReason\", " + "\"TripAttemptResult\".\"complianceTerminationReason\", " + "\"TripAttemptResult\".\"policySuspensionReason\", " + "\"TripAttemptResult\".\"policyTerminationReason\", " + "\"TripAttemptResult\".\"cancelationReason\", " + "\"TripAttemptResult\".\"failureReason\", " + "\"TripAttemptResult\".\"details\" " + "FROM \"TripAttemptResult\" " + "WHERE \"TripAttemptResult\".\"id\"=$1"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::update_statement[] = + "UPDATE \"TripAttemptResult\" " + "SET " + "\"result\"=$1, " + "\"retryReason\"=$2, " + "\"governmentSuspensionReason\"=$3, " + "\"governmentTerminationReason\"=$4, " + "\"complianceSuspensionReason\"=$5, " + "\"complianceTerminationReason\"=$6, " + "\"policySuspensionReason\"=$7, " + "\"policyTerminationReason\"=$8, " + "\"cancelationReason\"=$9, " + "\"failureReason\"=$10, " + "\"details\"=$11 " + "WHERE \"id\"=$12"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::erase_statement[] = + "DELETE FROM \"TripAttemptResult\" " + "WHERE \"id\"=$1"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::query_statement[] = + "SELECT " + "\"TripAttemptResult\".\"id\", " + "\"TripAttemptResult\".\"result\", " + "\"TripAttemptResult\".\"retryReason\", " + "\"TripAttemptResult\".\"governmentSuspensionReason\", " + "\"TripAttemptResult\".\"governmentTerminationReason\", " + "\"TripAttemptResult\".\"complianceSuspensionReason\", " + "\"TripAttemptResult\".\"complianceTerminationReason\", " + "\"TripAttemptResult\".\"policySuspensionReason\", " + "\"TripAttemptResult\".\"policyTerminationReason\", " + "\"TripAttemptResult\".\"cancelationReason\", " + "\"TripAttemptResult\".\"failureReason\", " + "\"TripAttemptResult\".\"details\" " + "FROM \"TripAttemptResult\""; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::erase_query_statement[] = + "DELETE FROM \"TripAttemptResult\""; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::table_name[] = + "\"TripAttemptResult\""; + + void access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + persist (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + callback (db, + obj, + callback_event::pre_persist); + + image_type& im (sts.image ()); + binding& imb (sts.insert_image_binding ()); + + if (init (im, obj, statement_insert)) + im.version++; + + if (im.version != sts.insert_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_insert); + sts.insert_image_version (im.version); + imb.version++; + } + + insert_statement& st (sts.persist_statement ()); + if (!st.execute ()) + throw object_already_persistent (); + + callback (db, + obj, + callback_event::post_persist); + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + update (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace pgsql; + using pgsql::update_statement; + + callback (db, obj, callback_event::pre_update); + + pgsql::transaction& tr (pgsql::transaction::current ()); + pgsql::connection& conn (tr.connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + const id_type& id ( + obj.id); + id_image_type& idi (sts.id_image ()); + init (idi, id); + + image_type& im (sts.image ()); + if (init (im, obj, statement_update)) + im.version++; + + bool u (false); + binding& imb (sts.update_image_binding ()); + if (im.version != sts.update_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_update); + sts.update_image_version (im.version); + imb.version++; + u = true; + } + + binding& idb (sts.id_image_binding ()); + if (idi.version != sts.update_id_image_version () || + idb.version == 0) + { + if (idi.version != sts.id_image_version () || + idb.version == 0) + { + bind (idb.bind, idi); + sts.id_image_version (idi.version); + idb.version++; + } + + sts.update_id_image_version (idi.version); + + if (!u) + imb.version++; + } + + update_statement& st (sts.update_statement ()); + if (st.execute () == 0) + throw object_not_persistent (); + + callback (db, obj, callback_event::post_update); + pointer_cache_traits::update (db, obj); + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + erase (database& db, const id_type& id) + { + using namespace pgsql; + + ODB_POTENTIALLY_UNUSED (db); + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + id_image_type& i (sts.id_image ()); + init (i, id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + if (sts.erase_statement ().execute () != 1) + throw object_not_persistent (); + + pointer_cache_traits::erase (db, id); + } + + access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::pointer_type + access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + find (database& db, const id_type& id) + { + using namespace pgsql; + + { + pointer_type p (pointer_cache_traits::find (db, id)); + + if (!pointer_traits::null_ptr (p)) + return p; + } + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (l.locked ()) + { + if (!find_ (sts, &id)) + return pointer_type (); + } + + pointer_type p ( + access::object_factory::create ()); + pointer_traits::guard pg (p); + + pointer_cache_traits::insert_guard ig ( + pointer_cache_traits::insert (db, id, p)); + + object_type& obj (pointer_traits::get_ref (p)); + + if (l.locked ()) + { + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + pointer_cache_traits::load (ig.position ()); + } + else + sts.delay_load (id, obj, ig.position ()); + + ig.release (); + pg.release (); + return p; + } + + bool access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + find (database& db, const id_type& id, object_type& obj) + { + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + reference_cache_traits::position_type pos ( + reference_cache_traits::insert (db, id, obj)); + reference_cache_traits::insert_guard ig (pos); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + reference_cache_traits::load (pos); + ig.release (); + return true; + } + + bool access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + reload (database& db, object_type& obj) + { + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + const id_type& id ( + obj.id); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, true); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + return true; + } + + bool access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + find_ (statements_type& sts, + const id_type* id) + { + using namespace pgsql; + + id_image_type& i (sts.id_image ()); + init (i, *id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + select_statement& st (sts.find_statement ()); + + st.execute (); + auto_result ar (st); + select_statement::result r (st.fetch ()); + + if (r == select_statement::truncated) + { + if (grow (im, sts.select_image_truncated ())) + im.version++; + + if (im.version != sts.select_image_version ()) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + st.refetch (); + } + } + + return r != select_statement::no_data; + } + + result< access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >::object_type > + access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + query (database&, const query_base_type& q) + { + using namespace pgsql; + using odb::details::shared; + using odb::details::shared_ptr; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + + statements_type& sts ( + conn.statement_cache ().find_object ()); + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + std::string text (query_statement); + if (!q.empty ()) + { + text += " "; + text += q.clause (); + } + + q.init_parameters (); + shared_ptr st ( + new (shared) select_statement ( + sts.connection (), + query_statement_name, + text, + false, + true, + q.parameter_types (), + q.parameter_count (), + q.parameters_binding (), + imb)); + + st->execute (); + st->deallocate (); + + shared_ptr< odb::object_result_impl > r ( + new (shared) pgsql::object_result_impl ( + q, st, sts, 0)); + + return result (r); + } + + unsigned long long access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + erase_query (database&, const query_base_type& q) + { + using namespace pgsql; + + pgsql::connection& conn ( + pgsql::transaction::current ().connection ()); + + std::string text (erase_query_statement); + if (!q.empty ()) + { + text += ' '; + text += q.clause (); + } + + q.init_parameters (); + delete_statement st ( + conn, + erase_query_statement_name, + text, + q.parameter_types (), + q.parameter_count (), + q.parameters_binding ()); + + return st.execute (); + } +} + +#include diff --git a/db/test-schema-v1.2/generated-sql-ddl/postgre/TripAttemptResult-odb.hxx b/db/test-schema-v1.2/generated-sql-ddl/postgre/TripAttemptResult-odb.hxx new file mode 100644 index 0000000..0bb9327 --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/postgre/TripAttemptResult-odb.hxx @@ -0,0 +1,516 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#ifndef TRIP_ATTEMPT_RESULT_ODB_HXX +#define TRIP_ATTEMPT_RESULT_ODB_HXX + +#include + +#if (ODB_VERSION != 20400UL) +#error ODB runtime version mismatch +#endif + +#include + +#include "TripAttemptResult.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace odb +{ + // TripAttemptResult + // + template <> + struct class_traits< ::models::TripAttemptResult > + { + static const class_kind kind = class_object; + }; + + template <> + class access::object_traits< ::models::TripAttemptResult > + { + public: + typedef ::models::TripAttemptResult object_type; + typedef ::models::TripAttemptResult* pointer_type; + typedef odb::pointer_traits pointer_traits; + + static const bool polymorphic = false; + + typedef ::std::string id_type; + + static const bool auto_id = false; + + static const bool abstract = false; + + static id_type + id (const object_type&); + + typedef + no_op_pointer_cache_traits + pointer_cache_traits; + + typedef + no_op_reference_cache_traits + reference_cache_traits; + + static void + callback (database&, object_type&, callback_event); + + static void + callback (database&, const object_type&, callback_event); + }; +} + +#include + +#include +#include +#include +#include +#include + +namespace odb +{ + // TripAttemptResult + // + template + struct query_columns< ::models::TripAttemptResult, id_pgsql, A > + { + // id + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + id_type_; + + static const id_type_ id; + + // result + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + result_type_; + + static const result_type_ result; + + // retryReason + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + retryReason_type_; + + static const retryReason_type_ retryReason; + + // governmentSuspensionReason + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + governmentSuspensionReason_type_; + + static const governmentSuspensionReason_type_ governmentSuspensionReason; + + // governmentTerminationReason + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + governmentTerminationReason_type_; + + static const governmentTerminationReason_type_ governmentTerminationReason; + + // complianceSuspensionReason + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + complianceSuspensionReason_type_; + + static const complianceSuspensionReason_type_ complianceSuspensionReason; + + // complianceTerminationReason + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + complianceTerminationReason_type_; + + static const complianceTerminationReason_type_ complianceTerminationReason; + + // policySuspensionReason + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + policySuspensionReason_type_; + + static const policySuspensionReason_type_ policySuspensionReason; + + // policyTerminationReason + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + policyTerminationReason_type_; + + static const policyTerminationReason_type_ policyTerminationReason; + + // cancelationReason + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + cancelationReason_type_; + + static const cancelationReason_type_ cancelationReason; + + // failureReason + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + failureReason_type_; + + static const failureReason_type_ failureReason; + + // details + // + typedef + pgsql::query_column< + pgsql::value_traits< + ::std::string, + pgsql::id_string >::query_type, + pgsql::id_string > + details_type_; + + static const details_type_ details; + }; + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::id_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + id (A::table_name, "\"id\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::result_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + result (A::table_name, "\"result\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::retryReason_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + retryReason (A::table_name, "\"retryReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::governmentSuspensionReason_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + governmentSuspensionReason (A::table_name, "\"governmentSuspensionReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::governmentTerminationReason_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + governmentTerminationReason (A::table_name, "\"governmentTerminationReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::complianceSuspensionReason_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + complianceSuspensionReason (A::table_name, "\"complianceSuspensionReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::complianceTerminationReason_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + complianceTerminationReason (A::table_name, "\"complianceTerminationReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::policySuspensionReason_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + policySuspensionReason (A::table_name, "\"policySuspensionReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::policyTerminationReason_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + policyTerminationReason (A::table_name, "\"policyTerminationReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::cancelationReason_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + cancelationReason (A::table_name, "\"cancelationReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::failureReason_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + failureReason (A::table_name, "\"failureReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_pgsql, A >::details_type_ + query_columns< ::models::TripAttemptResult, id_pgsql, A >:: + details (A::table_name, "\"details\"", 0); + + template + struct pointer_query_columns< ::models::TripAttemptResult, id_pgsql, A >: + query_columns< ::models::TripAttemptResult, id_pgsql, A > + { + }; + + template <> + class access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >: + public access::object_traits< ::models::TripAttemptResult > + { + public: + struct id_image_type + { + details::buffer id_value; + std::size_t id_size; + bool id_null; + + std::size_t version; + }; + + struct image_type + { + // id + // + details::buffer id_value; + std::size_t id_size; + bool id_null; + + // result + // + details::buffer result_value; + std::size_t result_size; + bool result_null; + + // retryReason + // + details::buffer retryReason_value; + std::size_t retryReason_size; + bool retryReason_null; + + // governmentSuspensionReason + // + details::buffer governmentSuspensionReason_value; + std::size_t governmentSuspensionReason_size; + bool governmentSuspensionReason_null; + + // governmentTerminationReason + // + details::buffer governmentTerminationReason_value; + std::size_t governmentTerminationReason_size; + bool governmentTerminationReason_null; + + // complianceSuspensionReason + // + details::buffer complianceSuspensionReason_value; + std::size_t complianceSuspensionReason_size; + bool complianceSuspensionReason_null; + + // complianceTerminationReason + // + details::buffer complianceTerminationReason_value; + std::size_t complianceTerminationReason_size; + bool complianceTerminationReason_null; + + // policySuspensionReason + // + details::buffer policySuspensionReason_value; + std::size_t policySuspensionReason_size; + bool policySuspensionReason_null; + + // policyTerminationReason + // + details::buffer policyTerminationReason_value; + std::size_t policyTerminationReason_size; + bool policyTerminationReason_null; + + // cancelationReason + // + details::buffer cancelationReason_value; + std::size_t cancelationReason_size; + bool cancelationReason_null; + + // failureReason + // + details::buffer failureReason_value; + std::size_t failureReason_size; + bool failureReason_null; + + // details + // + details::buffer details_value; + std::size_t details_size; + bool details_null; + + std::size_t version; + }; + + struct extra_statement_cache_type; + + using object_traits::id; + + static id_type + id (const image_type&); + + static bool + grow (image_type&, + bool*); + + static void + bind (pgsql::bind*, + image_type&, + pgsql::statement_kind); + + static void + bind (pgsql::bind*, id_image_type&); + + static bool + init (image_type&, + const object_type&, + pgsql::statement_kind); + + static void + init (object_type&, + const image_type&, + database*); + + static void + init (id_image_type&, const id_type&); + + typedef pgsql::object_statements statements_type; + + typedef pgsql::query_base query_base_type; + + static const std::size_t column_count = 12UL; + static const std::size_t id_column_count = 1UL; + static const std::size_t inverse_column_count = 0UL; + static const std::size_t readonly_column_count = 0UL; + static const std::size_t managed_optimistic_column_count = 0UL; + + static const std::size_t separate_load_column_count = 0UL; + static const std::size_t separate_update_column_count = 0UL; + + static const bool versioned = false; + + static const char persist_statement[]; + static const char find_statement[]; + static const char update_statement[]; + static const char erase_statement[]; + static const char query_statement[]; + static const char erase_query_statement[]; + + static const char table_name[]; + + static void + persist (database&, const object_type&); + + static pointer_type + find (database&, const id_type&); + + static bool + find (database&, const id_type&, object_type&); + + static bool + reload (database&, object_type&); + + static void + update (database&, const object_type&); + + static void + erase (database&, const id_type&); + + static void + erase (database&, const object_type&); + + static result + query (database&, const query_base_type&); + + static unsigned long long + erase_query (database&, const query_base_type&); + + static const char persist_statement_name[]; + static const char find_statement_name[]; + static const char update_statement_name[]; + static const char erase_statement_name[]; + static const char query_statement_name[]; + static const char erase_query_statement_name[]; + + static const unsigned int persist_statement_types[]; + static const unsigned int find_statement_types[]; + static const unsigned int update_statement_types[]; + + public: + static bool + find_ (statements_type&, + const id_type*); + + static void + load_ (statements_type&, + object_type&, + bool reload); + }; + + template <> + class access::object_traits_impl< ::models::TripAttemptResult, id_common >: + public access::object_traits_impl< ::models::TripAttemptResult, id_pgsql > + { + }; + + // TripAttemptResult + // +} + +#include "TripAttemptResult-odb.ixx" + +#include + +#endif // TRIP_ATTEMPT_RESULT_ODB_HXX diff --git a/db/test-schema-v1.2/generated-sql-ddl/postgre/TripAttemptResult-odb.ixx b/db/test-schema-v1.2/generated-sql-ddl/postgre/TripAttemptResult-odb.ixx new file mode 100644 index 0000000..e51e168 --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/postgre/TripAttemptResult-odb.ixx @@ -0,0 +1,61 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +namespace odb +{ + // TripAttemptResult + // + + inline + access::object_traits< ::models::TripAttemptResult >::id_type + access::object_traits< ::models::TripAttemptResult >:: + id (const object_type& o) + { + return o.id; + } + + inline + void access::object_traits< ::models::TripAttemptResult >:: + callback (database& db, object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } + + inline + void access::object_traits< ::models::TripAttemptResult >:: + callback (database& db, const object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } +} + +namespace odb +{ + // TripAttemptResult + // + + inline + void access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + erase (database& db, const object_type& obj) + { + callback (db, obj, callback_event::pre_erase); + erase (db, id (obj)); + callback (db, obj, callback_event::post_erase); + } + + inline + void access::object_traits_impl< ::models::TripAttemptResult, id_pgsql >:: + load_ (statements_type& sts, + object_type& obj, + bool) + { + ODB_POTENTIALLY_UNUSED (sts); + ODB_POTENTIALLY_UNUSED (obj); + } +} + diff --git a/db/test-schema-v1.2/generated-sql-ddl/postgre/TripAttemptResult.sql b/db/test-schema-v1.2/generated-sql-ddl/postgre/TripAttemptResult.sql new file mode 100644 index 0000000..d1bd944 --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/postgre/TripAttemptResult.sql @@ -0,0 +1,31 @@ +/* This file was generated by ODB, object-relational mapping (ORM) + * compiler for C++. + */ + +DROP TABLE IF EXISTS "TripAttemptResult" CASCADE; + +DROP TABLE IF EXISTS "schema_version"; + +CREATE TABLE "TripAttemptResult" ( + "id" TEXT NOT NULL PRIMARY KEY, + "result" TEXT NOT NULL, + "retryReason" TEXT NOT NULL, + "governmentSuspensionReason" TEXT NOT NULL, + "governmentTerminationReason" TEXT NOT NULL, + "complianceSuspensionReason" TEXT NOT NULL, + "complianceTerminationReason" TEXT NOT NULL, + "policySuspensionReason" TEXT NOT NULL, + "policyTerminationReason" TEXT NOT NULL, + "cancelationReason" TEXT NOT NULL, + "failureReason" TEXT NOT NULL, + "details" TEXT NOT NULL); + +CREATE TABLE "schema_version" ( + "name" TEXT NOT NULL PRIMARY KEY, + "version" BIGINT NOT NULL, + "migration" BOOLEAN NOT NULL); + +INSERT INTO "schema_version" ( + "name", "version", "migration") + VALUES ('', 2, FALSE); + diff --git a/db/test-schema-v1.2/generated-sql-ddl/sqlite/Agent-002-post.sql b/db/test-schema-v1.2/generated-sql-ddl/sqlite/Agent-002-post.sql new file mode 100644 index 0000000..a3c08ed --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/sqlite/Agent-002-post.sql @@ -0,0 +1,8 @@ +/* This file was generated by ODB, object-relational mapping (ORM) + * compiler for C++. + */ + +UPDATE "schema_version" + SET "migration" = 0 + WHERE "name" = ''; + diff --git a/db/test-schema-v1.2/generated-sql-ddl/sqlite/Agent-002-pre.sql b/db/test-schema-v1.2/generated-sql-ddl/sqlite/Agent-002-pre.sql new file mode 100644 index 0000000..bd6d649 --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/sqlite/Agent-002-pre.sql @@ -0,0 +1,15 @@ +/* This file was generated by ODB, object-relational mapping (ORM) + * compiler for C++. + */ + +CREATE TABLE "Agent" ( + "id" TEXT NOT NULL PRIMARY KEY, + "role" TEXT NOT NULL, + "persistent" INTEGER NOT NULL, + "displayName" TEXT NOT NULL, + "trustScore" INTEGER NOT NULL); + +UPDATE "schema_version" + SET "version" = 2, "migration" = 1 + WHERE "name" = ''; + diff --git a/db/test-schema-v1.2/generated-sql-ddl/sqlite/Agent-odb.cxx b/db/test-schema-v1.2/generated-sql-ddl/sqlite/Agent-odb.cxx new file mode 100644 index 0000000..4da4886 --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/sqlite/Agent-odb.cxx @@ -0,0 +1,815 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#include + +#include "Agent-odb.hxx" + +#include +#include // std::memcpy + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace odb +{ + // Agent + // + + struct access::object_traits_impl< ::models::Agent, id_sqlite >::extra_statement_cache_type + { + extra_statement_cache_type ( + sqlite::connection&, + image_type&, + id_image_type&, + sqlite::binding&, + sqlite::binding&) + { + } + }; + + access::object_traits_impl< ::models::Agent, id_sqlite >::id_type + access::object_traits_impl< ::models::Agent, id_sqlite >:: + id (const image_type& i) + { + sqlite::database* db (0); + ODB_POTENTIALLY_UNUSED (db); + + id_type id; + { + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + id, + i.id_value, + i.id_size, + i.id_null); + } + + return id; + } + + bool access::object_traits_impl< ::models::Agent, id_sqlite >:: + grow (image_type& i, + bool* t) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (t); + + bool grew (false); + + // id + // + if (t[0UL]) + { + i.id_value.capacity (i.id_size); + grew = true; + } + + // role + // + if (t[1UL]) + { + i.role_value.capacity (i.role_size); + grew = true; + } + + // persistent + // + t[2UL] = false; + + // displayName + // + if (t[3UL]) + { + i.displayName_value.capacity (i.displayName_size); + grew = true; + } + + // trustScore + // + t[4UL] = false; + + return grew; + } + + void access::object_traits_impl< ::models::Agent, id_sqlite >:: + bind (sqlite::bind* b, + image_type& i, + sqlite::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (sk); + + using namespace sqlite; + + std::size_t n (0); + + // id + // + if (sk != statement_update) + { + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.id_value.data (); + b[n].size = &i.id_size; + b[n].capacity = i.id_value.capacity (); + b[n].is_null = &i.id_null; + n++; + } + + // role + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.role_value.data (); + b[n].size = &i.role_size; + b[n].capacity = i.role_value.capacity (); + b[n].is_null = &i.role_null; + n++; + + // persistent + // + b[n].type = sqlite::bind::integer; + b[n].buffer = &i.persistent_value; + b[n].is_null = &i.persistent_null; + n++; + + // displayName + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.displayName_value.data (); + b[n].size = &i.displayName_size; + b[n].capacity = i.displayName_value.capacity (); + b[n].is_null = &i.displayName_null; + n++; + + // trustScore + // + b[n].type = sqlite::bind::integer; + b[n].buffer = &i.trustScore_value; + b[n].is_null = &i.trustScore_null; + n++; + } + + void access::object_traits_impl< ::models::Agent, id_sqlite >:: + bind (sqlite::bind* b, id_image_type& i) + { + std::size_t n (0); + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.id_value.data (); + b[n].size = &i.id_size; + b[n].capacity = i.id_value.capacity (); + b[n].is_null = &i.id_null; + } + + bool access::object_traits_impl< ::models::Agent, id_sqlite >:: + init (image_type& i, + const object_type& o, + sqlite::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (sk); + + using namespace sqlite; + + bool grew (false); + + // id + // + if (sk == statement_insert) + { + ::std::string const& v = + o.id; + + bool is_null (false); + std::size_t cap (i.id_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.id_value, + i.id_size, + is_null, + v); + i.id_null = is_null; + grew = grew || (cap != i.id_value.capacity ()); + } + + // role + // + { + ::std::string const& v = + o.role; + + bool is_null (false); + std::size_t cap (i.role_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.role_value, + i.role_size, + is_null, + v); + i.role_null = is_null; + grew = grew || (cap != i.role_value.capacity ()); + } + + // persistent + // + { + bool const& v = + o.persistent; + + bool is_null (false); + sqlite::value_traits< + bool, + sqlite::id_integer >::set_image ( + i.persistent_value, + is_null, + v); + i.persistent_null = is_null; + } + + // displayName + // + { + ::std::string const& v = + o.displayName; + + bool is_null (false); + std::size_t cap (i.displayName_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.displayName_value, + i.displayName_size, + is_null, + v); + i.displayName_null = is_null; + grew = grew || (cap != i.displayName_value.capacity ()); + } + + // trustScore + // + { + ::int32_t const& v = + o.trustScore; + + bool is_null (false); + sqlite::value_traits< + ::int32_t, + sqlite::id_integer >::set_image ( + i.trustScore_value, + is_null, + v); + i.trustScore_null = is_null; + } + + return grew; + } + + void access::object_traits_impl< ::models::Agent, id_sqlite >:: + init (object_type& o, + const image_type& i, + database* db) + { + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (db); + + // id + // + { + ::std::string& v = + o.id; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.id_value, + i.id_size, + i.id_null); + } + + // role + // + { + ::std::string& v = + o.role; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.role_value, + i.role_size, + i.role_null); + } + + // persistent + // + { + bool& v = + o.persistent; + + sqlite::value_traits< + bool, + sqlite::id_integer >::set_value ( + v, + i.persistent_value, + i.persistent_null); + } + + // displayName + // + { + ::std::string& v = + o.displayName; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.displayName_value, + i.displayName_size, + i.displayName_null); + } + + // trustScore + // + { + ::int32_t& v = + o.trustScore; + + sqlite::value_traits< + ::int32_t, + sqlite::id_integer >::set_value ( + v, + i.trustScore_value, + i.trustScore_null); + } + } + + void access::object_traits_impl< ::models::Agent, id_sqlite >:: + init (id_image_type& i, const id_type& id) + { + bool grew (false); + { + bool is_null (false); + std::size_t cap (i.id_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.id_value, + i.id_size, + is_null, + id); + i.id_null = is_null; + grew = grew || (cap != i.id_value.capacity ()); + } + + if (grew) + i.version++; + } + + const char access::object_traits_impl< ::models::Agent, id_sqlite >::persist_statement[] = + "INSERT INTO \"Agent\" " + "(\"id\", " + "\"role\", " + "\"persistent\", " + "\"displayName\", " + "\"trustScore\") " + "VALUES " + "(?, ?, ?, ?, ?)"; + + const char access::object_traits_impl< ::models::Agent, id_sqlite >::find_statement[] = + "SELECT " + "\"Agent\".\"id\", " + "\"Agent\".\"role\", " + "\"Agent\".\"persistent\", " + "\"Agent\".\"displayName\", " + "\"Agent\".\"trustScore\" " + "FROM \"Agent\" " + "WHERE \"Agent\".\"id\"=?"; + + const char access::object_traits_impl< ::models::Agent, id_sqlite >::update_statement[] = + "UPDATE \"Agent\" " + "SET " + "\"role\"=?, " + "\"persistent\"=?, " + "\"displayName\"=?, " + "\"trustScore\"=? " + "WHERE \"id\"=?"; + + const char access::object_traits_impl< ::models::Agent, id_sqlite >::erase_statement[] = + "DELETE FROM \"Agent\" " + "WHERE \"id\"=?"; + + const char access::object_traits_impl< ::models::Agent, id_sqlite >::query_statement[] = + "SELECT " + "\"Agent\".\"id\", " + "\"Agent\".\"role\", " + "\"Agent\".\"persistent\", " + "\"Agent\".\"displayName\", " + "\"Agent\".\"trustScore\" " + "FROM \"Agent\""; + + const char access::object_traits_impl< ::models::Agent, id_sqlite >::erase_query_statement[] = + "DELETE FROM \"Agent\""; + + const char access::object_traits_impl< ::models::Agent, id_sqlite >::table_name[] = + "\"Agent\""; + + void access::object_traits_impl< ::models::Agent, id_sqlite >:: + persist (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + callback (db, + obj, + callback_event::pre_persist); + + image_type& im (sts.image ()); + binding& imb (sts.insert_image_binding ()); + + if (init (im, obj, statement_insert)) + im.version++; + + if (im.version != sts.insert_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_insert); + sts.insert_image_version (im.version); + imb.version++; + } + + insert_statement& st (sts.persist_statement ()); + if (!st.execute ()) + throw object_already_persistent (); + + callback (db, + obj, + callback_event::post_persist); + } + + void access::object_traits_impl< ::models::Agent, id_sqlite >:: + update (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace sqlite; + using sqlite::update_statement; + + callback (db, obj, callback_event::pre_update); + + sqlite::transaction& tr (sqlite::transaction::current ()); + sqlite::connection& conn (tr.connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + const id_type& id ( + obj.id); + id_image_type& idi (sts.id_image ()); + init (idi, id); + + image_type& im (sts.image ()); + if (init (im, obj, statement_update)) + im.version++; + + bool u (false); + binding& imb (sts.update_image_binding ()); + if (im.version != sts.update_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_update); + sts.update_image_version (im.version); + imb.version++; + u = true; + } + + binding& idb (sts.id_image_binding ()); + if (idi.version != sts.update_id_image_version () || + idb.version == 0) + { + if (idi.version != sts.id_image_version () || + idb.version == 0) + { + bind (idb.bind, idi); + sts.id_image_version (idi.version); + idb.version++; + } + + sts.update_id_image_version (idi.version); + + if (!u) + imb.version++; + } + + update_statement& st (sts.update_statement ()); + if (st.execute () == 0) + throw object_not_persistent (); + + callback (db, obj, callback_event::post_update); + pointer_cache_traits::update (db, obj); + } + + void access::object_traits_impl< ::models::Agent, id_sqlite >:: + erase (database& db, const id_type& id) + { + using namespace sqlite; + + ODB_POTENTIALLY_UNUSED (db); + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + id_image_type& i (sts.id_image ()); + init (i, id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + if (sts.erase_statement ().execute () != 1) + throw object_not_persistent (); + + pointer_cache_traits::erase (db, id); + } + + access::object_traits_impl< ::models::Agent, id_sqlite >::pointer_type + access::object_traits_impl< ::models::Agent, id_sqlite >:: + find (database& db, const id_type& id) + { + using namespace sqlite; + + { + pointer_type p (pointer_cache_traits::find (db, id)); + + if (!pointer_traits::null_ptr (p)) + return p; + } + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (l.locked ()) + { + if (!find_ (sts, &id)) + return pointer_type (); + } + + pointer_type p ( + access::object_factory::create ()); + pointer_traits::guard pg (p); + + pointer_cache_traits::insert_guard ig ( + pointer_cache_traits::insert (db, id, p)); + + object_type& obj (pointer_traits::get_ref (p)); + + if (l.locked ()) + { + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + pointer_cache_traits::load (ig.position ()); + } + else + sts.delay_load (id, obj, ig.position ()); + + ig.release (); + pg.release (); + return p; + } + + bool access::object_traits_impl< ::models::Agent, id_sqlite >:: + find (database& db, const id_type& id, object_type& obj) + { + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + reference_cache_traits::position_type pos ( + reference_cache_traits::insert (db, id, obj)); + reference_cache_traits::insert_guard ig (pos); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + reference_cache_traits::load (pos); + ig.release (); + return true; + } + + bool access::object_traits_impl< ::models::Agent, id_sqlite >:: + reload (database& db, object_type& obj) + { + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + const id_type& id ( + obj.id); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, true); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + return true; + } + + bool access::object_traits_impl< ::models::Agent, id_sqlite >:: + find_ (statements_type& sts, + const id_type* id) + { + using namespace sqlite; + + id_image_type& i (sts.id_image ()); + init (i, *id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + select_statement& st (sts.find_statement ()); + + st.execute (); + auto_result ar (st); + select_statement::result r (st.fetch ()); + + if (r == select_statement::truncated) + { + if (grow (im, sts.select_image_truncated ())) + im.version++; + + if (im.version != sts.select_image_version ()) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + st.refetch (); + } + } + + return r != select_statement::no_data; + } + + result< access::object_traits_impl< ::models::Agent, id_sqlite >::object_type > + access::object_traits_impl< ::models::Agent, id_sqlite >:: + query (database&, const query_base_type& q) + { + using namespace sqlite; + using odb::details::shared; + using odb::details::shared_ptr; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + + statements_type& sts ( + conn.statement_cache ().find_object ()); + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + std::string text (query_statement); + if (!q.empty ()) + { + text += " "; + text += q.clause (); + } + + q.init_parameters (); + shared_ptr st ( + new (shared) select_statement ( + conn, + text, + false, + true, + q.parameters_binding (), + imb)); + + st->execute (); + + shared_ptr< odb::object_result_impl > r ( + new (shared) sqlite::object_result_impl ( + q, st, sts, 0)); + + return result (r); + } + + unsigned long long access::object_traits_impl< ::models::Agent, id_sqlite >:: + erase_query (database&, const query_base_type& q) + { + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + + std::string text (erase_query_statement); + if (!q.empty ()) + { + text += ' '; + text += q.clause (); + } + + q.init_parameters (); + delete_statement st ( + conn, + text, + q.parameters_binding ()); + + return st.execute (); + } +} + +#include diff --git a/db/test-schema-v1.2/generated-sql-ddl/sqlite/Agent-odb.hxx b/db/test-schema-v1.2/generated-sql-ddl/sqlite/Agent-odb.hxx new file mode 100644 index 0000000..08008ee --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/sqlite/Agent-odb.hxx @@ -0,0 +1,342 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#ifndef AGENT_ODB_HXX +#define AGENT_ODB_HXX + +#include + +#if (ODB_VERSION != 20400UL) +#error ODB runtime version mismatch +#endif + +#include + +#include "Agent.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace odb +{ + // Agent + // + template <> + struct class_traits< ::models::Agent > + { + static const class_kind kind = class_object; + }; + + template <> + class access::object_traits< ::models::Agent > + { + public: + typedef ::models::Agent object_type; + typedef ::models::Agent* pointer_type; + typedef odb::pointer_traits pointer_traits; + + static const bool polymorphic = false; + + typedef ::std::string id_type; + + static const bool auto_id = false; + + static const bool abstract = false; + + static id_type + id (const object_type&); + + typedef + no_op_pointer_cache_traits + pointer_cache_traits; + + typedef + no_op_reference_cache_traits + reference_cache_traits; + + static void + callback (database&, object_type&, callback_event); + + static void + callback (database&, const object_type&, callback_event); + }; +} + +#include + +#include +#include +#include +#include +#include + +namespace odb +{ + // Agent + // + template + struct query_columns< ::models::Agent, id_sqlite, A > + { + // id + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + id_type_; + + static const id_type_ id; + + // role + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + role_type_; + + static const role_type_ role; + + // persistent + // + typedef + sqlite::query_column< + sqlite::value_traits< + bool, + sqlite::id_integer >::query_type, + sqlite::id_integer > + persistent_type_; + + static const persistent_type_ persistent; + + // displayName + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + displayName_type_; + + static const displayName_type_ displayName; + + // trustScore + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::int32_t, + sqlite::id_integer >::query_type, + sqlite::id_integer > + trustScore_type_; + + static const trustScore_type_ trustScore; + }; + + template + const typename query_columns< ::models::Agent, id_sqlite, A >::id_type_ + query_columns< ::models::Agent, id_sqlite, A >:: + id (A::table_name, "\"id\"", 0); + + template + const typename query_columns< ::models::Agent, id_sqlite, A >::role_type_ + query_columns< ::models::Agent, id_sqlite, A >:: + role (A::table_name, "\"role\"", 0); + + template + const typename query_columns< ::models::Agent, id_sqlite, A >::persistent_type_ + query_columns< ::models::Agent, id_sqlite, A >:: + persistent (A::table_name, "\"persistent\"", 0); + + template + const typename query_columns< ::models::Agent, id_sqlite, A >::displayName_type_ + query_columns< ::models::Agent, id_sqlite, A >:: + displayName (A::table_name, "\"displayName\"", 0); + + template + const typename query_columns< ::models::Agent, id_sqlite, A >::trustScore_type_ + query_columns< ::models::Agent, id_sqlite, A >:: + trustScore (A::table_name, "\"trustScore\"", 0); + + template + struct pointer_query_columns< ::models::Agent, id_sqlite, A >: + query_columns< ::models::Agent, id_sqlite, A > + { + }; + + template <> + class access::object_traits_impl< ::models::Agent, id_sqlite >: + public access::object_traits< ::models::Agent > + { + public: + struct id_image_type + { + details::buffer id_value; + std::size_t id_size; + bool id_null; + + std::size_t version; + }; + + struct image_type + { + // id + // + details::buffer id_value; + std::size_t id_size; + bool id_null; + + // role + // + details::buffer role_value; + std::size_t role_size; + bool role_null; + + // persistent + // + long long persistent_value; + bool persistent_null; + + // displayName + // + details::buffer displayName_value; + std::size_t displayName_size; + bool displayName_null; + + // trustScore + // + long long trustScore_value; + bool trustScore_null; + + std::size_t version; + }; + + struct extra_statement_cache_type; + + using object_traits::id; + + static id_type + id (const image_type&); + + static bool + grow (image_type&, + bool*); + + static void + bind (sqlite::bind*, + image_type&, + sqlite::statement_kind); + + static void + bind (sqlite::bind*, id_image_type&); + + static bool + init (image_type&, + const object_type&, + sqlite::statement_kind); + + static void + init (object_type&, + const image_type&, + database*); + + static void + init (id_image_type&, const id_type&); + + typedef sqlite::object_statements statements_type; + + typedef sqlite::query_base query_base_type; + + static const std::size_t column_count = 5UL; + static const std::size_t id_column_count = 1UL; + static const std::size_t inverse_column_count = 0UL; + static const std::size_t readonly_column_count = 0UL; + static const std::size_t managed_optimistic_column_count = 0UL; + + static const std::size_t separate_load_column_count = 0UL; + static const std::size_t separate_update_column_count = 0UL; + + static const bool versioned = false; + + static const char persist_statement[]; + static const char find_statement[]; + static const char update_statement[]; + static const char erase_statement[]; + static const char query_statement[]; + static const char erase_query_statement[]; + + static const char table_name[]; + + static void + persist (database&, const object_type&); + + static pointer_type + find (database&, const id_type&); + + static bool + find (database&, const id_type&, object_type&); + + static bool + reload (database&, object_type&); + + static void + update (database&, const object_type&); + + static void + erase (database&, const id_type&); + + static void + erase (database&, const object_type&); + + static result + query (database&, const query_base_type&); + + static unsigned long long + erase_query (database&, const query_base_type&); + + public: + static bool + find_ (statements_type&, + const id_type*); + + static void + load_ (statements_type&, + object_type&, + bool reload); + }; + + template <> + class access::object_traits_impl< ::models::Agent, id_common >: + public access::object_traits_impl< ::models::Agent, id_sqlite > + { + }; + + // Agent + // +} + +#include "Agent-odb.ixx" + +#include + +#endif // AGENT_ODB_HXX diff --git a/db/test-schema-v1.2/generated-sql-ddl/sqlite/Agent-odb.ixx b/db/test-schema-v1.2/generated-sql-ddl/sqlite/Agent-odb.ixx new file mode 100644 index 0000000..8f2b5e1 --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/sqlite/Agent-odb.ixx @@ -0,0 +1,61 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +namespace odb +{ + // Agent + // + + inline + access::object_traits< ::models::Agent >::id_type + access::object_traits< ::models::Agent >:: + id (const object_type& o) + { + return o.id; + } + + inline + void access::object_traits< ::models::Agent >:: + callback (database& db, object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } + + inline + void access::object_traits< ::models::Agent >:: + callback (database& db, const object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } +} + +namespace odb +{ + // Agent + // + + inline + void access::object_traits_impl< ::models::Agent, id_sqlite >:: + erase (database& db, const object_type& obj) + { + callback (db, obj, callback_event::pre_erase); + erase (db, id (obj)); + callback (db, obj, callback_event::post_erase); + } + + inline + void access::object_traits_impl< ::models::Agent, id_sqlite >:: + load_ (statements_type& sts, + object_type& obj, + bool) + { + ODB_POTENTIALLY_UNUSED (sts); + ODB_POTENTIALLY_UNUSED (obj); + } +} + diff --git a/db/test-schema-v1.2/generated-sql-ddl/sqlite/Agent.sql b/db/test-schema-v1.2/generated-sql-ddl/sqlite/Agent.sql new file mode 100644 index 0000000..713603a --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/sqlite/Agent.sql @@ -0,0 +1,25 @@ +/* This file was generated by ODB, object-relational mapping (ORM) + * compiler for C++. + */ + +DROP TABLE IF EXISTS "Agent"; + +CREATE TABLE IF NOT EXISTS "schema_version" ( + "name" TEXT NOT NULL PRIMARY KEY, + "version" INTEGER NOT NULL, + "migration" INTEGER NOT NULL); + +DELETE FROM "schema_version" + WHERE "name" = ''; + +CREATE TABLE "Agent" ( + "id" TEXT NOT NULL PRIMARY KEY, + "role" TEXT NOT NULL, + "persistent" INTEGER NOT NULL, + "displayName" TEXT NOT NULL, + "trustScore" INTEGER NOT NULL); + +INSERT OR IGNORE INTO "schema_version" ( + "name", "version", "migration") + VALUES ('', 2, 0); + diff --git a/db/test-schema-v1.2/generated-sql-ddl/sqlite/GovernmentAddress-002-post.sql b/db/test-schema-v1.2/generated-sql-ddl/sqlite/GovernmentAddress-002-post.sql new file mode 100644 index 0000000..a3c08ed --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/sqlite/GovernmentAddress-002-post.sql @@ -0,0 +1,8 @@ +/* This file was generated by ODB, object-relational mapping (ORM) + * compiler for C++. + */ + +UPDATE "schema_version" + SET "migration" = 0 + WHERE "name" = ''; + diff --git a/db/test-schema-v1.2/generated-sql-ddl/sqlite/GovernmentAddress-002-pre.sql b/db/test-schema-v1.2/generated-sql-ddl/sqlite/GovernmentAddress-002-pre.sql new file mode 100644 index 0000000..6165583 --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/sqlite/GovernmentAddress-002-pre.sql @@ -0,0 +1,13 @@ +/* This file was generated by ODB, object-relational mapping (ORM) + * compiler for C++. + */ + +CREATE TABLE "GovernmentAddress" ( + "id" TEXT NOT NULL PRIMARY KEY, + "addressLabel" TEXT NOT NULL, + "regionLookupKey" TEXT NOT NULL); + +UPDATE "schema_version" + SET "version" = 2, "migration" = 1 + WHERE "name" = ''; + diff --git a/db/test-schema-v1.2/generated-sql-ddl/sqlite/GovernmentAddress-odb.cxx b/db/test-schema-v1.2/generated-sql-ddl/sqlite/GovernmentAddress-odb.cxx new file mode 100644 index 0000000..f5c1a1a --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/sqlite/GovernmentAddress-odb.cxx @@ -0,0 +1,725 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#include + +#include "GovernmentAddress-odb.hxx" + +#include +#include // std::memcpy + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace odb +{ + // GovernmentAddress + // + + struct access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::extra_statement_cache_type + { + extra_statement_cache_type ( + sqlite::connection&, + image_type&, + id_image_type&, + sqlite::binding&, + sqlite::binding&) + { + } + }; + + access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::id_type + access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + id (const image_type& i) + { + sqlite::database* db (0); + ODB_POTENTIALLY_UNUSED (db); + + id_type id; + { + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + id, + i.id_value, + i.id_size, + i.id_null); + } + + return id; + } + + bool access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + grow (image_type& i, + bool* t) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (t); + + bool grew (false); + + // id + // + if (t[0UL]) + { + i.id_value.capacity (i.id_size); + grew = true; + } + + // addressLabel + // + if (t[1UL]) + { + i.addressLabel_value.capacity (i.addressLabel_size); + grew = true; + } + + // regionLookupKey + // + if (t[2UL]) + { + i.regionLookupKey_value.capacity (i.regionLookupKey_size); + grew = true; + } + + return grew; + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + bind (sqlite::bind* b, + image_type& i, + sqlite::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (sk); + + using namespace sqlite; + + std::size_t n (0); + + // id + // + if (sk != statement_update) + { + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.id_value.data (); + b[n].size = &i.id_size; + b[n].capacity = i.id_value.capacity (); + b[n].is_null = &i.id_null; + n++; + } + + // addressLabel + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.addressLabel_value.data (); + b[n].size = &i.addressLabel_size; + b[n].capacity = i.addressLabel_value.capacity (); + b[n].is_null = &i.addressLabel_null; + n++; + + // regionLookupKey + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.regionLookupKey_value.data (); + b[n].size = &i.regionLookupKey_size; + b[n].capacity = i.regionLookupKey_value.capacity (); + b[n].is_null = &i.regionLookupKey_null; + n++; + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + bind (sqlite::bind* b, id_image_type& i) + { + std::size_t n (0); + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.id_value.data (); + b[n].size = &i.id_size; + b[n].capacity = i.id_value.capacity (); + b[n].is_null = &i.id_null; + } + + bool access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + init (image_type& i, + const object_type& o, + sqlite::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (sk); + + using namespace sqlite; + + bool grew (false); + + // id + // + if (sk == statement_insert) + { + ::std::string const& v = + o.id; + + bool is_null (false); + std::size_t cap (i.id_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.id_value, + i.id_size, + is_null, + v); + i.id_null = is_null; + grew = grew || (cap != i.id_value.capacity ()); + } + + // addressLabel + // + { + ::std::string const& v = + o.addressLabel; + + bool is_null (false); + std::size_t cap (i.addressLabel_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.addressLabel_value, + i.addressLabel_size, + is_null, + v); + i.addressLabel_null = is_null; + grew = grew || (cap != i.addressLabel_value.capacity ()); + } + + // regionLookupKey + // + { + ::std::string const& v = + o.regionLookupKey; + + bool is_null (false); + std::size_t cap (i.regionLookupKey_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.regionLookupKey_value, + i.regionLookupKey_size, + is_null, + v); + i.regionLookupKey_null = is_null; + grew = grew || (cap != i.regionLookupKey_value.capacity ()); + } + + return grew; + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + init (object_type& o, + const image_type& i, + database* db) + { + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (db); + + // id + // + { + ::std::string& v = + o.id; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.id_value, + i.id_size, + i.id_null); + } + + // addressLabel + // + { + ::std::string& v = + o.addressLabel; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.addressLabel_value, + i.addressLabel_size, + i.addressLabel_null); + } + + // regionLookupKey + // + { + ::std::string& v = + o.regionLookupKey; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.regionLookupKey_value, + i.regionLookupKey_size, + i.regionLookupKey_null); + } + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + init (id_image_type& i, const id_type& id) + { + bool grew (false); + { + bool is_null (false); + std::size_t cap (i.id_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.id_value, + i.id_size, + is_null, + id); + i.id_null = is_null; + grew = grew || (cap != i.id_value.capacity ()); + } + + if (grew) + i.version++; + } + + const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::persist_statement[] = + "INSERT INTO \"GovernmentAddress\" " + "(\"id\", " + "\"addressLabel\", " + "\"regionLookupKey\") " + "VALUES " + "(?, ?, ?)"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::find_statement[] = + "SELECT " + "\"GovernmentAddress\".\"id\", " + "\"GovernmentAddress\".\"addressLabel\", " + "\"GovernmentAddress\".\"regionLookupKey\" " + "FROM \"GovernmentAddress\" " + "WHERE \"GovernmentAddress\".\"id\"=?"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::update_statement[] = + "UPDATE \"GovernmentAddress\" " + "SET " + "\"addressLabel\"=?, " + "\"regionLookupKey\"=? " + "WHERE \"id\"=?"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::erase_statement[] = + "DELETE FROM \"GovernmentAddress\" " + "WHERE \"id\"=?"; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::query_statement[] = + "SELECT " + "\"GovernmentAddress\".\"id\", " + "\"GovernmentAddress\".\"addressLabel\", " + "\"GovernmentAddress\".\"regionLookupKey\" " + "FROM \"GovernmentAddress\""; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::erase_query_statement[] = + "DELETE FROM \"GovernmentAddress\""; + + const char access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::table_name[] = + "\"GovernmentAddress\""; + + void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + persist (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + callback (db, + obj, + callback_event::pre_persist); + + image_type& im (sts.image ()); + binding& imb (sts.insert_image_binding ()); + + if (init (im, obj, statement_insert)) + im.version++; + + if (im.version != sts.insert_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_insert); + sts.insert_image_version (im.version); + imb.version++; + } + + insert_statement& st (sts.persist_statement ()); + if (!st.execute ()) + throw object_already_persistent (); + + callback (db, + obj, + callback_event::post_persist); + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + update (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace sqlite; + using sqlite::update_statement; + + callback (db, obj, callback_event::pre_update); + + sqlite::transaction& tr (sqlite::transaction::current ()); + sqlite::connection& conn (tr.connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + const id_type& id ( + obj.id); + id_image_type& idi (sts.id_image ()); + init (idi, id); + + image_type& im (sts.image ()); + if (init (im, obj, statement_update)) + im.version++; + + bool u (false); + binding& imb (sts.update_image_binding ()); + if (im.version != sts.update_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_update); + sts.update_image_version (im.version); + imb.version++; + u = true; + } + + binding& idb (sts.id_image_binding ()); + if (idi.version != sts.update_id_image_version () || + idb.version == 0) + { + if (idi.version != sts.id_image_version () || + idb.version == 0) + { + bind (idb.bind, idi); + sts.id_image_version (idi.version); + idb.version++; + } + + sts.update_id_image_version (idi.version); + + if (!u) + imb.version++; + } + + update_statement& st (sts.update_statement ()); + if (st.execute () == 0) + throw object_not_persistent (); + + callback (db, obj, callback_event::post_update); + pointer_cache_traits::update (db, obj); + } + + void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + erase (database& db, const id_type& id) + { + using namespace sqlite; + + ODB_POTENTIALLY_UNUSED (db); + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + id_image_type& i (sts.id_image ()); + init (i, id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + if (sts.erase_statement ().execute () != 1) + throw object_not_persistent (); + + pointer_cache_traits::erase (db, id); + } + + access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::pointer_type + access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + find (database& db, const id_type& id) + { + using namespace sqlite; + + { + pointer_type p (pointer_cache_traits::find (db, id)); + + if (!pointer_traits::null_ptr (p)) + return p; + } + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (l.locked ()) + { + if (!find_ (sts, &id)) + return pointer_type (); + } + + pointer_type p ( + access::object_factory::create ()); + pointer_traits::guard pg (p); + + pointer_cache_traits::insert_guard ig ( + pointer_cache_traits::insert (db, id, p)); + + object_type& obj (pointer_traits::get_ref (p)); + + if (l.locked ()) + { + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + pointer_cache_traits::load (ig.position ()); + } + else + sts.delay_load (id, obj, ig.position ()); + + ig.release (); + pg.release (); + return p; + } + + bool access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + find (database& db, const id_type& id, object_type& obj) + { + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + reference_cache_traits::position_type pos ( + reference_cache_traits::insert (db, id, obj)); + reference_cache_traits::insert_guard ig (pos); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + reference_cache_traits::load (pos); + ig.release (); + return true; + } + + bool access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + reload (database& db, object_type& obj) + { + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + const id_type& id ( + obj.id); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, true); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + return true; + } + + bool access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + find_ (statements_type& sts, + const id_type* id) + { + using namespace sqlite; + + id_image_type& i (sts.id_image ()); + init (i, *id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + select_statement& st (sts.find_statement ()); + + st.execute (); + auto_result ar (st); + select_statement::result r (st.fetch ()); + + if (r == select_statement::truncated) + { + if (grow (im, sts.select_image_truncated ())) + im.version++; + + if (im.version != sts.select_image_version ()) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + st.refetch (); + } + } + + return r != select_statement::no_data; + } + + result< access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >::object_type > + access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + query (database&, const query_base_type& q) + { + using namespace sqlite; + using odb::details::shared; + using odb::details::shared_ptr; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + + statements_type& sts ( + conn.statement_cache ().find_object ()); + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + std::string text (query_statement); + if (!q.empty ()) + { + text += " "; + text += q.clause (); + } + + q.init_parameters (); + shared_ptr st ( + new (shared) select_statement ( + conn, + text, + false, + true, + q.parameters_binding (), + imb)); + + st->execute (); + + shared_ptr< odb::object_result_impl > r ( + new (shared) sqlite::object_result_impl ( + q, st, sts, 0)); + + return result (r); + } + + unsigned long long access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + erase_query (database&, const query_base_type& q) + { + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + + std::string text (erase_query_statement); + if (!q.empty ()) + { + text += ' '; + text += q.clause (); + } + + q.init_parameters (); + delete_statement st ( + conn, + text, + q.parameters_binding ()); + + return st.execute (); + } +} + +#include diff --git a/db/test-schema-v1.2/generated-sql-ddl/sqlite/GovernmentAddress-odb.hxx b/db/test-schema-v1.2/generated-sql-ddl/sqlite/GovernmentAddress-odb.hxx new file mode 100644 index 0000000..52d8158 --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/sqlite/GovernmentAddress-odb.hxx @@ -0,0 +1,298 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#ifndef GOVERNMENT_ADDRESS_ODB_HXX +#define GOVERNMENT_ADDRESS_ODB_HXX + +#include + +#if (ODB_VERSION != 20400UL) +#error ODB runtime version mismatch +#endif + +#include + +#include "GovernmentAddress.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace odb +{ + // GovernmentAddress + // + template <> + struct class_traits< ::models::GovernmentAddress > + { + static const class_kind kind = class_object; + }; + + template <> + class access::object_traits< ::models::GovernmentAddress > + { + public: + typedef ::models::GovernmentAddress object_type; + typedef ::models::GovernmentAddress* pointer_type; + typedef odb::pointer_traits pointer_traits; + + static const bool polymorphic = false; + + typedef ::std::string id_type; + + static const bool auto_id = false; + + static const bool abstract = false; + + static id_type + id (const object_type&); + + typedef + no_op_pointer_cache_traits + pointer_cache_traits; + + typedef + no_op_reference_cache_traits + reference_cache_traits; + + static void + callback (database&, object_type&, callback_event); + + static void + callback (database&, const object_type&, callback_event); + }; +} + +#include + +#include +#include +#include +#include +#include + +namespace odb +{ + // GovernmentAddress + // + template + struct query_columns< ::models::GovernmentAddress, id_sqlite, A > + { + // id + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + id_type_; + + static const id_type_ id; + + // addressLabel + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + addressLabel_type_; + + static const addressLabel_type_ addressLabel; + + // regionLookupKey + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + regionLookupKey_type_; + + static const regionLookupKey_type_ regionLookupKey; + }; + + template + const typename query_columns< ::models::GovernmentAddress, id_sqlite, A >::id_type_ + query_columns< ::models::GovernmentAddress, id_sqlite, A >:: + id (A::table_name, "\"id\"", 0); + + template + const typename query_columns< ::models::GovernmentAddress, id_sqlite, A >::addressLabel_type_ + query_columns< ::models::GovernmentAddress, id_sqlite, A >:: + addressLabel (A::table_name, "\"addressLabel\"", 0); + + template + const typename query_columns< ::models::GovernmentAddress, id_sqlite, A >::regionLookupKey_type_ + query_columns< ::models::GovernmentAddress, id_sqlite, A >:: + regionLookupKey (A::table_name, "\"regionLookupKey\"", 0); + + template + struct pointer_query_columns< ::models::GovernmentAddress, id_sqlite, A >: + query_columns< ::models::GovernmentAddress, id_sqlite, A > + { + }; + + template <> + class access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >: + public access::object_traits< ::models::GovernmentAddress > + { + public: + struct id_image_type + { + details::buffer id_value; + std::size_t id_size; + bool id_null; + + std::size_t version; + }; + + struct image_type + { + // id + // + details::buffer id_value; + std::size_t id_size; + bool id_null; + + // addressLabel + // + details::buffer addressLabel_value; + std::size_t addressLabel_size; + bool addressLabel_null; + + // regionLookupKey + // + details::buffer regionLookupKey_value; + std::size_t regionLookupKey_size; + bool regionLookupKey_null; + + std::size_t version; + }; + + struct extra_statement_cache_type; + + using object_traits::id; + + static id_type + id (const image_type&); + + static bool + grow (image_type&, + bool*); + + static void + bind (sqlite::bind*, + image_type&, + sqlite::statement_kind); + + static void + bind (sqlite::bind*, id_image_type&); + + static bool + init (image_type&, + const object_type&, + sqlite::statement_kind); + + static void + init (object_type&, + const image_type&, + database*); + + static void + init (id_image_type&, const id_type&); + + typedef sqlite::object_statements statements_type; + + typedef sqlite::query_base query_base_type; + + static const std::size_t column_count = 3UL; + static const std::size_t id_column_count = 1UL; + static const std::size_t inverse_column_count = 0UL; + static const std::size_t readonly_column_count = 0UL; + static const std::size_t managed_optimistic_column_count = 0UL; + + static const std::size_t separate_load_column_count = 0UL; + static const std::size_t separate_update_column_count = 0UL; + + static const bool versioned = false; + + static const char persist_statement[]; + static const char find_statement[]; + static const char update_statement[]; + static const char erase_statement[]; + static const char query_statement[]; + static const char erase_query_statement[]; + + static const char table_name[]; + + static void + persist (database&, const object_type&); + + static pointer_type + find (database&, const id_type&); + + static bool + find (database&, const id_type&, object_type&); + + static bool + reload (database&, object_type&); + + static void + update (database&, const object_type&); + + static void + erase (database&, const id_type&); + + static void + erase (database&, const object_type&); + + static result + query (database&, const query_base_type&); + + static unsigned long long + erase_query (database&, const query_base_type&); + + public: + static bool + find_ (statements_type&, + const id_type*); + + static void + load_ (statements_type&, + object_type&, + bool reload); + }; + + template <> + class access::object_traits_impl< ::models::GovernmentAddress, id_common >: + public access::object_traits_impl< ::models::GovernmentAddress, id_sqlite > + { + }; + + // GovernmentAddress + // +} + +#include "GovernmentAddress-odb.ixx" + +#include + +#endif // GOVERNMENT_ADDRESS_ODB_HXX diff --git a/db/test-schema-v1.2/generated-sql-ddl/sqlite/GovernmentAddress-odb.ixx b/db/test-schema-v1.2/generated-sql-ddl/sqlite/GovernmentAddress-odb.ixx new file mode 100644 index 0000000..932bbcf --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/sqlite/GovernmentAddress-odb.ixx @@ -0,0 +1,61 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +namespace odb +{ + // GovernmentAddress + // + + inline + access::object_traits< ::models::GovernmentAddress >::id_type + access::object_traits< ::models::GovernmentAddress >:: + id (const object_type& o) + { + return o.id; + } + + inline + void access::object_traits< ::models::GovernmentAddress >:: + callback (database& db, object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } + + inline + void access::object_traits< ::models::GovernmentAddress >:: + callback (database& db, const object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } +} + +namespace odb +{ + // GovernmentAddress + // + + inline + void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + erase (database& db, const object_type& obj) + { + callback (db, obj, callback_event::pre_erase); + erase (db, id (obj)); + callback (db, obj, callback_event::post_erase); + } + + inline + void access::object_traits_impl< ::models::GovernmentAddress, id_sqlite >:: + load_ (statements_type& sts, + object_type& obj, + bool) + { + ODB_POTENTIALLY_UNUSED (sts); + ODB_POTENTIALLY_UNUSED (obj); + } +} + diff --git a/db/test-schema-v1.2/generated-sql-ddl/sqlite/GovernmentAddress.sql b/db/test-schema-v1.2/generated-sql-ddl/sqlite/GovernmentAddress.sql new file mode 100644 index 0000000..ac64f3d --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/sqlite/GovernmentAddress.sql @@ -0,0 +1,23 @@ +/* This file was generated by ODB, object-relational mapping (ORM) + * compiler for C++. + */ + +DROP TABLE IF EXISTS "GovernmentAddress"; + +CREATE TABLE IF NOT EXISTS "schema_version" ( + "name" TEXT NOT NULL PRIMARY KEY, + "version" INTEGER NOT NULL, + "migration" INTEGER NOT NULL); + +DELETE FROM "schema_version" + WHERE "name" = ''; + +CREATE TABLE "GovernmentAddress" ( + "id" TEXT NOT NULL PRIMARY KEY, + "addressLabel" TEXT NOT NULL, + "regionLookupKey" TEXT NOT NULL); + +INSERT OR IGNORE INTO "schema_version" ( + "name", "version", "migration") + VALUES ('', 2, 0); + diff --git a/db/test-schema-v1.2/generated-sql-ddl/sqlite/TripAttemptResult-002-post.sql b/db/test-schema-v1.2/generated-sql-ddl/sqlite/TripAttemptResult-002-post.sql new file mode 100644 index 0000000..a3c08ed --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/sqlite/TripAttemptResult-002-post.sql @@ -0,0 +1,8 @@ +/* This file was generated by ODB, object-relational mapping (ORM) + * compiler for C++. + */ + +UPDATE "schema_version" + SET "migration" = 0 + WHERE "name" = ''; + diff --git a/db/test-schema-v1.2/generated-sql-ddl/sqlite/TripAttemptResult-002-pre.sql b/db/test-schema-v1.2/generated-sql-ddl/sqlite/TripAttemptResult-002-pre.sql new file mode 100644 index 0000000..9d1d52d --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/sqlite/TripAttemptResult-002-pre.sql @@ -0,0 +1,22 @@ +/* This file was generated by ODB, object-relational mapping (ORM) + * compiler for C++. + */ + +CREATE TABLE "TripAttemptResult" ( + "id" TEXT NOT NULL PRIMARY KEY, + "result" TEXT NOT NULL, + "retryReason" TEXT NOT NULL, + "governmentSuspensionReason" TEXT NOT NULL, + "governmentTerminationReason" TEXT NOT NULL, + "complianceSuspensionReason" TEXT NOT NULL, + "complianceTerminationReason" TEXT NOT NULL, + "policySuspensionReason" TEXT NOT NULL, + "policyTerminationReason" TEXT NOT NULL, + "cancelationReason" TEXT NOT NULL, + "failureReason" TEXT NOT NULL, + "details" TEXT NOT NULL); + +UPDATE "schema_version" + SET "version" = 2, "migration" = 1 + WHERE "name" = ''; + diff --git a/db/test-schema-v1.2/generated-sql-ddl/sqlite/TripAttemptResult-odb.cxx b/db/test-schema-v1.2/generated-sql-ddl/sqlite/TripAttemptResult-odb.cxx new file mode 100644 index 0000000..44e4bfc --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/sqlite/TripAttemptResult-odb.cxx @@ -0,0 +1,1238 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#include + +#include "TripAttemptResult-odb.hxx" + +#include +#include // std::memcpy + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace odb +{ + // TripAttemptResult + // + + struct access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::extra_statement_cache_type + { + extra_statement_cache_type ( + sqlite::connection&, + image_type&, + id_image_type&, + sqlite::binding&, + sqlite::binding&) + { + } + }; + + access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::id_type + access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + id (const image_type& i) + { + sqlite::database* db (0); + ODB_POTENTIALLY_UNUSED (db); + + id_type id; + { + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + id, + i.id_value, + i.id_size, + i.id_null); + } + + return id; + } + + bool access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + grow (image_type& i, + bool* t) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (t); + + bool grew (false); + + // id + // + if (t[0UL]) + { + i.id_value.capacity (i.id_size); + grew = true; + } + + // result + // + if (t[1UL]) + { + i.result_value.capacity (i.result_size); + grew = true; + } + + // retryReason + // + if (t[2UL]) + { + i.retryReason_value.capacity (i.retryReason_size); + grew = true; + } + + // governmentSuspensionReason + // + if (t[3UL]) + { + i.governmentSuspensionReason_value.capacity (i.governmentSuspensionReason_size); + grew = true; + } + + // governmentTerminationReason + // + if (t[4UL]) + { + i.governmentTerminationReason_value.capacity (i.governmentTerminationReason_size); + grew = true; + } + + // complianceSuspensionReason + // + if (t[5UL]) + { + i.complianceSuspensionReason_value.capacity (i.complianceSuspensionReason_size); + grew = true; + } + + // complianceTerminationReason + // + if (t[6UL]) + { + i.complianceTerminationReason_value.capacity (i.complianceTerminationReason_size); + grew = true; + } + + // policySuspensionReason + // + if (t[7UL]) + { + i.policySuspensionReason_value.capacity (i.policySuspensionReason_size); + grew = true; + } + + // policyTerminationReason + // + if (t[8UL]) + { + i.policyTerminationReason_value.capacity (i.policyTerminationReason_size); + grew = true; + } + + // cancelationReason + // + if (t[9UL]) + { + i.cancelationReason_value.capacity (i.cancelationReason_size); + grew = true; + } + + // failureReason + // + if (t[10UL]) + { + i.failureReason_value.capacity (i.failureReason_size); + grew = true; + } + + // details + // + if (t[11UL]) + { + i.details_value.capacity (i.details_size); + grew = true; + } + + return grew; + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + bind (sqlite::bind* b, + image_type& i, + sqlite::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (sk); + + using namespace sqlite; + + std::size_t n (0); + + // id + // + if (sk != statement_update) + { + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.id_value.data (); + b[n].size = &i.id_size; + b[n].capacity = i.id_value.capacity (); + b[n].is_null = &i.id_null; + n++; + } + + // result + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.result_value.data (); + b[n].size = &i.result_size; + b[n].capacity = i.result_value.capacity (); + b[n].is_null = &i.result_null; + n++; + + // retryReason + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.retryReason_value.data (); + b[n].size = &i.retryReason_size; + b[n].capacity = i.retryReason_value.capacity (); + b[n].is_null = &i.retryReason_null; + n++; + + // governmentSuspensionReason + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.governmentSuspensionReason_value.data (); + b[n].size = &i.governmentSuspensionReason_size; + b[n].capacity = i.governmentSuspensionReason_value.capacity (); + b[n].is_null = &i.governmentSuspensionReason_null; + n++; + + // governmentTerminationReason + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.governmentTerminationReason_value.data (); + b[n].size = &i.governmentTerminationReason_size; + b[n].capacity = i.governmentTerminationReason_value.capacity (); + b[n].is_null = &i.governmentTerminationReason_null; + n++; + + // complianceSuspensionReason + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.complianceSuspensionReason_value.data (); + b[n].size = &i.complianceSuspensionReason_size; + b[n].capacity = i.complianceSuspensionReason_value.capacity (); + b[n].is_null = &i.complianceSuspensionReason_null; + n++; + + // complianceTerminationReason + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.complianceTerminationReason_value.data (); + b[n].size = &i.complianceTerminationReason_size; + b[n].capacity = i.complianceTerminationReason_value.capacity (); + b[n].is_null = &i.complianceTerminationReason_null; + n++; + + // policySuspensionReason + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.policySuspensionReason_value.data (); + b[n].size = &i.policySuspensionReason_size; + b[n].capacity = i.policySuspensionReason_value.capacity (); + b[n].is_null = &i.policySuspensionReason_null; + n++; + + // policyTerminationReason + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.policyTerminationReason_value.data (); + b[n].size = &i.policyTerminationReason_size; + b[n].capacity = i.policyTerminationReason_value.capacity (); + b[n].is_null = &i.policyTerminationReason_null; + n++; + + // cancelationReason + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.cancelationReason_value.data (); + b[n].size = &i.cancelationReason_size; + b[n].capacity = i.cancelationReason_value.capacity (); + b[n].is_null = &i.cancelationReason_null; + n++; + + // failureReason + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.failureReason_value.data (); + b[n].size = &i.failureReason_size; + b[n].capacity = i.failureReason_value.capacity (); + b[n].is_null = &i.failureReason_null; + n++; + + // details + // + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.details_value.data (); + b[n].size = &i.details_size; + b[n].capacity = i.details_value.capacity (); + b[n].is_null = &i.details_null; + n++; + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + bind (sqlite::bind* b, id_image_type& i) + { + std::size_t n (0); + b[n].type = sqlite::image_traits< + ::std::string, + sqlite::id_text>::bind_value; + b[n].buffer = i.id_value.data (); + b[n].size = &i.id_size; + b[n].capacity = i.id_value.capacity (); + b[n].is_null = &i.id_null; + } + + bool access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + init (image_type& i, + const object_type& o, + sqlite::statement_kind sk) + { + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (sk); + + using namespace sqlite; + + bool grew (false); + + // id + // + if (sk == statement_insert) + { + ::std::string const& v = + o.id; + + bool is_null (false); + std::size_t cap (i.id_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.id_value, + i.id_size, + is_null, + v); + i.id_null = is_null; + grew = grew || (cap != i.id_value.capacity ()); + } + + // result + // + { + ::std::string const& v = + o.result; + + bool is_null (false); + std::size_t cap (i.result_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.result_value, + i.result_size, + is_null, + v); + i.result_null = is_null; + grew = grew || (cap != i.result_value.capacity ()); + } + + // retryReason + // + { + ::std::string const& v = + o.retryReason; + + bool is_null (false); + std::size_t cap (i.retryReason_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.retryReason_value, + i.retryReason_size, + is_null, + v); + i.retryReason_null = is_null; + grew = grew || (cap != i.retryReason_value.capacity ()); + } + + // governmentSuspensionReason + // + { + ::std::string const& v = + o.governmentSuspensionReason; + + bool is_null (false); + std::size_t cap (i.governmentSuspensionReason_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.governmentSuspensionReason_value, + i.governmentSuspensionReason_size, + is_null, + v); + i.governmentSuspensionReason_null = is_null; + grew = grew || (cap != i.governmentSuspensionReason_value.capacity ()); + } + + // governmentTerminationReason + // + { + ::std::string const& v = + o.governmentTerminationReason; + + bool is_null (false); + std::size_t cap (i.governmentTerminationReason_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.governmentTerminationReason_value, + i.governmentTerminationReason_size, + is_null, + v); + i.governmentTerminationReason_null = is_null; + grew = grew || (cap != i.governmentTerminationReason_value.capacity ()); + } + + // complianceSuspensionReason + // + { + ::std::string const& v = + o.complianceSuspensionReason; + + bool is_null (false); + std::size_t cap (i.complianceSuspensionReason_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.complianceSuspensionReason_value, + i.complianceSuspensionReason_size, + is_null, + v); + i.complianceSuspensionReason_null = is_null; + grew = grew || (cap != i.complianceSuspensionReason_value.capacity ()); + } + + // complianceTerminationReason + // + { + ::std::string const& v = + o.complianceTerminationReason; + + bool is_null (false); + std::size_t cap (i.complianceTerminationReason_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.complianceTerminationReason_value, + i.complianceTerminationReason_size, + is_null, + v); + i.complianceTerminationReason_null = is_null; + grew = grew || (cap != i.complianceTerminationReason_value.capacity ()); + } + + // policySuspensionReason + // + { + ::std::string const& v = + o.policySuspensionReason; + + bool is_null (false); + std::size_t cap (i.policySuspensionReason_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.policySuspensionReason_value, + i.policySuspensionReason_size, + is_null, + v); + i.policySuspensionReason_null = is_null; + grew = grew || (cap != i.policySuspensionReason_value.capacity ()); + } + + // policyTerminationReason + // + { + ::std::string const& v = + o.policyTerminationReason; + + bool is_null (false); + std::size_t cap (i.policyTerminationReason_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.policyTerminationReason_value, + i.policyTerminationReason_size, + is_null, + v); + i.policyTerminationReason_null = is_null; + grew = grew || (cap != i.policyTerminationReason_value.capacity ()); + } + + // cancelationReason + // + { + ::std::string const& v = + o.cancelationReason; + + bool is_null (false); + std::size_t cap (i.cancelationReason_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.cancelationReason_value, + i.cancelationReason_size, + is_null, + v); + i.cancelationReason_null = is_null; + grew = grew || (cap != i.cancelationReason_value.capacity ()); + } + + // failureReason + // + { + ::std::string const& v = + o.failureReason; + + bool is_null (false); + std::size_t cap (i.failureReason_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.failureReason_value, + i.failureReason_size, + is_null, + v); + i.failureReason_null = is_null; + grew = grew || (cap != i.failureReason_value.capacity ()); + } + + // details + // + { + ::std::string const& v = + o.details; + + bool is_null (false); + std::size_t cap (i.details_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.details_value, + i.details_size, + is_null, + v); + i.details_null = is_null; + grew = grew || (cap != i.details_value.capacity ()); + } + + return grew; + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + init (object_type& o, + const image_type& i, + database* db) + { + ODB_POTENTIALLY_UNUSED (o); + ODB_POTENTIALLY_UNUSED (i); + ODB_POTENTIALLY_UNUSED (db); + + // id + // + { + ::std::string& v = + o.id; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.id_value, + i.id_size, + i.id_null); + } + + // result + // + { + ::std::string& v = + o.result; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.result_value, + i.result_size, + i.result_null); + } + + // retryReason + // + { + ::std::string& v = + o.retryReason; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.retryReason_value, + i.retryReason_size, + i.retryReason_null); + } + + // governmentSuspensionReason + // + { + ::std::string& v = + o.governmentSuspensionReason; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.governmentSuspensionReason_value, + i.governmentSuspensionReason_size, + i.governmentSuspensionReason_null); + } + + // governmentTerminationReason + // + { + ::std::string& v = + o.governmentTerminationReason; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.governmentTerminationReason_value, + i.governmentTerminationReason_size, + i.governmentTerminationReason_null); + } + + // complianceSuspensionReason + // + { + ::std::string& v = + o.complianceSuspensionReason; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.complianceSuspensionReason_value, + i.complianceSuspensionReason_size, + i.complianceSuspensionReason_null); + } + + // complianceTerminationReason + // + { + ::std::string& v = + o.complianceTerminationReason; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.complianceTerminationReason_value, + i.complianceTerminationReason_size, + i.complianceTerminationReason_null); + } + + // policySuspensionReason + // + { + ::std::string& v = + o.policySuspensionReason; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.policySuspensionReason_value, + i.policySuspensionReason_size, + i.policySuspensionReason_null); + } + + // policyTerminationReason + // + { + ::std::string& v = + o.policyTerminationReason; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.policyTerminationReason_value, + i.policyTerminationReason_size, + i.policyTerminationReason_null); + } + + // cancelationReason + // + { + ::std::string& v = + o.cancelationReason; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.cancelationReason_value, + i.cancelationReason_size, + i.cancelationReason_null); + } + + // failureReason + // + { + ::std::string& v = + o.failureReason; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.failureReason_value, + i.failureReason_size, + i.failureReason_null); + } + + // details + // + { + ::std::string& v = + o.details; + + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_value ( + v, + i.details_value, + i.details_size, + i.details_null); + } + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + init (id_image_type& i, const id_type& id) + { + bool grew (false); + { + bool is_null (false); + std::size_t cap (i.id_value.capacity ()); + sqlite::value_traits< + ::std::string, + sqlite::id_text >::set_image ( + i.id_value, + i.id_size, + is_null, + id); + i.id_null = is_null; + grew = grew || (cap != i.id_value.capacity ()); + } + + if (grew) + i.version++; + } + + const char access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::persist_statement[] = + "INSERT INTO \"TripAttemptResult\" " + "(\"id\", " + "\"result\", " + "\"retryReason\", " + "\"governmentSuspensionReason\", " + "\"governmentTerminationReason\", " + "\"complianceSuspensionReason\", " + "\"complianceTerminationReason\", " + "\"policySuspensionReason\", " + "\"policyTerminationReason\", " + "\"cancelationReason\", " + "\"failureReason\", " + "\"details\") " + "VALUES " + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::find_statement[] = + "SELECT " + "\"TripAttemptResult\".\"id\", " + "\"TripAttemptResult\".\"result\", " + "\"TripAttemptResult\".\"retryReason\", " + "\"TripAttemptResult\".\"governmentSuspensionReason\", " + "\"TripAttemptResult\".\"governmentTerminationReason\", " + "\"TripAttemptResult\".\"complianceSuspensionReason\", " + "\"TripAttemptResult\".\"complianceTerminationReason\", " + "\"TripAttemptResult\".\"policySuspensionReason\", " + "\"TripAttemptResult\".\"policyTerminationReason\", " + "\"TripAttemptResult\".\"cancelationReason\", " + "\"TripAttemptResult\".\"failureReason\", " + "\"TripAttemptResult\".\"details\" " + "FROM \"TripAttemptResult\" " + "WHERE \"TripAttemptResult\".\"id\"=?"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::update_statement[] = + "UPDATE \"TripAttemptResult\" " + "SET " + "\"result\"=?, " + "\"retryReason\"=?, " + "\"governmentSuspensionReason\"=?, " + "\"governmentTerminationReason\"=?, " + "\"complianceSuspensionReason\"=?, " + "\"complianceTerminationReason\"=?, " + "\"policySuspensionReason\"=?, " + "\"policyTerminationReason\"=?, " + "\"cancelationReason\"=?, " + "\"failureReason\"=?, " + "\"details\"=? " + "WHERE \"id\"=?"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::erase_statement[] = + "DELETE FROM \"TripAttemptResult\" " + "WHERE \"id\"=?"; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::query_statement[] = + "SELECT " + "\"TripAttemptResult\".\"id\", " + "\"TripAttemptResult\".\"result\", " + "\"TripAttemptResult\".\"retryReason\", " + "\"TripAttemptResult\".\"governmentSuspensionReason\", " + "\"TripAttemptResult\".\"governmentTerminationReason\", " + "\"TripAttemptResult\".\"complianceSuspensionReason\", " + "\"TripAttemptResult\".\"complianceTerminationReason\", " + "\"TripAttemptResult\".\"policySuspensionReason\", " + "\"TripAttemptResult\".\"policyTerminationReason\", " + "\"TripAttemptResult\".\"cancelationReason\", " + "\"TripAttemptResult\".\"failureReason\", " + "\"TripAttemptResult\".\"details\" " + "FROM \"TripAttemptResult\""; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::erase_query_statement[] = + "DELETE FROM \"TripAttemptResult\""; + + const char access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::table_name[] = + "\"TripAttemptResult\""; + + void access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + persist (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + callback (db, + obj, + callback_event::pre_persist); + + image_type& im (sts.image ()); + binding& imb (sts.insert_image_binding ()); + + if (init (im, obj, statement_insert)) + im.version++; + + if (im.version != sts.insert_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_insert); + sts.insert_image_version (im.version); + imb.version++; + } + + insert_statement& st (sts.persist_statement ()); + if (!st.execute ()) + throw object_already_persistent (); + + callback (db, + obj, + callback_event::post_persist); + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + update (database& db, const object_type& obj) + { + ODB_POTENTIALLY_UNUSED (db); + + using namespace sqlite; + using sqlite::update_statement; + + callback (db, obj, callback_event::pre_update); + + sqlite::transaction& tr (sqlite::transaction::current ()); + sqlite::connection& conn (tr.connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + const id_type& id ( + obj.id); + id_image_type& idi (sts.id_image ()); + init (idi, id); + + image_type& im (sts.image ()); + if (init (im, obj, statement_update)) + im.version++; + + bool u (false); + binding& imb (sts.update_image_binding ()); + if (im.version != sts.update_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_update); + sts.update_image_version (im.version); + imb.version++; + u = true; + } + + binding& idb (sts.id_image_binding ()); + if (idi.version != sts.update_id_image_version () || + idb.version == 0) + { + if (idi.version != sts.id_image_version () || + idb.version == 0) + { + bind (idb.bind, idi); + sts.id_image_version (idi.version); + idb.version++; + } + + sts.update_id_image_version (idi.version); + + if (!u) + imb.version++; + } + + update_statement& st (sts.update_statement ()); + if (st.execute () == 0) + throw object_not_persistent (); + + callback (db, obj, callback_event::post_update); + pointer_cache_traits::update (db, obj); + } + + void access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + erase (database& db, const id_type& id) + { + using namespace sqlite; + + ODB_POTENTIALLY_UNUSED (db); + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + id_image_type& i (sts.id_image ()); + init (i, id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + if (sts.erase_statement ().execute () != 1) + throw object_not_persistent (); + + pointer_cache_traits::erase (db, id); + } + + access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::pointer_type + access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + find (database& db, const id_type& id) + { + using namespace sqlite; + + { + pointer_type p (pointer_cache_traits::find (db, id)); + + if (!pointer_traits::null_ptr (p)) + return p; + } + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (l.locked ()) + { + if (!find_ (sts, &id)) + return pointer_type (); + } + + pointer_type p ( + access::object_factory::create ()); + pointer_traits::guard pg (p); + + pointer_cache_traits::insert_guard ig ( + pointer_cache_traits::insert (db, id, p)); + + object_type& obj (pointer_traits::get_ref (p)); + + if (l.locked ()) + { + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + pointer_cache_traits::load (ig.position ()); + } + else + sts.delay_load (id, obj, ig.position ()); + + ig.release (); + pg.release (); + return p; + } + + bool access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + find (database& db, const id_type& id, object_type& obj) + { + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + reference_cache_traits::position_type pos ( + reference_cache_traits::insert (db, id, obj)); + reference_cache_traits::insert_guard ig (pos); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, false); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + reference_cache_traits::load (pos); + ig.release (); + return true; + } + + bool access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + reload (database& db, object_type& obj) + { + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + statements_type& sts ( + conn.statement_cache ().find_object ()); + + statements_type::auto_lock l (sts); + + const id_type& id ( + obj.id); + + if (!find_ (sts, &id)) + return false; + + select_statement& st (sts.find_statement ()); + ODB_POTENTIALLY_UNUSED (st); + + callback (db, obj, callback_event::pre_load); + init (obj, sts.image (), &db); + load_ (sts, obj, true); + sts.load_delayed (0); + l.unlock (); + callback (db, obj, callback_event::post_load); + return true; + } + + bool access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + find_ (statements_type& sts, + const id_type* id) + { + using namespace sqlite; + + id_image_type& i (sts.id_image ()); + init (i, *id); + + binding& idb (sts.id_image_binding ()); + if (i.version != sts.id_image_version () || idb.version == 0) + { + bind (idb.bind, i); + sts.id_image_version (i.version); + idb.version++; + } + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + select_statement& st (sts.find_statement ()); + + st.execute (); + auto_result ar (st); + select_statement::result r (st.fetch ()); + + if (r == select_statement::truncated) + { + if (grow (im, sts.select_image_truncated ())) + im.version++; + + if (im.version != sts.select_image_version ()) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + st.refetch (); + } + } + + return r != select_statement::no_data; + } + + result< access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >::object_type > + access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + query (database&, const query_base_type& q) + { + using namespace sqlite; + using odb::details::shared; + using odb::details::shared_ptr; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + + statements_type& sts ( + conn.statement_cache ().find_object ()); + + image_type& im (sts.image ()); + binding& imb (sts.select_image_binding ()); + + if (im.version != sts.select_image_version () || + imb.version == 0) + { + bind (imb.bind, im, statement_select); + sts.select_image_version (im.version); + imb.version++; + } + + std::string text (query_statement); + if (!q.empty ()) + { + text += " "; + text += q.clause (); + } + + q.init_parameters (); + shared_ptr st ( + new (shared) select_statement ( + conn, + text, + false, + true, + q.parameters_binding (), + imb)); + + st->execute (); + + shared_ptr< odb::object_result_impl > r ( + new (shared) sqlite::object_result_impl ( + q, st, sts, 0)); + + return result (r); + } + + unsigned long long access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + erase_query (database&, const query_base_type& q) + { + using namespace sqlite; + + sqlite::connection& conn ( + sqlite::transaction::current ().connection ()); + + std::string text (erase_query_statement); + if (!q.empty ()) + { + text += ' '; + text += q.clause (); + } + + q.init_parameters (); + delete_statement st ( + conn, + text, + q.parameters_binding ()); + + return st.execute (); + } +} + +#include diff --git a/db/test-schema-v1.2/generated-sql-ddl/sqlite/TripAttemptResult-odb.hxx b/db/test-schema-v1.2/generated-sql-ddl/sqlite/TripAttemptResult-odb.hxx new file mode 100644 index 0000000..e43bfa6 --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/sqlite/TripAttemptResult-odb.hxx @@ -0,0 +1,505 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +#ifndef TRIP_ATTEMPT_RESULT_ODB_HXX +#define TRIP_ATTEMPT_RESULT_ODB_HXX + +#include + +#if (ODB_VERSION != 20400UL) +#error ODB runtime version mismatch +#endif + +#include + +#include "TripAttemptResult.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace odb +{ + // TripAttemptResult + // + template <> + struct class_traits< ::models::TripAttemptResult > + { + static const class_kind kind = class_object; + }; + + template <> + class access::object_traits< ::models::TripAttemptResult > + { + public: + typedef ::models::TripAttemptResult object_type; + typedef ::models::TripAttemptResult* pointer_type; + typedef odb::pointer_traits pointer_traits; + + static const bool polymorphic = false; + + typedef ::std::string id_type; + + static const bool auto_id = false; + + static const bool abstract = false; + + static id_type + id (const object_type&); + + typedef + no_op_pointer_cache_traits + pointer_cache_traits; + + typedef + no_op_reference_cache_traits + reference_cache_traits; + + static void + callback (database&, object_type&, callback_event); + + static void + callback (database&, const object_type&, callback_event); + }; +} + +#include + +#include +#include +#include +#include +#include + +namespace odb +{ + // TripAttemptResult + // + template + struct query_columns< ::models::TripAttemptResult, id_sqlite, A > + { + // id + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + id_type_; + + static const id_type_ id; + + // result + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + result_type_; + + static const result_type_ result; + + // retryReason + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + retryReason_type_; + + static const retryReason_type_ retryReason; + + // governmentSuspensionReason + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + governmentSuspensionReason_type_; + + static const governmentSuspensionReason_type_ governmentSuspensionReason; + + // governmentTerminationReason + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + governmentTerminationReason_type_; + + static const governmentTerminationReason_type_ governmentTerminationReason; + + // complianceSuspensionReason + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + complianceSuspensionReason_type_; + + static const complianceSuspensionReason_type_ complianceSuspensionReason; + + // complianceTerminationReason + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + complianceTerminationReason_type_; + + static const complianceTerminationReason_type_ complianceTerminationReason; + + // policySuspensionReason + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + policySuspensionReason_type_; + + static const policySuspensionReason_type_ policySuspensionReason; + + // policyTerminationReason + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + policyTerminationReason_type_; + + static const policyTerminationReason_type_ policyTerminationReason; + + // cancelationReason + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + cancelationReason_type_; + + static const cancelationReason_type_ cancelationReason; + + // failureReason + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + failureReason_type_; + + static const failureReason_type_ failureReason; + + // details + // + typedef + sqlite::query_column< + sqlite::value_traits< + ::std::string, + sqlite::id_text >::query_type, + sqlite::id_text > + details_type_; + + static const details_type_ details; + }; + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::id_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + id (A::table_name, "\"id\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::result_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + result (A::table_name, "\"result\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::retryReason_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + retryReason (A::table_name, "\"retryReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::governmentSuspensionReason_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + governmentSuspensionReason (A::table_name, "\"governmentSuspensionReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::governmentTerminationReason_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + governmentTerminationReason (A::table_name, "\"governmentTerminationReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::complianceSuspensionReason_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + complianceSuspensionReason (A::table_name, "\"complianceSuspensionReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::complianceTerminationReason_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + complianceTerminationReason (A::table_name, "\"complianceTerminationReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::policySuspensionReason_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + policySuspensionReason (A::table_name, "\"policySuspensionReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::policyTerminationReason_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + policyTerminationReason (A::table_name, "\"policyTerminationReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::cancelationReason_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + cancelationReason (A::table_name, "\"cancelationReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::failureReason_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + failureReason (A::table_name, "\"failureReason\"", 0); + + template + const typename query_columns< ::models::TripAttemptResult, id_sqlite, A >::details_type_ + query_columns< ::models::TripAttemptResult, id_sqlite, A >:: + details (A::table_name, "\"details\"", 0); + + template + struct pointer_query_columns< ::models::TripAttemptResult, id_sqlite, A >: + query_columns< ::models::TripAttemptResult, id_sqlite, A > + { + }; + + template <> + class access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >: + public access::object_traits< ::models::TripAttemptResult > + { + public: + struct id_image_type + { + details::buffer id_value; + std::size_t id_size; + bool id_null; + + std::size_t version; + }; + + struct image_type + { + // id + // + details::buffer id_value; + std::size_t id_size; + bool id_null; + + // result + // + details::buffer result_value; + std::size_t result_size; + bool result_null; + + // retryReason + // + details::buffer retryReason_value; + std::size_t retryReason_size; + bool retryReason_null; + + // governmentSuspensionReason + // + details::buffer governmentSuspensionReason_value; + std::size_t governmentSuspensionReason_size; + bool governmentSuspensionReason_null; + + // governmentTerminationReason + // + details::buffer governmentTerminationReason_value; + std::size_t governmentTerminationReason_size; + bool governmentTerminationReason_null; + + // complianceSuspensionReason + // + details::buffer complianceSuspensionReason_value; + std::size_t complianceSuspensionReason_size; + bool complianceSuspensionReason_null; + + // complianceTerminationReason + // + details::buffer complianceTerminationReason_value; + std::size_t complianceTerminationReason_size; + bool complianceTerminationReason_null; + + // policySuspensionReason + // + details::buffer policySuspensionReason_value; + std::size_t policySuspensionReason_size; + bool policySuspensionReason_null; + + // policyTerminationReason + // + details::buffer policyTerminationReason_value; + std::size_t policyTerminationReason_size; + bool policyTerminationReason_null; + + // cancelationReason + // + details::buffer cancelationReason_value; + std::size_t cancelationReason_size; + bool cancelationReason_null; + + // failureReason + // + details::buffer failureReason_value; + std::size_t failureReason_size; + bool failureReason_null; + + // details + // + details::buffer details_value; + std::size_t details_size; + bool details_null; + + std::size_t version; + }; + + struct extra_statement_cache_type; + + using object_traits::id; + + static id_type + id (const image_type&); + + static bool + grow (image_type&, + bool*); + + static void + bind (sqlite::bind*, + image_type&, + sqlite::statement_kind); + + static void + bind (sqlite::bind*, id_image_type&); + + static bool + init (image_type&, + const object_type&, + sqlite::statement_kind); + + static void + init (object_type&, + const image_type&, + database*); + + static void + init (id_image_type&, const id_type&); + + typedef sqlite::object_statements statements_type; + + typedef sqlite::query_base query_base_type; + + static const std::size_t column_count = 12UL; + static const std::size_t id_column_count = 1UL; + static const std::size_t inverse_column_count = 0UL; + static const std::size_t readonly_column_count = 0UL; + static const std::size_t managed_optimistic_column_count = 0UL; + + static const std::size_t separate_load_column_count = 0UL; + static const std::size_t separate_update_column_count = 0UL; + + static const bool versioned = false; + + static const char persist_statement[]; + static const char find_statement[]; + static const char update_statement[]; + static const char erase_statement[]; + static const char query_statement[]; + static const char erase_query_statement[]; + + static const char table_name[]; + + static void + persist (database&, const object_type&); + + static pointer_type + find (database&, const id_type&); + + static bool + find (database&, const id_type&, object_type&); + + static bool + reload (database&, object_type&); + + static void + update (database&, const object_type&); + + static void + erase (database&, const id_type&); + + static void + erase (database&, const object_type&); + + static result + query (database&, const query_base_type&); + + static unsigned long long + erase_query (database&, const query_base_type&); + + public: + static bool + find_ (statements_type&, + const id_type*); + + static void + load_ (statements_type&, + object_type&, + bool reload); + }; + + template <> + class access::object_traits_impl< ::models::TripAttemptResult, id_common >: + public access::object_traits_impl< ::models::TripAttemptResult, id_sqlite > + { + }; + + // TripAttemptResult + // +} + +#include "TripAttemptResult-odb.ixx" + +#include + +#endif // TRIP_ATTEMPT_RESULT_ODB_HXX diff --git a/db/test-schema-v1.2/generated-sql-ddl/sqlite/TripAttemptResult-odb.ixx b/db/test-schema-v1.2/generated-sql-ddl/sqlite/TripAttemptResult-odb.ixx new file mode 100644 index 0000000..ac500cc --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/sqlite/TripAttemptResult-odb.ixx @@ -0,0 +1,61 @@ +// This file was generated by ODB, object-relational mapping (ORM) +// compiler for C++. +// + +namespace odb +{ + // TripAttemptResult + // + + inline + access::object_traits< ::models::TripAttemptResult >::id_type + access::object_traits< ::models::TripAttemptResult >:: + id (const object_type& o) + { + return o.id; + } + + inline + void access::object_traits< ::models::TripAttemptResult >:: + callback (database& db, object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } + + inline + void access::object_traits< ::models::TripAttemptResult >:: + callback (database& db, const object_type& x, callback_event e) + { + ODB_POTENTIALLY_UNUSED (db); + ODB_POTENTIALLY_UNUSED (x); + ODB_POTENTIALLY_UNUSED (e); + } +} + +namespace odb +{ + // TripAttemptResult + // + + inline + void access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + erase (database& db, const object_type& obj) + { + callback (db, obj, callback_event::pre_erase); + erase (db, id (obj)); + callback (db, obj, callback_event::post_erase); + } + + inline + void access::object_traits_impl< ::models::TripAttemptResult, id_sqlite >:: + load_ (statements_type& sts, + object_type& obj, + bool) + { + ODB_POTENTIALLY_UNUSED (sts); + ODB_POTENTIALLY_UNUSED (obj); + } +} + diff --git a/db/test-schema-v1.2/generated-sql-ddl/sqlite/TripAttemptResult.sql b/db/test-schema-v1.2/generated-sql-ddl/sqlite/TripAttemptResult.sql new file mode 100644 index 0000000..031c32f --- /dev/null +++ b/db/test-schema-v1.2/generated-sql-ddl/sqlite/TripAttemptResult.sql @@ -0,0 +1,32 @@ +/* This file was generated by ODB, object-relational mapping (ORM) + * compiler for C++. + */ + +DROP TABLE IF EXISTS "TripAttemptResult"; + +CREATE TABLE IF NOT EXISTS "schema_version" ( + "name" TEXT NOT NULL PRIMARY KEY, + "version" INTEGER NOT NULL, + "migration" INTEGER NOT NULL); + +DELETE FROM "schema_version" + WHERE "name" = ''; + +CREATE TABLE "TripAttemptResult" ( + "id" TEXT NOT NULL PRIMARY KEY, + "result" TEXT NOT NULL, + "retryReason" TEXT NOT NULL, + "governmentSuspensionReason" TEXT NOT NULL, + "governmentTerminationReason" TEXT NOT NULL, + "complianceSuspensionReason" TEXT NOT NULL, + "complianceTerminationReason" TEXT NOT NULL, + "policySuspensionReason" TEXT NOT NULL, + "policyTerminationReason" TEXT NOT NULL, + "cancelationReason" TEXT NOT NULL, + "failureReason" TEXT NOT NULL, + "details" TEXT NOT NULL); + +INSERT OR IGNORE INTO "schema_version" ( + "name", "version", "migration") + VALUES ('', 2, 0); + diff --git a/db/test-schema-v1.2/generated-ts-types/.openapi-generator-ignore b/db/test-schema-v1.2/generated-ts-types/.openapi-generator-ignore new file mode 100644 index 0000000..7484ee5 --- /dev/null +++ b/db/test-schema-v1.2/generated-ts-types/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/db/test-schema-v1.2/generated-ts-types/.openapi-generator/FILES b/db/test-schema-v1.2/generated-ts-types/.openapi-generator/FILES new file mode 100644 index 0000000..7e75000 --- /dev/null +++ b/db/test-schema-v1.2/generated-ts-types/.openapi-generator/FILES @@ -0,0 +1,10 @@ +.openapi-generator-ignore +docs/Agent.md +docs/GovernmentAddress.md +docs/TripAttemptResult.md +index.ts +models/Agent.ts +models/GovernmentAddress.ts +models/TripAttemptResult.ts +models/index.ts +runtime.ts diff --git a/db/test-schema-v1.2/generated-ts-types/.openapi-generator/VERSION b/db/test-schema-v1.2/generated-ts-types/.openapi-generator/VERSION new file mode 100644 index 0000000..2540a3a --- /dev/null +++ b/db/test-schema-v1.2/generated-ts-types/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.20.0 diff --git a/db/test-schema-v1.2/generated-ts-types/docs/Agent.md b/db/test-schema-v1.2/generated-ts-types/docs/Agent.md new file mode 100644 index 0000000..7dfe8a9 --- /dev/null +++ b/db/test-schema-v1.2/generated-ts-types/docs/Agent.md @@ -0,0 +1,42 @@ + +# Agent + + +## Properties + +Name | Type +------------ | ------------- +`id` | string +`role` | string +`persistent` | boolean +`displayName` | string +`trustScore` | number + +## Example + +```typescript +import type { Agent } from '' + +// TODO: Update the object below with actual values +const example = { + "id": null, + "role": null, + "persistent": null, + "displayName": null, + "trustScore": null, +} satisfies Agent + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as Agent +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/db/test-schema-v1.2/generated-ts-types/docs/GovernmentAddress.md b/db/test-schema-v1.2/generated-ts-types/docs/GovernmentAddress.md new file mode 100644 index 0000000..5eedd03 --- /dev/null +++ b/db/test-schema-v1.2/generated-ts-types/docs/GovernmentAddress.md @@ -0,0 +1,38 @@ + +# GovernmentAddress + + +## Properties + +Name | Type +------------ | ------------- +`id` | string +`addressLabel` | string +`regionLookupKey` | string + +## Example + +```typescript +import type { GovernmentAddress } from '' + +// TODO: Update the object below with actual values +const example = { + "id": null, + "addressLabel": null, + "regionLookupKey": null, +} satisfies GovernmentAddress + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as GovernmentAddress +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/db/test-schema-v1.2/generated-ts-types/docs/TripAttemptResult.md b/db/test-schema-v1.2/generated-ts-types/docs/TripAttemptResult.md new file mode 100644 index 0000000..c3e1bcf --- /dev/null +++ b/db/test-schema-v1.2/generated-ts-types/docs/TripAttemptResult.md @@ -0,0 +1,56 @@ + +# TripAttemptResult + + +## Properties + +Name | Type +------------ | ------------- +`id` | string +`result` | string +`retryReason` | string +`governmentSuspensionReason` | string +`governmentTerminationReason` | string +`complianceSuspensionReason` | string +`complianceTerminationReason` | string +`policySuspensionReason` | string +`policyTerminationReason` | string +`cancelationReason` | string +`failureReason` | string +`details` | string + +## Example + +```typescript +import type { TripAttemptResult } from '' + +// TODO: Update the object below with actual values +const example = { + "id": null, + "result": null, + "retryReason": null, + "governmentSuspensionReason": null, + "governmentTerminationReason": null, + "complianceSuspensionReason": null, + "complianceTerminationReason": null, + "policySuspensionReason": null, + "policyTerminationReason": null, + "cancelationReason": null, + "failureReason": null, + "details": null, +} satisfies TripAttemptResult + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as TripAttemptResult +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/db/test-schema-v1.2/generated-ts-types/index.ts b/db/test-schema-v1.2/generated-ts-types/index.ts new file mode 100644 index 0000000..ff7dac6 --- /dev/null +++ b/db/test-schema-v1.2/generated-ts-types/index.ts @@ -0,0 +1,4 @@ +/* tslint:disable */ +/* eslint-disable */ +export * from './runtime'; +export * from './models/index'; diff --git a/db/test-schema-v1.2/generated-ts-types/models/Agent.ts b/db/test-schema-v1.2/generated-ts-types/models/Agent.ts new file mode 100644 index 0000000..05f7044 --- /dev/null +++ b/db/test-schema-v1.2/generated-ts-types/models/Agent.ts @@ -0,0 +1,100 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * cppbessot-test-schema-v1.2 + * Self-contained additive test fixture for cppbessot serdes and migration validation. + * + * The version of the OpenAPI document: 1.2.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import { mapValues } from '../runtime'; +/** + * + * @export + * @interface Agent + */ +export interface Agent { + /** + * + * @type {string} + * @memberof Agent + */ + id: string; + /** + * + * @type {string} + * @memberof Agent + */ + role: string; + /** + * + * @type {boolean} + * @memberof Agent + */ + persistent: boolean; + /** + * + * @type {string} + * @memberof Agent + */ + displayName?: string; + /** + * + * @type {number} + * @memberof Agent + */ + trustScore?: number; +} + +/** + * Check if a given object implements the Agent interface. + */ +export function instanceOfAgent(value: object): value is Agent { + if (!('id' in value) || value['id'] === undefined) return false; + if (!('role' in value) || value['role'] === undefined) return false; + if (!('persistent' in value) || value['persistent'] === undefined) return false; + return true; +} + +export function AgentFromJSON(json: any): Agent { + return AgentFromJSONTyped(json, false); +} + +export function AgentFromJSONTyped(json: any, ignoreDiscriminator: boolean): Agent { + if (json == null) { + return json; + } + return { + + 'id': json['id'], + 'role': json['role'], + 'persistent': json['persistent'], + 'displayName': json['displayName'] == null ? undefined : json['displayName'], + 'trustScore': json['trustScore'] == null ? undefined : json['trustScore'], + }; +} + +export function AgentToJSON(json: any): Agent { + return AgentToJSONTyped(json, false); +} + +export function AgentToJSONTyped(value?: Agent | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'id': value['id'], + 'role': value['role'], + 'persistent': value['persistent'], + 'displayName': value['displayName'], + 'trustScore': value['trustScore'], + }; +} + diff --git a/db/test-schema-v1.2/generated-ts-types/models/GovernmentAddress.ts b/db/test-schema-v1.2/generated-ts-types/models/GovernmentAddress.ts new file mode 100644 index 0000000..5781792 --- /dev/null +++ b/db/test-schema-v1.2/generated-ts-types/models/GovernmentAddress.ts @@ -0,0 +1,82 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * cppbessot-test-schema-v1.2 + * Self-contained additive test fixture for cppbessot serdes and migration validation. + * + * The version of the OpenAPI document: 1.2.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import { mapValues } from '../runtime'; +/** + * + * @export + * @interface GovernmentAddress + */ +export interface GovernmentAddress { + /** + * + * @type {string} + * @memberof GovernmentAddress + */ + id: string; + /** + * + * @type {string} + * @memberof GovernmentAddress + */ + addressLabel?: string; + /** + * + * @type {string} + * @memberof GovernmentAddress + */ + regionLookupKey?: string; +} + +/** + * Check if a given object implements the GovernmentAddress interface. + */ +export function instanceOfGovernmentAddress(value: object): value is GovernmentAddress { + if (!('id' in value) || value['id'] === undefined) return false; + return true; +} + +export function GovernmentAddressFromJSON(json: any): GovernmentAddress { + return GovernmentAddressFromJSONTyped(json, false); +} + +export function GovernmentAddressFromJSONTyped(json: any, ignoreDiscriminator: boolean): GovernmentAddress { + if (json == null) { + return json; + } + return { + + 'id': json['id'], + 'addressLabel': json['addressLabel'] == null ? undefined : json['addressLabel'], + 'regionLookupKey': json['regionLookupKey'] == null ? undefined : json['regionLookupKey'], + }; +} + +export function GovernmentAddressToJSON(json: any): GovernmentAddress { + return GovernmentAddressToJSONTyped(json, false); +} + +export function GovernmentAddressToJSONTyped(value?: GovernmentAddress | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'id': value['id'], + 'addressLabel': value['addressLabel'], + 'regionLookupKey': value['regionLookupKey'], + }; +} + diff --git a/db/test-schema-v1.2/generated-ts-types/models/TripAttemptResult.ts b/db/test-schema-v1.2/generated-ts-types/models/TripAttemptResult.ts new file mode 100644 index 0000000..83ed281 --- /dev/null +++ b/db/test-schema-v1.2/generated-ts-types/models/TripAttemptResult.ts @@ -0,0 +1,155 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * cppbessot-test-schema-v1.2 + * Self-contained additive test fixture for cppbessot serdes and migration validation. + * + * The version of the OpenAPI document: 1.2.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import { mapValues } from '../runtime'; +/** + * + * @export + * @interface TripAttemptResult + */ +export interface TripAttemptResult { + /** + * + * @type {string} + * @memberof TripAttemptResult + */ + id: string; + /** + * + * @type {string} + * @memberof TripAttemptResult + */ + result: string; + /** + * + * @type {string} + * @memberof TripAttemptResult + */ + retryReason?: string; + /** + * + * @type {string} + * @memberof TripAttemptResult + */ + governmentSuspensionReason?: string; + /** + * + * @type {string} + * @memberof TripAttemptResult + */ + governmentTerminationReason?: string; + /** + * + * @type {string} + * @memberof TripAttemptResult + */ + complianceSuspensionReason?: string; + /** + * + * @type {string} + * @memberof TripAttemptResult + */ + complianceTerminationReason?: string; + /** + * + * @type {string} + * @memberof TripAttemptResult + */ + policySuspensionReason?: string; + /** + * + * @type {string} + * @memberof TripAttemptResult + */ + policyTerminationReason?: string; + /** + * + * @type {string} + * @memberof TripAttemptResult + */ + cancelationReason?: string; + /** + * + * @type {string} + * @memberof TripAttemptResult + */ + failureReason?: string; + /** + * + * @type {string} + * @memberof TripAttemptResult + */ + details?: string; +} + +/** + * Check if a given object implements the TripAttemptResult interface. + */ +export function instanceOfTripAttemptResult(value: object): value is TripAttemptResult { + if (!('id' in value) || value['id'] === undefined) return false; + if (!('result' in value) || value['result'] === undefined) return false; + return true; +} + +export function TripAttemptResultFromJSON(json: any): TripAttemptResult { + return TripAttemptResultFromJSONTyped(json, false); +} + +export function TripAttemptResultFromJSONTyped(json: any, ignoreDiscriminator: boolean): TripAttemptResult { + if (json == null) { + return json; + } + return { + + 'id': json['id'], + 'result': json['result'], + 'retryReason': json['retryReason'] == null ? undefined : json['retryReason'], + 'governmentSuspensionReason': json['governmentSuspensionReason'] == null ? undefined : json['governmentSuspensionReason'], + 'governmentTerminationReason': json['governmentTerminationReason'] == null ? undefined : json['governmentTerminationReason'], + 'complianceSuspensionReason': json['complianceSuspensionReason'] == null ? undefined : json['complianceSuspensionReason'], + 'complianceTerminationReason': json['complianceTerminationReason'] == null ? undefined : json['complianceTerminationReason'], + 'policySuspensionReason': json['policySuspensionReason'] == null ? undefined : json['policySuspensionReason'], + 'policyTerminationReason': json['policyTerminationReason'] == null ? undefined : json['policyTerminationReason'], + 'cancelationReason': json['cancelationReason'] == null ? undefined : json['cancelationReason'], + 'failureReason': json['failureReason'] == null ? undefined : json['failureReason'], + 'details': json['details'] == null ? undefined : json['details'], + }; +} + +export function TripAttemptResultToJSON(json: any): TripAttemptResult { + return TripAttemptResultToJSONTyped(json, false); +} + +export function TripAttemptResultToJSONTyped(value?: TripAttemptResult | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'id': value['id'], + 'result': value['result'], + 'retryReason': value['retryReason'], + 'governmentSuspensionReason': value['governmentSuspensionReason'], + 'governmentTerminationReason': value['governmentTerminationReason'], + 'complianceSuspensionReason': value['complianceSuspensionReason'], + 'complianceTerminationReason': value['complianceTerminationReason'], + 'policySuspensionReason': value['policySuspensionReason'], + 'policyTerminationReason': value['policyTerminationReason'], + 'cancelationReason': value['cancelationReason'], + 'failureReason': value['failureReason'], + 'details': value['details'], + }; +} + diff --git a/db/test-schema-v1.2/generated-ts-types/models/index.ts b/db/test-schema-v1.2/generated-ts-types/models/index.ts new file mode 100644 index 0000000..81c16ff --- /dev/null +++ b/db/test-schema-v1.2/generated-ts-types/models/index.ts @@ -0,0 +1,5 @@ +/* tslint:disable */ +/* eslint-disable */ +export * from './Agent'; +export * from './GovernmentAddress'; +export * from './TripAttemptResult'; diff --git a/db/test-schema-v1.2/generated-ts-types/runtime.ts b/db/test-schema-v1.2/generated-ts-types/runtime.ts new file mode 100644 index 0000000..a516af3 --- /dev/null +++ b/db/test-schema-v1.2/generated-ts-types/runtime.ts @@ -0,0 +1,432 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * cppbessot-test-schema-v1.2 + * Self-contained additive test fixture for cppbessot serdes and migration validation. + * + * The version of the OpenAPI document: 1.2.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +export const BASE_PATH = "http://localhost".replace(/\/+$/, ""); + +export interface ConfigurationParameters { + basePath?: string; // override base path + fetchApi?: FetchAPI; // override for fetch implementation + middleware?: Middleware[]; // middleware to apply before/after fetch requests + queryParamsStringify?: (params: HTTPQuery) => string; // stringify function for query strings + username?: string; // parameter for basic security + password?: string; // parameter for basic security + apiKey?: string | Promise | ((name: string) => string | Promise); // parameter for apiKey security + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string | Promise); // parameter for oauth2 security + headers?: HTTPHeaders; //header params we want to use on every request + credentials?: RequestCredentials; //value for the credentials param we want to use on each request +} + +export class Configuration { + constructor(private configuration: ConfigurationParameters = {}) {} + + set config(configuration: Configuration) { + this.configuration = configuration; + } + + get basePath(): string { + return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH; + } + + get fetchApi(): FetchAPI | undefined { + return this.configuration.fetchApi; + } + + get middleware(): Middleware[] { + return this.configuration.middleware || []; + } + + get queryParamsStringify(): (params: HTTPQuery) => string { + return this.configuration.queryParamsStringify || querystring; + } + + get username(): string | undefined { + return this.configuration.username; + } + + get password(): string | undefined { + return this.configuration.password; + } + + get apiKey(): ((name: string) => string | Promise) | undefined { + const apiKey = this.configuration.apiKey; + if (apiKey) { + return typeof apiKey === 'function' ? apiKey : () => apiKey; + } + return undefined; + } + + get accessToken(): ((name?: string, scopes?: string[]) => string | Promise) | undefined { + const accessToken = this.configuration.accessToken; + if (accessToken) { + return typeof accessToken === 'function' ? accessToken : async () => accessToken; + } + return undefined; + } + + get headers(): HTTPHeaders | undefined { + return this.configuration.headers; + } + + get credentials(): RequestCredentials | undefined { + return this.configuration.credentials; + } +} + +export const DefaultConfig = new Configuration(); + +/** + * This is the base class for all generated API classes. + */ +export class BaseAPI { + + private static readonly jsonRegex = new RegExp('^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$', 'i'); + private middleware: Middleware[]; + + constructor(protected configuration = DefaultConfig) { + this.middleware = configuration.middleware; + } + + withMiddleware(this: T, ...middlewares: Middleware[]) { + const next = this.clone(); + next.middleware = next.middleware.concat(...middlewares); + return next; + } + + withPreMiddleware(this: T, ...preMiddlewares: Array) { + const middlewares = preMiddlewares.map((pre) => ({ pre })); + return this.withMiddleware(...middlewares); + } + + withPostMiddleware(this: T, ...postMiddlewares: Array) { + const middlewares = postMiddlewares.map((post) => ({ post })); + return this.withMiddleware(...middlewares); + } + + /** + * Check if the given MIME is a JSON MIME. + * JSON MIME examples: + * application/json + * application/json; charset=UTF8 + * APPLICATION/JSON + * application/vnd.company+json + * @param mime - MIME (Multipurpose Internet Mail Extensions) + * @return True if the given MIME is JSON, false otherwise. + */ + protected isJsonMime(mime: string | null | undefined): boolean { + if (!mime) { + return false; + } + return BaseAPI.jsonRegex.test(mime); + } + + protected async request(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction): Promise { + const { url, init } = await this.createFetchParams(context, initOverrides); + const response = await this.fetchApi(url, init); + if (response && (response.status >= 200 && response.status < 300)) { + return response; + } + throw new ResponseError(response, 'Response returned an error code'); + } + + private async createFetchParams(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction) { + let url = this.configuration.basePath + context.path; + if (context.query !== undefined && Object.keys(context.query).length !== 0) { + // only add the querystring to the URL if there are query parameters. + // this is done to avoid urls ending with a "?" character which buggy webservers + // do not handle correctly sometimes. + url += '?' + this.configuration.queryParamsStringify(context.query); + } + + const headers = Object.assign({}, this.configuration.headers, context.headers); + Object.keys(headers).forEach(key => headers[key] === undefined ? delete headers[key] : {}); + + const initOverrideFn = + typeof initOverrides === "function" + ? initOverrides + : async () => initOverrides; + + const initParams = { + method: context.method, + headers, + body: context.body, + credentials: this.configuration.credentials, + }; + + const overriddenInit: RequestInit = { + ...initParams, + ...(await initOverrideFn({ + init: initParams, + context, + })) + }; + + let body: any; + if (isFormData(overriddenInit.body) + || (overriddenInit.body instanceof URLSearchParams) + || isBlob(overriddenInit.body)) { + body = overriddenInit.body; + } else if (this.isJsonMime(headers['Content-Type'])) { + body = JSON.stringify(overriddenInit.body); + } else { + body = overriddenInit.body; + } + + const init: RequestInit = { + ...overriddenInit, + body + }; + + return { url, init }; + } + + private fetchApi = async (url: string, init: RequestInit) => { + let fetchParams = { url, init }; + for (const middleware of this.middleware) { + if (middleware.pre) { + fetchParams = await middleware.pre({ + fetch: this.fetchApi, + ...fetchParams, + }) || fetchParams; + } + } + let response: Response | undefined = undefined; + try { + response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init); + } catch (e) { + for (const middleware of this.middleware) { + if (middleware.onError) { + response = await middleware.onError({ + fetch: this.fetchApi, + url: fetchParams.url, + init: fetchParams.init, + error: e, + response: response ? response.clone() : undefined, + }) || response; + } + } + if (response === undefined) { + if (e instanceof Error) { + throw new FetchError(e, 'The request failed and the interceptors did not return an alternative response'); + } else { + throw e; + } + } + } + for (const middleware of this.middleware) { + if (middleware.post) { + response = await middleware.post({ + fetch: this.fetchApi, + url: fetchParams.url, + init: fetchParams.init, + response: response.clone(), + }) || response; + } + } + return response; + } + + /** + * Create a shallow clone of `this` by constructing a new instance + * and then shallow cloning data members. + */ + private clone(this: T): T { + const constructor = this.constructor as any; + const next = new constructor(this.configuration); + next.middleware = this.middleware.slice(); + return next; + } +}; + +function isBlob(value: any): value is Blob { + return typeof Blob !== 'undefined' && value instanceof Blob; +} + +function isFormData(value: any): value is FormData { + return typeof FormData !== "undefined" && value instanceof FormData; +} + +export class ResponseError extends Error { + override name: "ResponseError" = "ResponseError"; + constructor(public response: Response, msg?: string) { + super(msg); + } +} + +export class FetchError extends Error { + override name: "FetchError" = "FetchError"; + constructor(public cause: Error, msg?: string) { + super(msg); + } +} + +export class RequiredError extends Error { + override name: "RequiredError" = "RequiredError"; + constructor(public field: string, msg?: string) { + super(msg); + } +} + +export const COLLECTION_FORMATS = { + csv: ",", + ssv: " ", + tsv: "\t", + pipes: "|", +}; + +export type FetchAPI = WindowOrWorkerGlobalScope['fetch']; + +export type Json = any; +export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD'; +export type HTTPHeaders = { [key: string]: string }; +export type HTTPQuery = { [key: string]: string | number | null | boolean | Array | Set | HTTPQuery }; +export type HTTPBody = Json | FormData | URLSearchParams; +export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: RequestCredentials; body?: HTTPBody }; +export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original'; + +export type InitOverrideFunction = (requestContext: { init: HTTPRequestInit, context: RequestOpts }) => Promise + +export interface FetchParams { + url: string; + init: RequestInit; +} + +export interface RequestOpts { + path: string; + method: HTTPMethod; + headers: HTTPHeaders; + query?: HTTPQuery; + body?: HTTPBody; +} + +export function querystring(params: HTTPQuery, prefix: string = ''): string { + return Object.keys(params) + .map(key => querystringSingleKey(key, params[key], prefix)) + .filter(part => part.length > 0) + .join('&'); +} + +function querystringSingleKey(key: string, value: string | number | null | undefined | boolean | Array | Set | HTTPQuery, keyPrefix: string = ''): string { + const fullKey = keyPrefix + (keyPrefix.length ? `[${key}]` : key); + if (value instanceof Array) { + const multiValue = value.map(singleValue => encodeURIComponent(String(singleValue))) + .join(`&${encodeURIComponent(fullKey)}=`); + return `${encodeURIComponent(fullKey)}=${multiValue}`; + } + if (value instanceof Set) { + const valueAsArray = Array.from(value); + return querystringSingleKey(key, valueAsArray, keyPrefix); + } + if (value instanceof Date) { + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + } + if (value instanceof Object) { + return querystring(value as HTTPQuery, fullKey); + } + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`; +} + +export function exists(json: any, key: string) { + const value = json[key]; + return value !== null && value !== undefined; +} + +export function mapValues(data: any, fn: (item: any) => any) { + const result: { [key: string]: any } = {}; + for (const key of Object.keys(data)) { + result[key] = fn(data[key]); + } + return result; +} + +export function canConsumeForm(consumes: Consume[]): boolean { + for (const consume of consumes) { + if ('multipart/form-data' === consume.contentType) { + return true; + } + } + return false; +} + +export interface Consume { + contentType: string; +} + +export interface RequestContext { + fetch: FetchAPI; + url: string; + init: RequestInit; +} + +export interface ResponseContext { + fetch: FetchAPI; + url: string; + init: RequestInit; + response: Response; +} + +export interface ErrorContext { + fetch: FetchAPI; + url: string; + init: RequestInit; + error: unknown; + response?: Response; +} + +export interface Middleware { + pre?(context: RequestContext): Promise; + post?(context: ResponseContext): Promise; + onError?(context: ErrorContext): Promise; +} + +export interface ApiResponse { + raw: Response; + value(): Promise; +} + +export interface ResponseTransformer { + (json: any): T; +} + +export class JSONApiResponse { + constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + + async value(): Promise { + return this.transformer(await this.raw.json()); + } +} + +export class VoidApiResponse { + constructor(public raw: Response) {} + + async value(): Promise { + return undefined; + } +} + +export class BlobApiResponse { + constructor(public raw: Response) {} + + async value(): Promise { + return await this.raw.blob(); + }; +} + +export class TextApiResponse { + constructor(public raw: Response) {} + + async value(): Promise { + return await this.raw.text(); + }; +} diff --git a/db/test-schema-v1.2/generated-zod/schemas.ts b/db/test-schema-v1.2/generated-zod/schemas.ts new file mode 100644 index 0000000..a4ce218 --- /dev/null +++ b/db/test-schema-v1.2/generated-zod/schemas.ts @@ -0,0 +1,55 @@ +/* + * AUTO-GENERATED BY CppBeSsot. + * Direct edits are pointless: this file is regenerated. + * Update the OpenAPI schema and/or CppBeSsot templates, then regenerate generated-* outputs. + */ + +import { makeApi, Zodios, type ZodiosOptions } from "@zodios/core"; +import { z } from "zod"; + +const Agent = z + .object({ + id: z.string(), + role: z.string(), + persistent: z.boolean(), + displayName: z.string().optional(), + trustScore: z.number().int().gte(0).lte(100).optional(), + }) + .passthrough(); +const GovernmentAddress = z + .object({ + id: z.string(), + addressLabel: z.string().optional(), + regionLookupKey: z.string().optional(), + }) + .passthrough(); +const TripAttemptResult = z + .object({ + id: z.string(), + result: z.string(), + retryReason: z.string().optional(), + governmentSuspensionReason: z.string().optional(), + governmentTerminationReason: z.string().optional(), + complianceSuspensionReason: z.string().optional(), + complianceTerminationReason: z.string().optional(), + policySuspensionReason: z.string().optional(), + policyTerminationReason: z.string().optional(), + cancelationReason: z.string().optional(), + failureReason: z.string().optional(), + details: z.string().optional(), + }) + .passthrough(); + +export const schemas = { + Agent, + GovernmentAddress, + TripAttemptResult, +}; + +const endpoints = makeApi([]); + +export const api = new Zodios(endpoints); + +export function createApiClient(baseUrl: string, options?: ZodiosOptions) { + return new Zodios(baseUrl, endpoints, options); +}