Skip to content

Commit 7d12354

Browse files
author
Christopher Kolstad
committed
Use correct values
1 parent e32ff3f commit 7d12354

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub(crate) type SessionState = HashMap<String, String>;
111111
impl SessionStore for SqlxPostgresqlSessionStore {
112112
async fn load(&self, session_key: &SessionKey) -> Result<Option<SessionState>, LoadError> {
113113
let key = (self.configuration.cache_keygen)(session_key.as_ref());
114-
let row = sqlx::query("SELECT session_state FROM sessions WHERE key = $1 AND expiry > NOW()")
114+
let row = sqlx::query("SELECT session_state FROM sessions WHERE key = $1 AND expires > NOW()")
115115
.bind( key)
116116
.fetch_optional(&self.client_pool)
117117
.await
@@ -133,11 +133,11 @@ impl SessionStore for SqlxPostgresqlSessionStore {
133133
.map_err(SaveError::Serialization)?;
134134
let key = generate_session_key();
135135
let cache_key = (self.configuration.cache_keygen)(key.as_ref());
136-
let expiry = Utc::now() + chrono::Duration::seconds(ttl.whole_seconds() as i64);
137-
sqlx::query("INSERT INTO sessions(key, value, expiry) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING")
136+
let expires = Utc::now() + chrono::Duration::seconds(ttl.whole_seconds() as i64);
137+
sqlx::query("INSERT INTO sessions(key, session_state, expires) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING")
138138
.bind(cache_key)
139139
.bind( body)
140-
.bind( expiry)
140+
.bind( expires)
141141
.execute(&self.client_pool)
142142
.await
143143
.map_err(Into::into)
@@ -148,10 +148,10 @@ impl SessionStore for SqlxPostgresqlSessionStore {
148148
async fn update(&self, session_key: SessionKey, session_state: SessionState, ttl: &Duration) -> Result<SessionKey, UpdateError> {
149149
let body = serde_json::to_string(&session_state).map_err(Into::into).map_err(UpdateError::Serialization)?;
150150
let cache_key = (self.configuration.cache_keygen)(session_key.as_ref());
151-
let new_expiry = Utc::now() + chrono::Duration::seconds(ttl.whole_seconds());
152-
sqlx::query("UPDATE sessions SET value = $1, expiry = $2 WHERE key = $3")
151+
let new_expires = Utc::now() + chrono::Duration::seconds(ttl.whole_seconds());
152+
sqlx::query("UPDATE sessions SET session_state = $1, expires = $2 WHERE key = $3")
153153
.bind( body)
154-
.bind( new_expiry)
154+
.bind( new_expires)
155155
.bind( cache_key)
156156
.execute(&self.client_pool)
157157
.await
@@ -161,10 +161,10 @@ impl SessionStore for SqlxPostgresqlSessionStore {
161161
}
162162

163163
async fn update_ttl(&self, session_key: &SessionKey, ttl: &Duration) -> Result<(), anyhow::Error> {
164-
let new_expiry = Utc::now() + chrono::Duration::seconds(ttl.whole_seconds() as i64);
164+
let new_expires = Utc::now() + chrono::Duration::seconds(ttl.whole_seconds() as i64);
165165
let key = (self.configuration.cache_keygen)(session_key.as_ref());
166-
sqlx::query("UPDATE sessions SET expiry = $1 WHERE key = $2")
167-
.bind(new_expiry)
166+
sqlx::query("UPDATE sessions SET expires = $1 WHERE key = $2")
167+
.bind(new_expires)
168168
.bind( key)
169169
.execute(&self.client_pool)
170170
.await

tests/session_store.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ pub mod tests {
4848
.expect("Could not create table");
4949
let mut session = HashMap::new();
5050
session.insert("key".to_string(), "value".to_string());
51-
assert!(postgres_store
51+
let data = postgres_store
5252
.save(session, &time::Duration::days(1))
53-
.await
53+
.await;
54+
println!("{:#?}", data);
55+
assert!(data
5456
.is_ok());
55-
// acceptance_test_suite(move || postgres_store.clone(), true).await;
57+
//acceptance_test_suite(move || postgres_store.clone(), true).await;
5658
}
5759
}

0 commit comments

Comments
 (0)