Skip to content

Commit f9befe6

Browse files
committed
db(core,mig): simplify Statement::bind API and align migrations with DbValue core
- Expose ergonomic Statement::bind overloads (int64, double, bool, string) - Remove explicit DbValue/str() usage from migration code - Align FileMigrationsRunner with new ResultSet::row() reference API - Add ISO-8601 UTC timestamps for applied migrations - Keep migrations fully SQL-driven and anti-ORM by design
1 parent caab5d4 commit f9befe6

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

include/vix/db/core/Drivers.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace vix::db
3232
void bind(std::size_t idx, double v) { bind(idx, f64(v)); }
3333
void bind(std::size_t idx, bool v) { bind(idx, b(v)); }
3434
void bind(std::size_t idx, std::string v) { bind(idx, str(std::move(v))); }
35+
void bind(std::size_t idx, std::string_view v) { bind(idx, std::string(v)); }
3536
void bindNull(std::size_t idx) { bind(idx, null()); }
3637
virtual std::unique_ptr<ResultSet> query() = 0;
3738
virtual std::uint64_t exec() = 0;

include/vix/db/mig/FileMigrationsRunner.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* @file FileMigrationRunner.hpp
3+
* @file FileMigrationsRunner.hpp
44
* @author Gaspard Kirira
55
*
66
* Copyright 2025, Gaspard Kirira. All rights reserved.

src/mig/FileMigrationsRunner.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,28 @@
1818
#include <sstream>
1919
#include <algorithm>
2020
#include <unordered_map>
21+
#include <chrono>
22+
#include <ctime>
23+
#include <iomanip>
2124

2225
namespace vix::db
2326
{
2427
static std::string now_text()
2528
{
26-
return "now";
29+
using namespace std::chrono;
30+
const auto now = system_clock::now();
31+
const std::time_t t = system_clock::to_time_t(now);
32+
33+
std::tm tm{};
34+
#if defined(_WIN32)
35+
gmtime_s(&tm, &t);
36+
#else
37+
gmtime_r(&t, &tm);
38+
#endif
39+
40+
std::ostringstream oss;
41+
oss << std::put_time(&tm, "%Y-%m-%dT%H:%M:%SZ");
42+
return oss.str();
2743
}
2844

2945
void FileMigrationsRunner::ensureTable()
@@ -176,7 +192,7 @@ namespace vix::db
176192
return false;
177193

178194
if (checksum_out)
179-
*checksum_out = rs->row()->getString(0);
195+
*checksum_out = rs->row().getString(0);
180196

181197
return true;
182198
}
@@ -203,7 +219,7 @@ namespace vix::db
203219
auto rs = st->query();
204220
if (!rs->next())
205221
return {};
206-
return rs->row()->getString(0);
222+
return rs->row().getString(0);
207223
}
208224

209225
void FileMigrationsRunner::applyAll()

0 commit comments

Comments
 (0)