@@ -4,19 +4,30 @@ use std::sync::Arc;
44
55use axum:: extract:: { FromRef , FromRequestParts } ;
66use axum:: http:: request:: Parts ;
7- use bb8:: Pool ;
8- use bb8_postgres:: PostgresConnectionManager ;
97use camino:: Utf8PathBuf ;
108use hyper:: StatusCode ;
119use parking_lot:: RwLock ;
12- use tokio_postgres:: config:: SslMode ;
13- use tokio_postgres:: NoTls ;
1410use tracing:: info;
1511
1612use crate :: config:: { Config , ConfigError , DbBackend } ;
17- use crate :: db:: { Database , DbError , LibsqlConn , PgPool } ;
13+ use crate :: db:: { Database , DbError } ;
1814use crate :: policy:: { LoadPolicyError , Policy } ;
1915
16+ #[ cfg( feature = "libsql" ) ]
17+ use crate :: db:: LibsqlConn ;
18+
19+ #[ cfg( feature = "postgres" ) ]
20+ use bb8:: Pool ;
21+ #[ cfg( feature = "postgres" ) ]
22+ use bb8_postgres:: PostgresConnectionManager ;
23+ #[ cfg( feature = "postgres" ) ]
24+ use tokio_postgres:: config:: SslMode ;
25+ #[ cfg( feature = "postgres" ) ]
26+ use tokio_postgres:: NoTls ;
27+
28+ #[ cfg( feature = "postgres" ) ]
29+ use crate :: db:: PgPool ;
30+
2031#[ derive( Clone ) ]
2132pub ( crate ) struct AppState {
2233 /// Request counter.
@@ -38,6 +49,19 @@ impl AppState {
3849 } ?;
3950
4051 let db: Arc < dyn Database + Send + Sync > = match config. db {
52+ #[ cfg( feature = "libsql" ) ]
53+ DbBackend :: Libsql => {
54+ #[ expect( clippy:: unwrap_used) ]
55+ let c = config. libsql . unwrap ( ) ; // already checked by `Config::validate` at the end of the load function
56+ let db_obj = libsql:: Builder :: new_local ( & c. path )
57+ . build ( )
58+ . await
59+ . map_err ( DbError :: from) ?;
60+ let conn = db_obj. connect ( ) . map_err ( DbError :: from) ?;
61+ info ! ( "Connecting to LibSQL database at {}" , c. path) ;
62+ Arc :: new ( LibsqlConn :: new ( conn) )
63+ }
64+ #[ cfg( feature = "postgres" ) ]
4165 DbBackend :: Postgres => {
4266 #[ expect( clippy:: unwrap_used) ]
4367 let c = config. postgres . unwrap ( ) ; // already checked by `Config::validate` at the end of the load function
@@ -59,17 +83,6 @@ impl AppState {
5983 info ! ( "Connecting to Postgres database {} on host {}" , c. dbname, c. host) ;
6084 Arc :: new ( PgPool :: new ( pool) )
6185 }
62- DbBackend :: Libsql => {
63- #[ expect( clippy:: unwrap_used) ]
64- let c = config. libsql . unwrap ( ) ; // already checked by `Config::validate` at the end of the load function
65- let db_obj = libsql:: Builder :: new_local ( & c. path )
66- . build ( )
67- . await
68- . map_err ( DbError :: from) ?;
69- let conn = db_obj. connect ( ) . map_err ( DbError :: from) ?;
70- info ! ( "Connecting to LibSQL database at {}" , c. path) ;
71- Arc :: new ( LibsqlConn :: new ( conn) )
72- }
7386 } ;
7487
7588 let policy = Policy :: load ( ) ?;
0 commit comments