@@ -7,12 +7,12 @@ use std::time::Duration;
7
7
/// sqlx sqlite session store for async-sessions
8
8
///
9
9
/// ```rust
10
- /// use async_sqlx_session::SqliteStore ;
10
+ /// use async_sqlx_session::SqliteSessionStore ;
11
11
/// use async_session::{Session, SessionStore};
12
12
/// use std::time::Duration;
13
13
///
14
14
/// # fn main() -> async_session::Result { async_std::task::block_on(async {
15
- /// let store = SqliteStore ::new("sqlite:%3Amemory:").await?;
15
+ /// let store = SqliteSessionStore ::new("sqlite:%3Amemory:").await?;
16
16
/// store.migrate().await?;
17
17
/// store.spawn_cleanup_task(Duration::from_secs(60 * 60));
18
18
///
@@ -25,23 +25,23 @@ use std::time::Duration;
25
25
/// # Ok(()) }) }
26
26
///
27
27
#[ derive( Clone , Debug ) ]
28
- pub struct SqliteStore {
28
+ pub struct SqliteSessionStore {
29
29
client : SqlitePool ,
30
30
table_name : String ,
31
31
}
32
32
33
- impl SqliteStore {
34
- /// constructs a new SqliteStore from an existing
33
+ impl SqliteSessionStore {
34
+ /// constructs a new SqliteSessionStore from an existing
35
35
/// sqlx::SqlitePool. the default table name for this session
36
36
/// store will be "async_sessions". To override this, chain this
37
- /// with [`with_table_name`](crate::SqliteStore ::with_table_name).
37
+ /// with [`with_table_name`](crate::SqliteSessionStore ::with_table_name).
38
38
///
39
39
/// ```rust
40
- /// # use async_sqlx_session::SqliteStore ;
40
+ /// # use async_sqlx_session::SqliteSessionStore ;
41
41
/// # use async_session::Result;
42
42
/// # fn main() -> Result { async_std::task::block_on(async {
43
43
/// let pool = sqlx::SqlitePool::new("sqlite:%3Amemory:").await.unwrap();
44
- /// let store = SqliteStore ::from_client(pool)
44
+ /// let store = SqliteSessionStore ::from_client(pool)
45
45
/// .with_table_name("custom_table_name");
46
46
/// store.migrate().await;
47
47
/// # Ok(()) }) }
@@ -53,40 +53,40 @@ impl SqliteStore {
53
53
}
54
54
}
55
55
56
- /// Constructs a new SqliteStore from a sqlite: database url. note
56
+ /// Constructs a new SqliteSessionStore from a sqlite: database url. note
57
57
/// that this documentation uses the special `:memory:` sqlite
58
58
/// database for convenient testing, but a real application would
59
59
/// use a path like `sqlite:///path/to/database.db`. The default
60
60
/// table name for this session store will be "async_sessions". To
61
61
/// override this, either chain with
62
- /// [`with_table_name`](crate::SqliteStore ::with_table_name) or
62
+ /// [`with_table_name`](crate::SqliteSessionStore ::with_table_name) or
63
63
/// use
64
- /// [`new_with_table_name`](crate::SqliteStore ::new_with_table_name)
64
+ /// [`new_with_table_name`](crate::SqliteSessionStore ::new_with_table_name)
65
65
///
66
66
/// ```rust
67
- /// # use async_sqlx_session::SqliteStore ;
67
+ /// # use async_sqlx_session::SqliteSessionStore ;
68
68
/// # use async_session::Result;
69
69
/// # fn main() -> Result { async_std::task::block_on(async {
70
- /// let store = SqliteStore ::new("sqlite:%3Amemory:").await?;
70
+ /// let store = SqliteSessionStore ::new("sqlite:%3Amemory:").await?;
71
71
/// store.migrate().await;
72
72
/// # Ok(()) }) }
73
73
/// ```
74
74
pub async fn new ( database_url : & str ) -> sqlx:: Result < Self > {
75
75
Ok ( Self :: from_client ( SqlitePool :: new ( database_url) . await ?) )
76
76
}
77
77
78
- /// constructs a new SqliteStore from a sqlite: database url. the
78
+ /// constructs a new SqliteSessionStore from a sqlite: database url. the
79
79
/// default table name for this session store will be
80
80
/// "async_sessions". To override this, either chain with
81
- /// [`with_table_name`](crate::SqliteStore ::with_table_name) or
81
+ /// [`with_table_name`](crate::SqliteSessionStore ::with_table_name) or
82
82
/// use
83
- /// [`new_with_table_name`](crate::SqliteStore ::new_with_table_name)
83
+ /// [`new_with_table_name`](crate::SqliteSessionStore ::new_with_table_name)
84
84
///
85
85
/// ```rust
86
- /// # use async_sqlx_session::SqliteStore ;
86
+ /// # use async_sqlx_session::SqliteSessionStore ;
87
87
/// # use async_session::Result;
88
88
/// # fn main() -> Result { async_std::task::block_on(async {
89
- /// let store = SqliteStore ::new_with_table_name("sqlite:%3Amemory:", "custom_table_name").await?;
89
+ /// let store = SqliteSessionStore ::new_with_table_name("sqlite:%3Amemory:", "custom_table_name").await?;
90
90
/// store.migrate().await;
91
91
/// # Ok(()) }) }
92
92
/// ```
@@ -97,20 +97,20 @@ impl SqliteStore {
97
97
/// Chainable method to add a custom table name. This will panic
98
98
/// if the table name is not `[a-zA-Z0-9_-]+`.
99
99
/// ```rust
100
- /// # use async_sqlx_session::SqliteStore ;
100
+ /// # use async_sqlx_session::SqliteSessionStore ;
101
101
/// # use async_session::Result;
102
102
/// # fn main() -> Result { async_std::task::block_on(async {
103
- /// let store = SqliteStore ::new("sqlite:%3Amemory:").await?
103
+ /// let store = SqliteSessionStore ::new("sqlite:%3Amemory:").await?
104
104
/// .with_table_name("custom_name");
105
105
/// store.migrate().await;
106
106
/// # Ok(()) }) }
107
107
/// ```
108
108
///
109
109
/// ```should_panic
110
- /// # use async_sqlx_session::SqliteStore ;
110
+ /// # use async_sqlx_session::SqliteSessionStore ;
111
111
/// # use async_session::Result;
112
112
/// # fn main() -> Result { async_std::task::block_on(async {
113
- /// let store = SqliteStore ::new("sqlite:%3Amemory:").await?
113
+ /// let store = SqliteSessionStore ::new("sqlite:%3Amemory:").await?
114
114
/// .with_table_name("johnny (); drop users;");
115
115
/// # Ok(()) }) }
116
116
/// ```
@@ -137,10 +137,10 @@ impl SqliteStore {
137
137
/// exactly-once modifications to the schema of the session table
138
138
/// on breaking releases.
139
139
/// ```rust
140
- /// # use async_sqlx_session::SqliteStore ;
140
+ /// # use async_sqlx_session::SqliteSessionStore ;
141
141
/// # use async_session::{Result, SessionStore, Session};
142
142
/// # fn main() -> Result { async_std::task::block_on(async {
143
- /// let store = SqliteStore ::new("sqlite:%3Amemory:").await?;
143
+ /// let store = SqliteSessionStore ::new("sqlite:%3Amemory:").await?;
144
144
/// assert!(store.count().await.is_err());
145
145
/// store.migrate().await?;
146
146
/// store.store_session(Session::new()).await;
@@ -180,11 +180,11 @@ impl SqliteStore {
180
180
/// Spawns an async_std::task that clears out stale (expired)
181
181
/// sessions on a periodic basis.
182
182
/// ```rust
183
- /// # use async_sqlx_session::SqliteStore ;
183
+ /// # use async_sqlx_session::SqliteSessionStore ;
184
184
/// # use async_session::{Result, SessionStore, Session};
185
185
/// # use std::time::Duration;
186
186
/// # fn main() -> Result { async_std::task::block_on(async {
187
- /// let store = SqliteStore ::new("sqlite:%3Amemory:").await?;
187
+ /// let store = SqliteSessionStore ::new("sqlite:%3Amemory:").await?;
188
188
/// store.migrate().await?;
189
189
/// store.spawn_cleanup_task(Duration::from_secs(1));
190
190
/// let mut session = Session::new();
@@ -210,10 +210,10 @@ impl SqliteStore {
210
210
/// Performs a one-time cleanup task that clears out stale
211
211
/// (expired) sessions. You may want to call this from cron.
212
212
/// ```rust
213
- /// # use async_sqlx_session::SqliteStore ;
213
+ /// # use async_sqlx_session::SqliteSessionStore ;
214
214
/// # use async_session::{chrono::{Utc,Duration}, Result, SessionStore, Session};
215
215
/// # fn main() -> Result { async_std::task::block_on(async {
216
- /// let store = SqliteStore ::new("sqlite:%3Amemory:").await?;
216
+ /// let store = SqliteSessionStore ::new("sqlite:%3Amemory:").await?;
217
217
/// store.migrate().await?;
218
218
/// let mut session = Session::new();
219
219
/// session.set_expiry(Utc::now() - Duration::seconds(5));
@@ -242,11 +242,11 @@ impl SqliteStore {
242
242
/// expired sessions
243
243
///
244
244
/// ```rust
245
- /// # use async_sqlx_session::SqliteStore ;
245
+ /// # use async_sqlx_session::SqliteSessionStore ;
246
246
/// # use async_session::{Result, SessionStore, Session};
247
247
/// # use std::time::Duration;
248
248
/// # fn main() -> Result { async_std::task::block_on(async {
249
- /// let store = SqliteStore ::new("sqlite:%3Amemory:").await?;
249
+ /// let store = SqliteSessionStore ::new("sqlite:%3Amemory:").await?;
250
250
/// store.migrate().await?;
251
251
/// assert_eq!(store.count().await?, 0);
252
252
/// store.store_session(Session::new()).await;
@@ -265,7 +265,7 @@ impl SqliteStore {
265
265
}
266
266
267
267
#[ async_trait]
268
- impl SessionStore for SqliteStore {
268
+ impl SessionStore for SqliteSessionStore {
269
269
async fn load_session ( & self , cookie_value : String ) -> Option < Session > {
270
270
let id = Session :: id_from_cookie_value ( & cookie_value) . ok ( ) ?;
271
271
let mut connection = self . connection ( ) . await . ok ( ) ?;
@@ -342,14 +342,14 @@ impl SessionStore for SqliteStore {
342
342
mod tests {
343
343
use super :: * ;
344
344
345
- async fn test_store ( ) -> SqliteStore {
346
- let store = SqliteStore :: new ( "sqlite:%3Amemory:" )
345
+ async fn test_store ( ) -> SqliteSessionStore {
346
+ let store = SqliteSessionStore :: new ( "sqlite:%3Amemory:" )
347
347
. await
348
- . expect ( "building a sqlite :memory: SqliteStore " ) ;
348
+ . expect ( "building a sqlite :memory: SqliteSessionStore " ) ;
349
349
store
350
350
. migrate ( )
351
351
. await
352
- . expect ( "migrating a brand new :memory: SqliteStore " ) ;
352
+ . expect ( "migrating a brand new :memory: SqliteSessionStore " ) ;
353
353
store
354
354
}
355
355
0 commit comments