progress on session_insert_builder
This commit is contained in:
@@ -8,6 +8,7 @@ add_library(matador-core STATIC
|
||||
../../include/matador/object/object_info.hpp
|
||||
../../include/matador/object/object_proxy.hpp
|
||||
../../include/matador/object/object_ptr.hpp
|
||||
../../include/matador/object/primary_key_resolver.hpp
|
||||
../../include/matador/object/schema.hpp
|
||||
../../include/matador/object/schema_node.hpp
|
||||
../../include/matador/object/schema_node_iterator.hpp
|
||||
@@ -39,6 +40,7 @@ add_library(matador-core STATIC
|
||||
../../include/matador/utils/singleton.hpp
|
||||
../../include/matador/utils/string.hpp
|
||||
../../include/matador/utils/types.hpp
|
||||
../../include/matador/utils/uuid.hpp
|
||||
../../include/matador/utils/value.hpp
|
||||
../../include/matador/utils/version.hpp
|
||||
object/attribute_definition_generator.cpp
|
||||
@@ -46,6 +48,7 @@ add_library(matador-core STATIC
|
||||
object/basic_object_info.cpp
|
||||
object/error_code.cpp
|
||||
object/object_definition.cpp
|
||||
object/primary_key_resolver.cpp
|
||||
object/schema.cpp
|
||||
object/schema_node.cpp
|
||||
object/schema_node_iterator.cpp
|
||||
@@ -59,10 +62,9 @@ add_library(matador-core STATIC
|
||||
utils/os.cpp
|
||||
utils/string.cpp
|
||||
utils/types.cpp
|
||||
utils/uuid.cpp
|
||||
utils/value.cpp
|
||||
utils/version.cpp
|
||||
../../include/matador/object/primary_key_resolver.hpp
|
||||
object/primary_key_resolver.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(matador-core ${CMAKE_DL_LIBS})
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
#include "matador/utils/uuid.hpp"
|
||||
|
||||
#include <random>
|
||||
|
||||
namespace matador::utils {
|
||||
|
||||
uuid uuid::generate() {
|
||||
std::random_device rd;
|
||||
std::mt19937_64 gen(rd());
|
||||
std::uniform_int_distribution<uint64_t> dist;
|
||||
|
||||
uint64_t high = dist(gen);
|
||||
uint64_t low = dist(gen);
|
||||
|
||||
// Set version to 4 (UUID v4)
|
||||
high &= 0xFFFFFFFFFFFF0FFFULL;
|
||||
high |= 0x0000000000004000ULL;
|
||||
|
||||
// Set variant to 10xx (RFC 4122)
|
||||
low &= 0x3FFFFFFFFFFFFFFFULL;
|
||||
low |= 0x8000000000000000ULL;
|
||||
|
||||
uuid result;
|
||||
result._data[0] = static_cast<uint32_t>(high >> 32);
|
||||
result._data[1] = static_cast<uint32_t>(high & 0xFFFFFFFF);
|
||||
result._data[2] = static_cast<uint32_t>(low >> 32);
|
||||
result._data[3] = static_cast<uint32_t>(low & 0xFFFFFFFF);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string uuid::str() const {
|
||||
const char* hex = "0123456789abcdef";
|
||||
char out[36]; // UUID string format is 36 characters
|
||||
int pos = 0;
|
||||
|
||||
auto write_hex = [&](uint32_t value, int digits) {
|
||||
for (int i = digits - 1; i >= 0; --i) {
|
||||
out[pos + i] = hex[value & 0xF];
|
||||
value >>= 4;
|
||||
}
|
||||
pos += digits;
|
||||
};
|
||||
|
||||
write_hex(_data[0] >> 16, 8);
|
||||
out[pos++] = '-';
|
||||
write_hex(_data[0] & 0xFFFF, 4);
|
||||
out[pos++] = '-';
|
||||
write_hex(_data[1] >> 16, 4);
|
||||
out[pos++] = '-';
|
||||
write_hex(_data[1] & 0xFFFF, 4);
|
||||
out[pos++] = '-';
|
||||
write_hex(_data[2] >> 16, 4);
|
||||
write_hex(_data[2] & 0xFFFF, 4);
|
||||
write_hex(_data[3], 4);
|
||||
|
||||
return {out, 36};
|
||||
}
|
||||
|
||||
const uuid::uuid_array& uuid::data() const {
|
||||
return _data;
|
||||
}
|
||||
|
||||
bool operator==( const uuid& lhs, const uuid& rhs ) {
|
||||
return lhs._data == rhs._data;
|
||||
}
|
||||
|
||||
bool operator!=( const uuid& lhs, const uuid& rhs ) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
bool operator<( const uuid& lhs, const uuid& rhs ) {
|
||||
return lhs._data < rhs._data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#include "matador/orm/session_insert_builder.hpp"
|
||||
|
||||
namespace matador::orm {
|
||||
void session_insert_builder::on_primary_key(const char* id, std::string& value, size_t) {
|
||||
push(id, value);
|
||||
}
|
||||
|
||||
void session_insert_builder::on_revision(const char* id, unsigned long long& x) {
|
||||
push(id, x);
|
||||
}
|
||||
|
||||
void session_insert_builder::push(const std::string& column_name, const utils::database_type& value) {
|
||||
entity_insert_data_.back().columns.emplace_back(column_name);
|
||||
entity_insert_data_.back().values.emplace_back(value);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ query_insert_intermediate::query_insert_intermediate()
|
||||
context_->parts.push_back(std::make_unique<internal::query_insert_part>());
|
||||
}
|
||||
|
||||
query_into_intermediate query_insert_intermediate::into(const sql::table &table, std::initializer_list<sql::column> columns)
|
||||
query_into_intermediate query_insert_intermediate::into(const sql::table &table, const std::initializer_list<sql::column> columns)
|
||||
{
|
||||
return into(table, std::move(std::vector<sql::column>{columns}));
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ void query_compiler::visit(internal::query_delete_part &/*delete_part*/)
|
||||
void query_compiler::visit(internal::query_delete_from_part &delete_from_part)
|
||||
{
|
||||
query_.table = delete_from_part.table();
|
||||
query_.sql += " " + query_compiler::build_table_name(delete_from_part.token(), *dialect_, query_.table);
|
||||
query_.sql += " " + build_table_name(delete_from_part.token(), *dialect_, query_.table);
|
||||
}
|
||||
|
||||
void query_compiler::visit(internal::query_create_part &/*create_part*/)
|
||||
|
||||
Reference in New Issue
Block a user