Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bump sqlx to 0.7.1 #33

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ async_std = ["async-std"]
mysql = ["sqlx/mysql", "sqlx/json"]

[dependencies]
async-session = "3.0.0"
sqlx = { version = "0.6.2", features = ["chrono"] }
async-session = { git = "https://github.com/http-rs/async-session", branch = "main"}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fairly dangerous.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, on the other hand, there's been no release in over 2 years and some of the deps updates are required for sqlx 0.7.1

sqlx = { version = "0.7.1", features = [ "time" ] }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the logic for switching to time here? That seems unrelated to upgrading.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to async-session moving away from chrono and to time
http-rs/async-session#35

async-std = { version = "1.12.0", optional = true }
time = "0.3.18"

[dev-dependencies]
async-std = { version = "1.12.0", features = ["attributes"] }

[dev-dependencies.sqlx]
version = "0.6.2"
features = ["chrono", "runtime-async-std-native-tls"]
version = "0.7.1"
features = ["runtime-async-std-native-tls"]
26 changes: 13 additions & 13 deletions src/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl MySqlSessionStore {
let mut connection = self.connection().await?;
sqlx::query(&self.substitute_table_name("DELETE FROM %%TABLE_NAME%% WHERE expires < ?"))
.bind(Utc::now())
.execute(&mut connection)
.execute(&mut *connection)
.await?;

Ok(())
Expand All @@ -261,7 +261,7 @@ impl MySqlSessionStore {
pub async fn count(&self) -> sqlx::Result<i64> {
let (count,) =
sqlx::query_as(&self.substitute_table_name("SELECT COUNT(*) FROM %%TABLE_NAME%%"))
.fetch_one(&mut self.connection().await?)
.fetch_one(&mut *self.connection().await?)
.await?;

Ok(count)
Expand All @@ -279,7 +279,7 @@ impl SessionStore for MySqlSessionStore {
))
.bind(&id)
.bind(Utc::now())
.fetch_optional(&mut connection)
.fetch_optional(&mut *connection)
.await?;

Ok(result
Expand All @@ -304,7 +304,7 @@ impl SessionStore for MySqlSessionStore {
.bind(&id)
.bind(&string)
.bind(&session.expiry())
.execute(&mut connection)
.execute(&mut *connection)
.await?;

Ok(session.into_cookie_value())
Expand All @@ -315,7 +315,7 @@ impl SessionStore for MySqlSessionStore {
let mut connection = self.connection().await?;
sqlx::query(&self.substitute_table_name("DELETE FROM %%TABLE_NAME%% WHERE id = ?"))
.bind(&id)
.execute(&mut connection)
.execute(&mut *connection)
.await?;

Ok(())
Expand All @@ -324,7 +324,7 @@ impl SessionStore for MySqlSessionStore {
async fn clear_store(&self) -> Result {
let mut connection = self.connection().await?;
sqlx::query(&self.substitute_table_name("TRUNCATE %%TABLE_NAME%%"))
.execute(&mut connection)
.execute(&mut *connection)
.await?;

Ok(())
Expand Down Expand Up @@ -360,9 +360,9 @@ mod tests {
let cloned = session.clone();
let cookie_value = store.store_session(session).await?.unwrap();

let (id, expires, serialized, count): (String, Option<DateTime<Utc>>, String, i64) =
let (id, expires, serialized, count): (String, Option<DateTime>, String, i64) =
sqlx::query_as("select id, expires, session, (select count(*) from async_sessions) from async_sessions")
.fetch_one(&mut store.connection().await?)
.fetch_one(&mut *store.connection().await?)
.await?;

assert_eq!(1, count);
Expand Down Expand Up @@ -399,7 +399,7 @@ mod tests {

let (id, count): (String, i64) =
sqlx::query_as("select id, (select count(*) from async_sessions) from async_sessions")
.fetch_one(&mut store.connection().await?)
.fetch_one(&mut *store.connection().await?)
.await?;

assert_eq!(1, count);
Expand All @@ -426,10 +426,10 @@ mod tests {
let session = store.load_session(cookie_value.clone()).await?.unwrap();
assert_eq!(session.expiry().unwrap(), &new_expires);

let (id, expires, count): (String, DateTime<Utc>, i64) = sqlx::query_as(
let (id, expires, count): (String, DateTime, i64) = sqlx::query_as(
"select id, expires, (select count(*) from async_sessions) from async_sessions",
)
.fetch_one(&mut store.connection().await?)
.fetch_one(&mut *store.connection().await?)
.await?;

assert_eq!(1, count);
Expand All @@ -449,9 +449,9 @@ mod tests {

let cookie_value = store.store_session(session).await?.unwrap();

let (id, expires, serialized, count): (String, Option<DateTime<Utc>>, String, i64) =
let (id, expires, serialized, count): (String, Option<DateTime>, String, i64) =
sqlx::query_as("select id, expires, session, (select count(*) from async_sessions) from async_sessions")
.fetch_one(&mut store.connection().await?)
.fetch_one(&mut *store.connection().await?)
.await?;

assert_eq!(1, count);
Expand Down
44 changes: 23 additions & 21 deletions src/pg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use async_session::{async_trait, chrono::Utc, log, serde_json, Result, Session, SessionStore};
use async_session::{async_trait, log, serde_json, Result, Session, SessionStore};
use sqlx::{pool::PoolConnection, Executor, PgPool, Postgres};

use time::OffsetDateTime as DateTime;

/// sqlx postgres session store for async-sessions
///
/// ```rust
Expand Down Expand Up @@ -216,13 +218,14 @@ impl PostgresSessionStore {
/// (expired) sessions. You may want to call this from cron.
/// ```rust
/// # use async_sqlx_session::PostgresSessionStore;
/// # use async_session::{chrono::{Utc,Duration}, Result, SessionStore, Session};
/// # use async_session::{Result, SessionStore, Session};
/// # use time::Duration;
/// # fn main() -> Result { async_std::task::block_on(async {
/// let store = PostgresSessionStore::new(&std::env::var("PG_TEST_DB_URL").unwrap()).await?;
/// store.migrate().await?;
/// # store.clear_store().await?;
/// let mut session = Session::new();
/// session.set_expiry(Utc::now() - Duration::seconds(5));
/// session.set_expiry(time::OffsetDateTime::now_utc() - Duration::seconds(5));
/// store.store_session(session).await?;
/// assert_eq!(store.count().await?, 1);
/// store.cleanup().await?;
Expand All @@ -232,8 +235,8 @@ impl PostgresSessionStore {
pub async fn cleanup(&self) -> sqlx::Result<()> {
let mut connection = self.connection().await?;
sqlx::query(&self.substitute_table_name("DELETE FROM %%TABLE_NAME%% WHERE expires < $1"))
.bind(Utc::now())
.execute(&mut connection)
.bind(DateTime::now_utc())
.execute(&mut *connection)
.await?;

Ok(())
Expand All @@ -259,7 +262,7 @@ impl PostgresSessionStore {
pub async fn count(&self) -> sqlx::Result<i64> {
let (count,) =
sqlx::query_as(&self.substitute_table_name("SELECT COUNT(*) FROM %%TABLE_NAME%%"))
.fetch_one(&mut self.connection().await?)
.fetch_one(&mut *self.connection().await?)
.await?;

Ok(count)
Expand All @@ -276,8 +279,8 @@ impl SessionStore for PostgresSessionStore {
"SELECT session FROM %%TABLE_NAME%% WHERE id = $1 AND (expires IS NULL OR expires > $2)"
))
.bind(&id)
.bind(Utc::now())
.fetch_optional(&mut connection)
.bind(DateTime::now_utc())
.fetch_optional(&mut *connection)
.await?;

Ok(result
Expand All @@ -302,7 +305,7 @@ impl SessionStore for PostgresSessionStore {
.bind(&id)
.bind(&string)
.bind(&session.expiry())
.execute(&mut connection)
.execute(&mut *connection)
.await?;

Ok(session.into_cookie_value())
Expand All @@ -313,7 +316,7 @@ impl SessionStore for PostgresSessionStore {
let mut connection = self.connection().await?;
sqlx::query(&self.substitute_table_name("DELETE FROM %%TABLE_NAME%% WHERE id = $1"))
.bind(&id)
.execute(&mut connection)
.execute(&mut *connection)
.await?;

Ok(())
Expand All @@ -322,7 +325,7 @@ impl SessionStore for PostgresSessionStore {
async fn clear_store(&self) -> Result {
let mut connection = self.connection().await?;
sqlx::query(&self.substitute_table_name("TRUNCATE %%TABLE_NAME%%"))
.execute(&mut connection)
.execute(&mut *connection)
.await?;

Ok(())
Expand All @@ -332,7 +335,6 @@ impl SessionStore for PostgresSessionStore {
#[cfg(test)]
mod tests {
use super::*;
use async_session::chrono::DateTime;
use std::time::Duration;

async fn test_store() -> PostgresSessionStore {
Expand All @@ -358,9 +360,9 @@ mod tests {
let cloned = session.clone();
let cookie_value = store.store_session(session).await?.unwrap();

let (id, expires, serialized, count): (String, Option<DateTime<Utc>>, String, i64) =
let (id, expires, serialized, count): (String, Option<DateTime>, String, i64) =
sqlx::query_as("select id, expires, session, (select count(*) from async_sessions) from async_sessions")
.fetch_one(&mut store.connection().await?)
.fetch_one(&mut *store.connection().await?)
.await?;

assert_eq!(1, count);
Expand Down Expand Up @@ -397,7 +399,7 @@ mod tests {

let (id, count): (String, i64) =
sqlx::query_as("select id, (select count(*) from async_sessions) from async_sessions")
.fetch_one(&mut store.connection().await?)
.fetch_one(&mut *store.connection().await?)
.await?;

assert_eq!(1, count);
Expand All @@ -424,14 +426,14 @@ mod tests {
let session = store.load_session(cookie_value.clone()).await?.unwrap();
assert_eq!(session.expiry().unwrap(), &new_expires);

let (id, expires, count): (String, DateTime<Utc>, i64) = sqlx::query_as(
let (id, expires, count): (String, DateTime, i64) = sqlx::query_as(
"select id, expires, (select count(*) from async_sessions) from async_sessions",
)
.fetch_one(&mut store.connection().await?)
.fetch_one(&mut *store.connection().await?)
.await?;

assert_eq!(1, count);
assert_eq!(expires.timestamp_millis(), new_expires.timestamp_millis());
assert_eq!(expires.unix_timestamp(), new_expires.unix_timestamp());
assert_eq!(original_id, id);

Ok(())
Expand All @@ -447,14 +449,14 @@ mod tests {

let cookie_value = store.store_session(session).await?.unwrap();

let (id, expires, serialized, count): (String, Option<DateTime<Utc>>, String, i64) =
let (id, expires, serialized, count): (String, Option<DateTime>, String, i64) =
sqlx::query_as("select id, expires, session, (select count(*) from async_sessions) from async_sessions")
.fetch_one(&mut store.connection().await?)
.fetch_one(&mut *store.connection().await?)
.await?;

assert_eq!(1, count);
assert_eq!(id, cloned.id());
assert!(expires.unwrap() > Utc::now());
assert!(expires.unwrap() > DateTime::now_utc());

let deserialized_session: Session = serde_json::from_str(&serialized)?;
assert_eq!(cloned.id(), deserialized_session.id());
Expand Down
20 changes: 10 additions & 10 deletions src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl SqliteSessionStore {
"#,
))
.bind(Utc::now().timestamp())
.execute(&mut connection)
.execute(&mut *connection)
.await?;

Ok(())
Expand All @@ -263,7 +263,7 @@ impl SqliteSessionStore {
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(&mut *self.connection().await?)
.await?;

Ok(count)
Expand All @@ -284,7 +284,7 @@ impl SessionStore for SqliteSessionStore {
))
.bind(&id)
.bind(Utc::now().timestamp())
.fetch_optional(&mut connection)
.fetch_optional(&mut *connection)
.await?;

Ok(result
Expand All @@ -309,7 +309,7 @@ impl SessionStore for SqliteSessionStore {
.bind(&id)
.bind(&string)
.bind(&session.expiry().map(|expiry| expiry.timestamp()))
.execute(&mut connection)
.execute(&mut *connection)
.await?;

Ok(session.into_cookie_value())
Expand All @@ -324,7 +324,7 @@ impl SessionStore for SqliteSessionStore {
"#,
))
.bind(&id)
.execute(&mut connection)
.execute(&mut *connection)
.await?;

Ok(())
Expand All @@ -337,7 +337,7 @@ impl SessionStore for SqliteSessionStore {
DELETE FROM %%TABLE_NAME%%
"#,
))
.execute(&mut connection)
.execute(&mut *connection)
.await?;

Ok(())
Expand Down Expand Up @@ -370,7 +370,7 @@ mod tests {

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(&mut *store.connection().await?)
.await?;

assert_eq!(1, count);
Expand Down Expand Up @@ -406,7 +406,7 @@ mod tests {
assert_eq!(session.get::<String>("key").unwrap(), "other value");

let (id, count): (String, i64) = sqlx::query_as("select id, count(*) from async_sessions")
.fetch_one(&mut store.connection().await?)
.fetch_one(&mut *store.connection().await?)
.await?;

assert_eq!(1, count);
Expand Down Expand Up @@ -435,7 +435,7 @@ mod tests {

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(&mut *store.connection().await?)
.await?;

assert_eq!(1, count);
Expand All @@ -457,7 +457,7 @@ mod tests {

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(&mut *store.connection().await?)
.await?;

assert_eq!(1, count);
Expand Down