37 for (
const auto& [key, value] : fields) {
67 start_ = std::chrono::high_resolution_clock::now();
71 auto now = std::chrono::high_resolution_clock::now();
72 return std::chrono::duration<double, std::milli>(now -
start_).count();
76 auto now = std::chrono::high_resolution_clock::now();
77 return std::chrono::duration<double, std::micro>(now -
start_).count();
81 std::chrono::high_resolution_clock::time_point
start_;
94 config.
host =
"localhost";
123 result.reserve(count);
124 for (
size_t i = 0; i < count; ++i) {
125 result.push_back(row_generator(i));
152 {{
"id", int64_t(1)}, {
"name", std::string(
"Alice")}, {
"email", std::string(
"alice@example.com")}, {
"active",
true}},
153 {{
"id", int64_t(2)}, {
"name", std::string(
"Bob")}, {
"email", std::string(
"bob@example.com")}, {
"active",
true}},
154 {{
"id", int64_t(3)}, {
"name", std::string(
"Charlie")}, {
"email", std::string(
"charlie@example.com")}, {
"active",
false}}
163 {{
"id", int64_t(1)}, {
"name", std::string(
"Widget")}, {
"price", 19.99}, {
"quantity", int64_t(100)}},
164 {{
"id", int64_t(2)}, {
"name", std::string(
"Gadget")}, {
"price", 29.99}, {
"quantity", int64_t(50)}},
165 {{
"id", int64_t(3)}, {
"name", std::string(
"Thing")}, {
"price", 9.99}, {
"quantity", int64_t(200)}}
181namespace assertions {
187 return result.size() == expected;
194 return result.empty();
202 for (
const auto& row : result) {
203 auto it = row.find(field);
204 if (it != row.end()) {
205 if (
auto* v = std::get_if<T>(&it->second)) {
206 if (*v == value)
return true;
218 return result.is_ok();
225bool is_error(
const kcenon::common::Result<T>& result) {
226 return result.is_err();
232inline bool is_success(
const kcenon::common::VoidResult& result) {
233 return result.is_ok();
239inline bool is_error(
const kcenon::common::VoidResult& result) {
240 return result.is_err();
Configurable mock for database_backend interface.
kcenon::common::VoidResult initialize(const core::connection_config &config) override
Initialize the database backend.
kcenon::common::VoidResult shutdown() override
Shutdown the database backend gracefully.
RAII wrapper for test database setup/teardown.
scoped_test_database(mock_database &db)
const mock_database & get() const
Simple timer for performance testing.
double elapsed_us() const
double elapsed_ms() const
std::chrono::high_resolution_clock::time_point start_
Abstract interface for database backends.
std::vector< database_row > database_result
std::map< std::string, database_value > database_row
std::variant< std::string, int64_t, double, bool, std::nullptr_t > database_value
bool contains_field_value(const core::database_result &result, const std::string &field, const T &value)
Check if result contains a row with specific field value.
bool is_error(const kcenon::common::Result< T > &result)
Check if a Result<T> is an error.
bool has_rows(const core::database_result &result, size_t expected)
Check if result contains expected number of rows.
bool is_empty(const core::database_result &result)
Check if result is empty.
bool is_success(const kcenon::common::Result< T > &result)
Check if a Result<T> is successful.
core::database_result empty_result()
Empty result.
core::database_result products_data()
Standard products table data.
core::database_result users_data()
Standard user table data.
core::database_result make_result(std::initializer_list< core::database_row > rows)
Helper function to create test data rows.
core::database_result generate_sequential_ids(size_t count, const std::string &id_column="id")
Generate sequential integer test data.
core::database_value make_null()
Create a NULL value.
core::database_row make_row(std::initializer_list< std::pair< std::string, core::database_value > > fields)
Create a single row.
core::database_value make_value(const T &val)
Create a database_value from common types.
core::database_result generate_test_data(size_t count, std::function< core::database_row(size_t index)> row_generator)
Generate test data for a table.
Configuration for database connection.