add sqlx check
This commit is contained in:
parent
acd8f234ab
commit
580d05d00c
5 changed files with 98 additions and 36 deletions
13
.github/workflows/build_and_test.yml
vendored
13
.github/workflows/build_and_test.yml
vendored
|
@ -38,3 +38,16 @@ jobs:
|
|||
run: cargo build --verbose
|
||||
- name: Run tests
|
||||
run: cargo test --verbose
|
||||
|
||||
sqlx-check:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Install sqlx-cli
|
||||
run: cargo install sqlx-cli
|
||||
- name: Initialize database
|
||||
run: mkdir -p cache && sqlite3 cache/metadata.sqlite < db_queries/init.sql
|
||||
- name: Check sqlx statements
|
||||
run: cargo sqlx prepare --check
|
||||
with:
|
||||
fail_ci_if_error: true
|
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -623,6 +623,9 @@ name = "either"
|
|||
version = "1.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding_rs"
|
||||
|
@ -1809,6 +1812,7 @@ version = "1.0.64"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
|
@ -2003,6 +2007,7 @@ dependencies = [
|
|||
"parking_lot",
|
||||
"percent-encoding",
|
||||
"rustls",
|
||||
"serde",
|
||||
"sha2",
|
||||
"smallvec",
|
||||
"sqlformat",
|
||||
|
@ -2027,9 +2032,12 @@ dependencies = [
|
|||
"either",
|
||||
"futures",
|
||||
"heck",
|
||||
"hex",
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha2",
|
||||
"sqlx-core",
|
||||
"sqlx-rt",
|
||||
|
|
|
@ -40,7 +40,7 @@ serde_repr = "0.1"
|
|||
serde_yaml = "0.8"
|
||||
simple_logger = "1"
|
||||
sodiumoxide = "0.2"
|
||||
sqlx = { version = "0.5", features = [ "runtime-actix-rustls", "sqlite", "time", "chrono", "macros" ] }
|
||||
sqlx = { version = "0.5", features = [ "runtime-actix-rustls", "sqlite", "time", "chrono", "macros", "offline" ] }
|
||||
thiserror = "1"
|
||||
tokio = { version = "1", features = [ "full", "parking_lot" ] }
|
||||
tokio-stream = { version = "0.1", features = [ "sync" ] }
|
||||
|
|
36
build.rs
36
build.rs
|
@ -1,7 +1,4 @@
|
|||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use std::str::FromStr;
|
||||
use std::{error::Error, io::Write};
|
||||
use std::error::Error;
|
||||
|
||||
use vergen::{vergen, Config, ShaKind};
|
||||
|
||||
|
@ -11,36 +8,5 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
*config.git_mut().sha_kind_mut() = ShaKind::Short;
|
||||
vergen(config)?;
|
||||
|
||||
// Initialize SQL stuff
|
||||
let project_root = std::env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
Command::new("mkdir")
|
||||
.args(["cache", "--parents"])
|
||||
.current_dir(&project_root)
|
||||
.output()?;
|
||||
|
||||
Command::new("sqlite3")
|
||||
.args(["cache/metadata.sqlite", include_str!("db_queries/init.sql")])
|
||||
.current_dir(&project_root)
|
||||
.output()?;
|
||||
|
||||
let env_var_regex = "^DATABASE_URL=sqlite:./cache/metadata.sqlite$";
|
||||
if !Command::new("grep")
|
||||
.args([env_var_regex, ".env"])
|
||||
.current_dir(&project_root)
|
||||
.output()?
|
||||
.status
|
||||
.success()
|
||||
{
|
||||
let mut path = PathBuf::from_str(&project_root)?;
|
||||
path.push(".env");
|
||||
|
||||
let mut file = std::fs::OpenOptions::new()
|
||||
.append(true)
|
||||
.create(true)
|
||||
.open(path)?;
|
||||
file.write_all(b"\nDATABASE_URL=sqlite:./cache/metadata.sqlite\n")?;
|
||||
file.sync_all()?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
75
sqlx-data.json
Normal file
75
sqlx-data.json
Normal file
|
@ -0,0 +1,75 @@
|
|||
{
|
||||
"db": "SQLite",
|
||||
"2a8aa6dd2c59241a451cd73f23547d0e94930e35654692839b5d11bb8b87703e": {
|
||||
"query": "insert into Images (id, size, accessed) values (?, ?, ?) on conflict do nothing",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 3
|
||||
},
|
||||
"nullable": []
|
||||
}
|
||||
},
|
||||
"311721fec7824c2fc3ecf53f714949a49245c11a6b622efdb04fdac24be41ba3": {
|
||||
"query": "SELECT IFNULL(SUM(size), 0) AS size FROM Images",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "size",
|
||||
"ordinal": 0,
|
||||
"type_info": "Int"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 0
|
||||
},
|
||||
"nullable": [
|
||||
true
|
||||
]
|
||||
}
|
||||
},
|
||||
"44234188e873a467ecf2c60dfb4731011e0b7afc4472339ed2ae33aee8b0c9dd": {
|
||||
"query": "select id, size from Images order by accessed asc limit 1000",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "id",
|
||||
"ordinal": 0,
|
||||
"type_info": "Text"
|
||||
},
|
||||
{
|
||||
"name": "size",
|
||||
"ordinal": 1,
|
||||
"type_info": "Int64"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 0
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false
|
||||
]
|
||||
}
|
||||
},
|
||||
"59e09d6fbcc7cd91807f6c9598e4028352b28e83e85c98d96cafd3e713b4d7b7": {
|
||||
"query": "update Images set accessed = ? where id = ? or id = ?",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 3
|
||||
},
|
||||
"nullable": []
|
||||
}
|
||||
},
|
||||
"a60501a30fd75b2a2a59f089e850343af075436a5c543a267ecb4fa841593ce9": {
|
||||
"query": "create table if not exists Images(\n id varchar primary key not null,\n size integer not null,\n accessed timestamp not null default CURRENT_TIMESTAMP\n);\ncreate index if not exists Images_accessed on Images(accessed);",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 0
|
||||
},
|
||||
"nullable": []
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue