Добавлено количество снимков в объект StorageFile
This commit is contained in:
parent
3eaae341aa
commit
83769410c3
3 changed files with 68 additions and 15 deletions
|
|
@ -14,6 +14,7 @@ import cdcdb.lib;
|
|||
struct DBFile {
|
||||
Identifier id;
|
||||
string path;
|
||||
long countSnapshots;
|
||||
|
||||
@trusted pure nothrow @nogc @property bool empty() const {
|
||||
return id.empty();
|
||||
|
|
@ -224,7 +225,13 @@ public:
|
|||
DBFile[] getFiles() {
|
||||
auto queryResult = sql(
|
||||
q{
|
||||
SELECT id, name FROM files
|
||||
SELECT
|
||||
f.id,
|
||||
f.name,
|
||||
count(s.file) count_snapshots
|
||||
FROM files f
|
||||
JOIN snapshots s ON s.file = f.id
|
||||
GROUP BY f.id
|
||||
}
|
||||
);
|
||||
|
||||
|
|
@ -236,6 +243,7 @@ public:
|
|||
|
||||
file.id = row["id"].as!Blob(Blob.init);
|
||||
file.path = row["name"].as!string;
|
||||
file.countSnapshots = row["count_snapshots"].as!long;
|
||||
|
||||
files ~= file;
|
||||
}
|
||||
|
|
@ -246,7 +254,13 @@ public:
|
|||
DBFile getFile(string path) {
|
||||
auto queryResult = sql(
|
||||
q{
|
||||
SELECT id FROM files WHERE name = ?1
|
||||
SELECT
|
||||
f.id,
|
||||
count(s.file) count_snapshots
|
||||
FROM files f
|
||||
JOIN snapshots s ON s.file = f.id
|
||||
WHERE f.name = ?1
|
||||
GROUP BY f.id
|
||||
}, path
|
||||
);
|
||||
|
||||
|
|
@ -257,6 +271,7 @@ public:
|
|||
|
||||
file.id = data["id"].as!Blob(Blob.init);
|
||||
file.path = path;
|
||||
file.countSnapshots = data["count_snapshots"].as!long;
|
||||
}
|
||||
|
||||
return file;
|
||||
|
|
@ -265,9 +280,14 @@ public:
|
|||
DBFile getFile(Identifier id) {
|
||||
auto queryResult = sql(
|
||||
q{
|
||||
SELECT id, name
|
||||
FROM files
|
||||
WHERE id = ?1
|
||||
SELECT
|
||||
f.id,
|
||||
f.name,
|
||||
count(s.file) count_snapshots
|
||||
FROM files f
|
||||
JOIN snapshots s ON s.file = f.id
|
||||
WHERE f.id = ?1
|
||||
GROUP BY f.id
|
||||
}, id[]
|
||||
);
|
||||
|
||||
|
|
@ -278,6 +298,7 @@ public:
|
|||
|
||||
file.id = id;
|
||||
file.path = data["name"].as!string;
|
||||
file.countSnapshots = data["count_snapshots"].as!long;
|
||||
}
|
||||
|
||||
return file;
|
||||
|
|
@ -313,7 +334,14 @@ public:
|
|||
DBFile[] findFile(string pattern) {
|
||||
auto queryResult = sql(
|
||||
q{
|
||||
SELECT id, name FROM files WHERE name LIKE ?1
|
||||
SELECT
|
||||
f.id,
|
||||
f.name,
|
||||
count(s.file) count_snapshots
|
||||
FROM files f
|
||||
JOIN snapshots s ON s.file = f.id
|
||||
WHERE f.name LIKE ?1
|
||||
GROUP BY f.id
|
||||
}, '%' ~ pattern ~ '%'
|
||||
);
|
||||
|
||||
|
|
@ -325,6 +353,7 @@ public:
|
|||
|
||||
file.id = row["id"].as!Blob(Blob.init);
|
||||
file.path = row["name"].as!string;
|
||||
file.countSnapshots = row["count_snapshots"].as!long;
|
||||
|
||||
files ~= file;
|
||||
}
|
||||
|
|
@ -338,14 +367,19 @@ public:
|
|||
DBFile[] findFile(Identifier id) {
|
||||
auto queryResult = sql(
|
||||
q{
|
||||
SELECT id, name
|
||||
FROM files
|
||||
SELECT
|
||||
f.id,
|
||||
f.name,
|
||||
count(s.file) count_snapshots
|
||||
FROM files f
|
||||
JOIN snapshots s ON s.file = f.id
|
||||
WHERE length(?1) BETWEEN 1 AND 16
|
||||
AND CASE
|
||||
WHEN substr(hex(?1), 2 * length(?1), 1) = '0'
|
||||
THEN instr(hex(id), substr(hex(?1), 1, 2 * length(?1) - 1)) > 0
|
||||
ELSE substr(id, 1, length(?1)) = ?1
|
||||
THEN instr(hex(f.id), substr(hex(?1), 1, 2 * length(?1) - 1)) > 0
|
||||
ELSE substr(f.id, 1, length(?1)) = ?1
|
||||
END
|
||||
GROUP BY f.id
|
||||
}, id[]
|
||||
);
|
||||
|
||||
|
|
@ -357,6 +391,7 @@ public:
|
|||
|
||||
file.id = row["id"].as!Blob(Blob.init);
|
||||
file.path = row["name"].as!string;
|
||||
file.countSnapshots = row["count_snapshots"].as!long;
|
||||
|
||||
files ~= file;
|
||||
}
|
||||
|
|
@ -650,6 +685,7 @@ public:
|
|||
s.id,
|
||||
f.id file_id,
|
||||
f.name file_name,
|
||||
count(sc.file) count_snapshots,
|
||||
s.sha256,
|
||||
s.description,
|
||||
s.created_utc,
|
||||
|
|
@ -671,6 +707,8 @@ public:
|
|||
JOIN users u ON u.uid = s.uid
|
||||
JOIN users r ON r.uid = s.ruid
|
||||
JOIN files f ON f.id = s.file AND (length(?) = 0 OR f.name = ?1)
|
||||
JOIN snapshots sc ON f.id = sc.file
|
||||
GROUP BY s.id
|
||||
ORDER BY s.created_utc
|
||||
}, file
|
||||
);
|
||||
|
|
@ -684,7 +722,8 @@ public:
|
|||
snapshot.id = row["id"].as!Blob(Blob.init);
|
||||
snapshot.file = DBFile(
|
||||
Identifier(row["file_id"].as!Blob(Blob.init)),
|
||||
row["file_name"].as!string
|
||||
row["file_name"].as!string,
|
||||
row["count_snapshots"].as!long
|
||||
);
|
||||
snapshot.sha256 = row["sha256"].as!Blob(Blob.init);
|
||||
snapshot.description = row["description"].as!string(""); // может быть NULL
|
||||
|
|
@ -719,6 +758,7 @@ public:
|
|||
s.id,
|
||||
f.id file_id,
|
||||
f.name file_name,
|
||||
count(sc.file) count_snapshots,
|
||||
s.sha256,
|
||||
s.description,
|
||||
s.created_utc,
|
||||
|
|
@ -740,7 +780,9 @@ public:
|
|||
JOIN users u ON u.uid = s.uid
|
||||
JOIN users r ON r.uid = s.ruid
|
||||
JOIN files f ON f.id = s.file
|
||||
JOIN snapshots sc ON f.id = sc.file
|
||||
WHERE f.id = ?1
|
||||
GROUP BY s.id
|
||||
ORDER BY s.created_utc
|
||||
}, id[]
|
||||
);
|
||||
|
|
@ -754,7 +796,8 @@ public:
|
|||
snapshot.id = row["id"].as!Blob(Blob.init);
|
||||
snapshot.file = DBFile(
|
||||
Identifier(row["file_id"].as!Blob(Blob.init)),
|
||||
row["file_name"].as!string
|
||||
row["file_name"].as!string,
|
||||
row["count_snapshots"].as!long
|
||||
);
|
||||
snapshot.sha256 = row["sha256"].as!Blob(Blob.init);
|
||||
snapshot.description = row["description"].as!string("");
|
||||
|
|
@ -788,6 +831,7 @@ public:
|
|||
s.id,
|
||||
f.id file_id,
|
||||
f.name file_name,
|
||||
count(sc.file) count_snapshots,
|
||||
s.sha256,
|
||||
s.description,
|
||||
s.created_utc,
|
||||
|
|
@ -809,7 +853,9 @@ public:
|
|||
JOIN users u ON u.uid = s.uid
|
||||
JOIN users r ON r.uid = s.ruid
|
||||
JOIN files f ON f.id = s.file
|
||||
JOIN snapshots sc ON f.id = sc.file
|
||||
WHERE s.id = ?1
|
||||
GROUP BY s.id
|
||||
ORDER BY s.created_utc
|
||||
}, id[]
|
||||
);
|
||||
|
|
@ -822,7 +868,8 @@ public:
|
|||
snapshot.id = data["id"].as!Blob(Blob.init);
|
||||
snapshot.file = DBFile(
|
||||
Identifier(data["file_id"].as!Blob(Blob.init)),
|
||||
data["file_name"].as!string
|
||||
data["file_name"].as!string,
|
||||
data["count_snapshots"].as!long
|
||||
);
|
||||
snapshot.sha256 = data["sha256"].as!Blob(Blob.init);
|
||||
snapshot.description = data["description"].as!string("");
|
||||
|
|
@ -857,6 +904,7 @@ public:
|
|||
s.id,
|
||||
f.id file_id,
|
||||
f.name file_name,
|
||||
count(sc.file) count_snapshots,
|
||||
s.sha256,
|
||||
s.description,
|
||||
s.created_utc,
|
||||
|
|
@ -878,12 +926,15 @@ public:
|
|||
JOIN users u ON u.uid = s.uid
|
||||
JOIN users r ON r.uid = s.ruid
|
||||
JOIN files f ON f.id = s.file
|
||||
JOIN snapshots sc ON f.id = sc.file
|
||||
WHERE length(?1) BETWEEN 1 AND 16
|
||||
AND CASE
|
||||
WHEN substr(hex(?1), 2 * length(?1), 1) = '0'
|
||||
THEN instr(hex(s.id), substr(hex(?1), 1, 2 * length(?1) - 1)) > 0
|
||||
ELSE substr(s.id, 1, length(?1)) = ?1
|
||||
END
|
||||
GROUP BY s.id
|
||||
ORDER BY s.created_utc
|
||||
}, id[]
|
||||
);
|
||||
|
||||
|
|
@ -896,7 +947,8 @@ public:
|
|||
snapshot.id = row["id"].as!Blob(Blob.init);
|
||||
snapshot.file = DBFile(
|
||||
Identifier(row["file_id"].as!Blob(Blob.init)),
|
||||
row["file_name"].as!string
|
||||
row["file_name"].as!string,
|
||||
row["count_snapshots"].as!long
|
||||
);
|
||||
snapshot.sha256 = row["sha256"].as!Blob(Blob.init);
|
||||
snapshot.description = row["description"].as!string("");
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ public:
|
|||
|
||||
@property ref Identifier id() return { return _dbfile.id; }
|
||||
@property string name() const nothrow @safe { return _dbfile.path; }
|
||||
@property long countSnapshots() const nothrow @safe { return _dbfile.countSnapshots; }
|
||||
|
||||
Snapshot[] snapshots() {
|
||||
Snapshot[] snapshots;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
module cdcdb.version_;
|
||||
|
||||
enum cdcdbVersion = "0.2.0";
|
||||
enum cdcdbVersion = "0.2.1";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue