From c8d21bc3ce6faafb16da3354f4c7ea924e526c7a Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Thu, 11 Sep 2025 20:48:49 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20=D0=B1?= =?UTF-8?q?=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82=D0=B5=D0=BA=D0=B8.=20?= =?UTF-8?q?=D0=94=D0=B0=D1=82=D0=B0=20=D0=BA=D0=BE=D0=BD=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D1=82=D0=B8=D1=80=D1=83=D0=B5=D1=82=D1=81=D1=8F=20=D0=B2=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=20D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/cdcdb/cdc/cas.d | 5 +++++ source/cdcdb/db/dblite.d | 12 +++++++++--- source/cdcdb/db/types.d | 8 +++++--- source/cdcdb/version_.d | 3 +++ test/app.d | 7 ++++++- 5 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 source/cdcdb/version_.d diff --git a/source/cdcdb/cdc/cas.d b/source/cdcdb/cdc/cas.d index 68ec16c..bcde2af 100644 --- a/source/cdcdb/cdc/cas.d +++ b/source/cdcdb/cdc/cas.d @@ -141,4 +141,9 @@ public: { _db.deleteSnapshot(snapshot.id); } + + string getVersion() { + import cdcdb.version_; + return cdcdbVersion; + } } diff --git a/source/cdcdb/db/dblite.d b/source/cdcdb/db/dblite.d index 5a3d670..d2bf2c2 100644 --- a/source/cdcdb/db/dblite.d +++ b/source/cdcdb/db/dblite.d @@ -7,7 +7,7 @@ import arsd.sqlite; import std.file : exists; import std.exception : enforce; import std.conv : to; -import std.string : join; +import std.string : join, replace; final class DBLite : Sqlite { @@ -57,6 +57,12 @@ private: } } + DateTime toDateTime(string sqliteDate) + { + string isoDate = sqliteDate.replace(" ", "T"); + return DateTime.fromISOExtString(isoDate); + } + public: this(string database) { @@ -189,7 +195,7 @@ public: snapshot.filePath = row["file_path"].to!string; snapshot.fileSha256 = cast(ubyte[]) row["file_sha256"].dup; snapshot.label = row["label"].to!string; - snapshot.createdUtc = row["created_utc"].to!string; + snapshot.createdUtc = toDateTime(row["created_utc"].to!string); snapshot.sourceLength = row["source_length"].to!long; snapshot.algoMin = row["algo_min"].to!long; snapshot.algoNormal = row["algo_normal"].to!long; @@ -224,7 +230,7 @@ public: snapshot.filePath = data["file_path"].to!string; snapshot.fileSha256 = cast(ubyte[]) data["file_sha256"].dup; snapshot.label = data["label"].to!string; - snapshot.createdUtc = data["created_utc"].to!string; + snapshot.createdUtc = toDateTime(data["created_utc"].to!string); snapshot.sourceLength = data["source_length"].to!long; snapshot.algoMin = data["algo_min"].to!long; snapshot.algoNormal = data["algo_normal"].to!long; diff --git a/source/cdcdb/db/types.d b/source/cdcdb/db/types.d index daf26b0..7e64d02 100644 --- a/source/cdcdb/db/types.d +++ b/source/cdcdb/db/types.d @@ -1,5 +1,7 @@ module cdcdb.db.types; +import std.datetime : DateTime; + enum SnapshotStatus : int { pending = 0, @@ -12,7 +14,7 @@ struct Snapshot string filePath; ubyte[32] fileSha256; string label; - string createdUtc; + DateTime createdUtc; long sourceLength; long algoMin; long algoNormal; @@ -29,8 +31,8 @@ struct Blob long size; long zSize; ubyte[] content; - string createdUtc; - string lastSeenUtc; + DateTime createdUtc; + DateTime lastSeenUtc; long refcount; bool zstd; } diff --git a/source/cdcdb/version_.d b/source/cdcdb/version_.d new file mode 100644 index 0000000..dd57171 --- /dev/null +++ b/source/cdcdb/version_.d @@ -0,0 +1,3 @@ +module cdcdb.version_; + +enum cdcdbVersion = "0.0.1"; diff --git a/test/app.d b/test/app.d index a6d6f7a..8c360ea 100644 --- a/test/app.d +++ b/test/app.d @@ -7,5 +7,10 @@ import std.file : read; void main() { auto cas = new CAS("/tmp/base.db", true); - cas.newSnapshot("/tmp/text", "Файл для тестирования", cast(ubyte[]) read("/tmp/text")); + // cas.newSnapshot("/tmp/text", "Файл для тестирования", cast(ubyte[]) read("/tmp/text")); + import std.stdio : writeln; + + writeln(cas.getSnapshotList("/tmp/text")); + + writeln(cas.getVersion); }