Добавлена версия библиотеки. Дата конвертируется в формат D

This commit is contained in:
Alexander Zhirov 2025-09-11 20:48:49 +03:00
parent b29b328f91
commit c8d21bc3ce
Signed by: alexander
GPG key ID: C8D8BE544A27C511
5 changed files with 28 additions and 7 deletions

View file

@ -141,4 +141,9 @@ public:
{ {
_db.deleteSnapshot(snapshot.id); _db.deleteSnapshot(snapshot.id);
} }
string getVersion() {
import cdcdb.version_;
return cdcdbVersion;
}
} }

View file

@ -7,7 +7,7 @@ import arsd.sqlite;
import std.file : exists; import std.file : exists;
import std.exception : enforce; import std.exception : enforce;
import std.conv : to; import std.conv : to;
import std.string : join; import std.string : join, replace;
final class DBLite : Sqlite final class DBLite : Sqlite
{ {
@ -57,6 +57,12 @@ private:
} }
} }
DateTime toDateTime(string sqliteDate)
{
string isoDate = sqliteDate.replace(" ", "T");
return DateTime.fromISOExtString(isoDate);
}
public: public:
this(string database) this(string database)
{ {
@ -189,7 +195,7 @@ public:
snapshot.filePath = row["file_path"].to!string; snapshot.filePath = row["file_path"].to!string;
snapshot.fileSha256 = cast(ubyte[]) row["file_sha256"].dup; snapshot.fileSha256 = cast(ubyte[]) row["file_sha256"].dup;
snapshot.label = row["label"].to!string; 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.sourceLength = row["source_length"].to!long;
snapshot.algoMin = row["algo_min"].to!long; snapshot.algoMin = row["algo_min"].to!long;
snapshot.algoNormal = row["algo_normal"].to!long; snapshot.algoNormal = row["algo_normal"].to!long;
@ -224,7 +230,7 @@ public:
snapshot.filePath = data["file_path"].to!string; snapshot.filePath = data["file_path"].to!string;
snapshot.fileSha256 = cast(ubyte[]) data["file_sha256"].dup; snapshot.fileSha256 = cast(ubyte[]) data["file_sha256"].dup;
snapshot.label = data["label"].to!string; 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.sourceLength = data["source_length"].to!long;
snapshot.algoMin = data["algo_min"].to!long; snapshot.algoMin = data["algo_min"].to!long;
snapshot.algoNormal = data["algo_normal"].to!long; snapshot.algoNormal = data["algo_normal"].to!long;

View file

@ -1,5 +1,7 @@
module cdcdb.db.types; module cdcdb.db.types;
import std.datetime : DateTime;
enum SnapshotStatus : int enum SnapshotStatus : int
{ {
pending = 0, pending = 0,
@ -12,7 +14,7 @@ struct Snapshot
string filePath; string filePath;
ubyte[32] fileSha256; ubyte[32] fileSha256;
string label; string label;
string createdUtc; DateTime createdUtc;
long sourceLength; long sourceLength;
long algoMin; long algoMin;
long algoNormal; long algoNormal;
@ -29,8 +31,8 @@ struct Blob
long size; long size;
long zSize; long zSize;
ubyte[] content; ubyte[] content;
string createdUtc; DateTime createdUtc;
string lastSeenUtc; DateTime lastSeenUtc;
long refcount; long refcount;
bool zstd; bool zstd;
} }

3
source/cdcdb/version_.d Normal file
View file

@ -0,0 +1,3 @@
module cdcdb.version_;
enum cdcdbVersion = "0.0.1";

View file

@ -7,5 +7,10 @@ import std.file : read;
void main() void main()
{ {
auto cas = new CAS("/tmp/base.db", true); 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);
} }