update to sqlx 0.7, using personal fork of axum-login
This commit is contained in:
parent
359a732a84
commit
c824a2b07a
4 changed files with 641 additions and 310 deletions
892
Cargo.lock
generated
892
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
16
Cargo.toml
16
Cargo.toml
|
@ -14,28 +14,28 @@ askama = { version = "0.12", features = ["with-axum"] }
|
|||
askama_axum = "0.3"
|
||||
async-session = "3"
|
||||
axum = { version = "0.6", features = ["macros", "headers"] }
|
||||
axum-login = { version = "0.5", features = ["sqlite", "sqlx"] }
|
||||
axum-login = { git = "https://github.com/nebkor/axum-login", branch = "sqlx-0.7", features = ["sqlite"], default-features = false }
|
||||
axum-macros = "0.3"
|
||||
chrono = { version = "0.4", default-features = false, features = ["std", "clock"] }
|
||||
clap = { version = "4.3.10", features = ["derive", "env", "unicode", "suggestions", "usage"] }
|
||||
clap = { version = "4", features = ["derive", "env", "unicode", "suggestions", "usage"] }
|
||||
justerror = "1"
|
||||
password-hash = { version = "0.5", features = ["std", "getrandom"] }
|
||||
rand = "0.8"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
sqlx = { version = "0.6", default-features = false, features = ["runtime-tokio-rustls", "any", "sqlite", "chrono", "time"] }
|
||||
sqlx = { version = "0.7", default-features = false, features = ["runtime-tokio-rustls", "sqlite", "chrono", "time"] }
|
||||
thiserror = "1"
|
||||
tokio = { version = "1", features = ["full", "tracing"], default-features = false }
|
||||
tokio-retry = "0.3.0"
|
||||
tokio-stream = "0.1.14"
|
||||
tokio-retry = "0.3"
|
||||
tokio-stream = "0.1"
|
||||
tower = { version = "0.4", features = ["util", "timeout"], default-features = false }
|
||||
tower-http = { version = "0.4", features = ["add-extension", "trace"] }
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
ulid = { version = "1", features = ["rand"] }
|
||||
unicode-segmentation = "1"
|
||||
rand_distr = "0.4.3"
|
||||
rand_distr = "0.4"
|
||||
|
||||
[dev-dependencies]
|
||||
axum-test = "9.0.0"
|
||||
serde_test = "1.0.164"
|
||||
axum-test = "9"
|
||||
serde_test = "1"
|
||||
|
||||
|
|
39
src/db.rs
39
src/db.rs
|
@ -55,15 +55,10 @@ pub fn get_db_pool() -> SqlitePool {
|
|||
let pool = SqlitePoolOptions::new()
|
||||
.max_connections(MAX_CONNS)
|
||||
.min_connections(MIN_CONNS)
|
||||
.idle_timeout(Some(Duration::from_secs(30)))
|
||||
.idle_timeout(Some(Duration::from_secs(3)))
|
||||
.max_lifetime(Some(Duration::from_secs(3600)))
|
||||
.connect_with(conn_opts);
|
||||
|
||||
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let pool = {
|
||||
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
|
@ -73,8 +68,6 @@ pub fn get_db_pool() -> SqlitePool {
|
|||
rt.block_on(pool).unwrap()
|
||||
};
|
||||
|
||||
let _con = rt.block_on(pool.acquire()).unwrap();
|
||||
|
||||
{
|
||||
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
|
@ -250,8 +243,6 @@ mod session_store {
|
|||
/// on breaking releases.
|
||||
pub async fn migrate(&self) -> sqlx::Result<()> {
|
||||
log::info!("migrating sessions on `{}`", self.table_name);
|
||||
|
||||
let mut conn = self.client.acquire().await?;
|
||||
sqlx::query(&self.substitute_table_name(
|
||||
r#"
|
||||
CREATE TABLE IF NOT EXISTS %%TABLE_NAME%% (
|
||||
|
@ -261,7 +252,7 @@ mod session_store {
|
|||
)
|
||||
"#,
|
||||
))
|
||||
.execute(&mut conn)
|
||||
.execute(&self.client)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -280,7 +271,6 @@ mod session_store {
|
|||
/// Performs a one-time cleanup task that clears out stale
|
||||
/// (expired) sessions. You may want to call this from cron.
|
||||
pub async fn cleanup(&self) -> sqlx::Result<()> {
|
||||
let mut connection = self.connection().await?;
|
||||
sqlx::query(&self.substitute_table_name(
|
||||
r#"
|
||||
DELETE FROM %%TABLE_NAME%%
|
||||
|
@ -288,7 +278,7 @@ mod session_store {
|
|||
"#,
|
||||
))
|
||||
.bind(Utc::now().timestamp())
|
||||
.execute(&mut connection)
|
||||
.execute(&self.client)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
|
@ -299,7 +289,7 @@ mod session_store {
|
|||
pub async fn count(&self) -> sqlx::Result<i32> {
|
||||
let (count,) =
|
||||
sqlx::query_as(&self.substitute_table_name("SELECT COUNT(*) FROM %%TABLE_NAME%%"))
|
||||
.fetch_one(&mut self.connection().await?)
|
||||
.fetch_one(&self.client)
|
||||
.await?;
|
||||
|
||||
Ok(count)
|
||||
|
@ -310,8 +300,6 @@ mod session_store {
|
|||
impl SessionStore for SqliteSessionStore {
|
||||
async fn load_session(&self, cookie_value: String) -> Result<Option<Session>> {
|
||||
let id = Session::id_from_cookie_value(&cookie_value)?;
|
||||
let mut connection = self.connection().await?;
|
||||
|
||||
let result: Option<(String,)> = sqlx::query_as(&self.substitute_table_name(
|
||||
r#"
|
||||
SELECT session FROM %%TABLE_NAME%%
|
||||
|
@ -320,7 +308,7 @@ mod session_store {
|
|||
))
|
||||
.bind(&id)
|
||||
.bind(Utc::now().timestamp())
|
||||
.fetch_optional(&mut connection)
|
||||
.fetch_optional(&self.client)
|
||||
.await?;
|
||||
|
||||
Ok(result
|
||||
|
@ -331,7 +319,6 @@ mod session_store {
|
|||
async fn store_session(&self, session: Session) -> Result<Option<String>> {
|
||||
let id = session.id();
|
||||
let string = serde_json::to_string(&session)?;
|
||||
let mut connection = self.connection().await?;
|
||||
|
||||
sqlx::query(&self.substitute_table_name(
|
||||
r#"
|
||||
|
@ -345,7 +332,7 @@ mod session_store {
|
|||
.bind(id)
|
||||
.bind(&string)
|
||||
.bind(session.expiry().map(|expiry| expiry.timestamp()))
|
||||
.execute(&mut connection)
|
||||
.execute(&self.client)
|
||||
.await?;
|
||||
|
||||
Ok(session.into_cookie_value())
|
||||
|
@ -353,27 +340,25 @@ mod session_store {
|
|||
|
||||
async fn destroy_session(&self, session: Session) -> Result {
|
||||
let id = session.id();
|
||||
let mut connection = self.connection().await?;
|
||||
sqlx::query(&self.substitute_table_name(
|
||||
r#"
|
||||
DELETE FROM %%TABLE_NAME%% WHERE id = ?
|
||||
"#,
|
||||
))
|
||||
.bind(id)
|
||||
.execute(&mut connection)
|
||||
.execute(&self.client)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn clear_store(&self) -> Result {
|
||||
let mut connection = self.connection().await?;
|
||||
sqlx::query(&self.substitute_table_name(
|
||||
r#"
|
||||
DELETE FROM %%TABLE_NAME%%
|
||||
"#,
|
||||
))
|
||||
.execute(&mut connection)
|
||||
.execute(&self.client)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
|
@ -408,7 +393,7 @@ mod session_store {
|
|||
|
||||
let (id, expires, serialized, count): (String, Option<i64>, String, i64) =
|
||||
sqlx::query_as("select id, expires, session, count(*) from async_sessions")
|
||||
.fetch_one(&mut store.connection().await?)
|
||||
.fetch_one(&store.client)
|
||||
.await?;
|
||||
|
||||
assert_eq!(1, count);
|
||||
|
@ -446,7 +431,7 @@ mod session_store {
|
|||
|
||||
let (id, count): (String, i64) =
|
||||
sqlx::query_as("select id, count(*) from async_sessions")
|
||||
.fetch_one(&mut store.connection().await?)
|
||||
.fetch_one(&store.client)
|
||||
.await?;
|
||||
|
||||
assert_eq!(1, count);
|
||||
|
@ -476,7 +461,7 @@ mod session_store {
|
|||
|
||||
let (id, expires, count): (String, i64, i64) =
|
||||
sqlx::query_as("select id, expires, count(*) from async_sessions")
|
||||
.fetch_one(&mut store.connection().await?)
|
||||
.fetch_one(&store.client)
|
||||
.await?;
|
||||
|
||||
assert_eq!(1, count);
|
||||
|
@ -498,7 +483,7 @@ mod session_store {
|
|||
|
||||
let (id, expires, serialized, count): (String, Option<i64>, String, i64) =
|
||||
sqlx::query_as("select id, expires, session, count(*) from async_sessions")
|
||||
.fetch_one(&mut store.connection().await?)
|
||||
.fetch_one(&store.client)
|
||||
.await?;
|
||||
|
||||
assert_eq!(1, count);
|
||||
|
|
|
@ -162,7 +162,7 @@ pub(crate) async fn add_new_watch_impl(
|
|||
.bind(watch.release_date)
|
||||
.bind(&watch.metadata_url)
|
||||
.bind(watch.added_by)
|
||||
.execute(&mut tx)
|
||||
.execute(&mut *tx)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
tracing::error!("Got error: {err}");
|
||||
|
@ -175,7 +175,7 @@ pub(crate) async fn add_new_watch_impl(
|
|||
.bind(quest.watch)
|
||||
.bind(quest.is_public)
|
||||
.bind(quest.already_watched)
|
||||
.execute(&mut tx)
|
||||
.execute(&mut *tx)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
tracing::error!("Got error: {err}");
|
||||
|
|
Loading…
Reference in a new issue