Compare commits

...

4 commits

Author SHA1 Message Date
47b72f6f04 fix: get lock as late as possible 2024-11-15 11:56:12 -08:00
b8d8b2918a dep: sqlx 2024-11-15 11:43:31 -08:00
a831d4fc61 feat: simple records schema 2024-11-15 11:43:23 -08:00
eeac5f2575 feat: sql dev tooling 2024-11-15 10:53:47 -08:00
7 changed files with 728 additions and 17 deletions

5
.lazy.lua Normal file
View file

@ -0,0 +1,5 @@
vim.g.dbs = {
dev = "sqlite:testing.db",
}
return {}

10
.sqlfluff Normal file
View file

@ -0,0 +1,10 @@
[sqlfluff]
dialect = sqlite
[sqlfluff:layout:type:column_constraint_segment]
spacing_before = align
align_within = create_table_statement
[sqlfluff:layout:type:data_type]
spacing_before = align
align_within = create_table_statement

717
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -38,6 +38,7 @@ tower = { version = "0.5.0", features = ["util"] }
tower-http = { version = "0.5.0", features = ["fs", "trace", "limit"] } tower-http = { version = "0.5.0", features = ["fs", "trace", "limit"] }
tracing = "0.1.37" tracing = "0.1.37"
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
sqlx = { version = "0.8.2", features = ["runtime-tokio", "chrono"] }
# I want to use askama's block feature, this requires unreleased 0.13 # I want to use askama's block feature, this requires unreleased 0.13
[dependencies.askama] [dependencies.askama]

View file

@ -0,0 +1,2 @@
-- Add down migration script here
DROP TABLE IF EXISTS records;

View file

@ -0,0 +1,8 @@
-- Add up migration script here
CREATE TABLE IF NOT EXISTS records (
id INTEGER PRIMARY KEY,
uploaded TEXT NOT NULL,
file_path TEXT NOT NULL,
downloads INTEGER NOT NULL DEFAULT 0,
max_downloads INTEGER NOT NULL
) STRICT;

View file

@ -74,8 +74,8 @@ async fn upload_to_zip(
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()))?; .map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()))?;
} }
let mut records = state.records.lock().await;
let record = UploadRecord::new(archive_path); let record = UploadRecord::new(archive_path);
let mut records = state.records.lock().await;
records.insert(cache_name.clone(), record.clone()); records.insert(cache_name.clone(), record.clone());
let records_cache = records.clone(); let records_cache = records.clone();