actix-extras
actix-extras copied to clipboard
session: Add Sqlite session backend
PR Type
Feature
PR Checklist
- [x] Tests for the changes have been added / updated.
- [x] Documentation comments have been added / updated.
- [x] A changelog entry has been made for the appropriate packages.
- [x] Format code with the nightly rustfmt (
cargo +nightly fmt).
Overview
Implemented Sqlite session backend. The database/table will get created automatically if they don't exist.
Default garbage collection of stale sessions happens through a database trigger. (it can be turned off and the trigger will be dropped, and garbage collection can be implemented outside if needed.)
I fixed the doctest errors in sqlite.rs (SqliteSessionStore), but I still have these errors locally and I'm not sure what am I missing:
running 11 tests
test src/lib.rs - (line 70) - compile ... ok
test src/lib.rs - (line 41) - compile ... FAILED
test src/middleware.rs - middleware::SessionMiddleware (line 48) - compile ... FAILED
test src/middleware.rs - middleware::SessionMiddleware (line 81) - compile ... FAILED
test src/storage/cookie.rs - storage::cookie::CookieSessionStore (line 14) - compile ... ok
test src/storage/sqlite.rs - storage::sqlite::SqliteSessionStore (line 17) - compile ... ok
test src/session.rs - session::Session (line 265) ... ok
test src/config.rs - config::SessionMiddlewareBuilder<Store>::session_lifecycle (line 252) ... ok
test src/config.rs - config::PersistentSession (line 102) ... ok
test src/session.rs - session::Session (line 25) ... ok
test src/storage/session_key.rs - storage::session_key::SessionKey (line 12) ... ok
failures:
---- src/lib.rs - (line 41) stdout ----
error[E0432]: unresolved import `actix_session::storage::RedisActorSessionStore`
--> src/lib.rs:43:49
|
4 | use actix_session::{Session, SessionMiddleware, storage::RedisActorSessionStore};
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `RedisActorSessionStore` in `storage`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0432`.
Couldn't compile the test.
---- src/middleware.rs - middleware::SessionMiddleware (line 48) stdout ----
error[E0432]: unresolved import `actix_session::storage::RedisActorSessionStore`
--> src/middleware.rs:50:49
|
4 | use actix_session::{Session, SessionMiddleware, storage::RedisActorSessionStore};
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `RedisActorSessionStore` in `storage`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0432`.
Couldn't compile the test.
---- src/middleware.rs - middleware::SessionMiddleware (line 81) stdout ----
error[E0432]: unresolved import `actix_session::storage::RedisActorSessionStore`
--> src/middleware.rs:83:49
|
4 | use actix_session::{Session, SessionMiddleware, storage::RedisActorSessionStore};
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `RedisActorSessionStore` in `storage`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0432`.
Couldn't compile the test.
failures:
src/lib.rs - (line 41)
src/middleware.rs - middleware::SessionMiddleware (line 48)
src/middleware.rs - middleware::SessionMiddleware (line 81)
test result: FAILED. 8 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out; finished in 4.53s
Any suggestions please ?
Left a bunch of comments - sorry for the long delay!
Another issue that needs to be addressed: rustqlite offers a sync API, while we are running in an async context. We'll need to spawn the queries on the blocking task pool to avoid blocking the runtime.
@bbogdan95 , will you be able to complete this?