diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml index c76fc9e0142c2fcf4f65c31a645e82b9ffe65ea1..5baa3133bfb8ddecca203c18fb6ecc0d4aed8c7e 100644 --- a/.gitea/workflows/test.yaml +++ b/.gitea/workflows/test.yaml @@ -1,12 +1,31 @@ # name: Format, check and test -name: cargo-check +name: format, check and test on: [push, pull_request] jobs: - check: - name: cargo check + format: + name: cargo fmt runs-on: ubuntu-latest steps: - uses: https://github.com/actions/checkout@v3 - uses: https://github.com/dtolnay/rust-toolchain@stable - - run: cargo check --all-features \ No newline at end of file + with: + components: rustfmt + - run: cargo fmt --all-features + + clippy: + name: cargo clippy + runs-on: ubuntu-latest + steps: + - uses: https://github.com/actions/checkout@v3 + - uses: https://github.com/dtolnay/rust-toolchain@stable + with: + components: clippy + - run: cargo clippy --all-features + test: + name: cargo test + runs-on: ubuntu-latest + steps: + - uses: https://github.com/actions/checkout@v3 + - uses: https://github.com/dtolnay/rust-toolchain@stable + - run: cargo test --all-features \ No newline at end of file diff --git a/.gitignore b/.gitignore index db1ea7c0081913974bae240e64d2e919c2e92739..56c238caaf7f34aa0f2a0c181d24c861c768b39e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ /target files.db /files/ -ephemeral.db +ephemeral-testing.db .timetracker ephemeral.db-shm ephemeral.db-wal diff --git a/config.sample.toml b/config.sample.toml index bef07c126ee9ec652d713958232c99487fe1fb0f..86b19f84c79e0e1f9812ea13fe964e996148f319 100644 --- a/config.sample.toml +++ b/config.sample.toml @@ -12,9 +12,11 @@ nginx_sendfile = false ## Available SQL backends: sqlite, postgres sql_backend = "sqlite" -# URL for postgres, see below for more information +# URL for the database, supporting both postgres and sqlite # https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING -postgres_url = "postgres://ephemeral:changeme@localhost:5432/ephemeral" +# url = "postgres://ephemeral:changeme@localhost:5432/ephemeral" + +url = "sqlite://ephemeral.db" [logging] # Controls the logging level of the ephemeral program, and the crates it uses. diff --git a/config.toml b/config.toml index 562edb5a566ae6cef91f7b50871675307a71cc35..4177af70afae5d23be4b521df9b4a7879599dae1 100644 --- a/config.toml +++ b/config.toml @@ -12,9 +12,11 @@ nginx_sendfile = false ## Available SQL backends: sqlite, postgres sql_backend = "sqlite" -# URL for postgres, see below for more information +# URL for the database, supporting both postgres and sqlite # https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING -postgres_url = "postgres://ephemeral:changeme@localhost:5432/ephemeral" +# url = "postgres://ephemeral:changeme@localhost:5432/ephemeral" + +url = "sqlite://ephemeral-testing.db" [logging] # Controls the logging level of the ephemeral program, and the crates it uses. diff --git a/ephemeral.db b/ephemeral.db new file mode 100644 index 0000000000000000000000000000000000000000..b95469fa030059c744925a09e1cbd0f6c7f05cbc Binary files /dev/null and b/ephemeral.db differ diff --git a/src/main.rs b/src/main.rs index 86691f8f55115cbf2a663cc302de5efc4b3c223b..ba8a09f423248a807eb10253785d4f2d67ea16e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,12 +54,16 @@ async fn main() { let sql = CONFIG .get_string("database.sql_backend") .expect("Couldn't find 'sql_backend' in config. :("); + // Pipe SQL url to database initialization + let sqlurl = CONFIG + .get_string("database.url") + .expect("Couldn't find 'url' in config. :("); // This /might be able to be a match statement, but I couldn't figure it out and want to go to bed. // REVIEW: yeah do a match. Also I'm pretty sure there is an enum somewhere you can match instead of strings if sql == "sqlite" { tracing::info!("Using SQLite backend"); - let pool = SqlitePool::connect("sqlite:ephemeral.db").await.unwrap(); + let pool = SqlitePool::connect(&sqlurl).await.unwrap(); SQLITE.set(pool).unwrap(); } else if sql == "postgres" { tracing::info!("Using Postgres backend");