[server] Move fs code around

This commit is contained in:
Abhishek Shroff
2025-06-05 21:01:16 +05:30
parent 7e9339d83a
commit dd276db109
2 changed files with 23 additions and 28 deletions
+23
View File
@@ -8,6 +8,7 @@ import (
"github.com/doug-martin/goqu/v9"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
)
@@ -229,3 +230,25 @@ func (f filesystem) insertResource(id, parent uuid.UUID, name string, dir bool,
return r, err
}
}
func (f filesystem) updateResourceModified(id uuid.UUID) error {
const q = "UPDATE resources SET modified = NOW() WHERE id = $1"
_, err := f.db.Exec(q, id)
return err
}
func (f filesystem) createResourceVersion(id, versionID uuid.UUID, size int64, mimeType, sha256 string) error {
const q = `INSERT INTO resource_versions(id, resource_id, size, mime_type, sha256, storage)
VALUES (@version_id::UUID, @resource_id::UUID, @size::INT, @mime_type::TEXT, @sha256::TEXT, @storage::TEXT)`
args := pgx.NamedArgs{
"resource_id": id,
"version_id": versionID,
"size": size,
"mime_type": mimeType,
"sha256": sha256,
"storage": "_",
}
_, err := f.db.Exec(q, args)
return err
}
-28
View File
@@ -1,28 +0,0 @@
package core
import (
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
)
func (f filesystem) updateResourceModified(id uuid.UUID) error {
const q = "UPDATE resources SET modified = NOW() WHERE id = $1"
_, err := f.db.Exec(q, id)
return err
}
func (f filesystem) createResourceVersion(id, versionID uuid.UUID, size int64, mimeType, sha256 string) error {
const q = `INSERT INTO resource_versions(id, resource_id, size, mime_type, sha256, storage)
VALUES (@version_id::UUID, @resource_id::UUID, @size::INT, @mime_type::TEXT, @sha256::TEXT, @storage::TEXT)`
args := pgx.NamedArgs{
"resource_id": id,
"version_id": versionID,
"size": size,
"mime_type": mimeType,
"sha256": sha256,
"storage": "_",
}
_, err := f.db.Exec(q, args)
return err
}