diff options
author | Jeremy Chone <jeremy.chone@gmail.com> | 2022-06-20 17:41:48 -0700 |
---|---|---|
committer | Jeremy Chone <jeremy.chone@gmail.com> | 2022-06-20 17:41:48 -0700 |
commit | e365f3cc197f020afa3909490530c55f7beaa51e (patch) | |
tree | 8977d9418437bf9e4737d63eb1802bdcd5aded9c /README.md | |
parent | 5ffb5c1d55397162a419945eb81b942fad6603fc (diff) | |
download | FlightCore-e365f3cc197f020afa3909490530c55f7beaa51e.tar.gz FlightCore-e365f3cc197f020afa3909490530c55f7beaa51e.zip |
. add sqlx state as example
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 29 |
1 files changed, 27 insertions, 2 deletions
@@ -13,7 +13,32 @@ npm install # terminal 1 (UI localhost for hot-reload) npm run ui-dev -# terminal 2 (for the Tauri ho) -npm +# terminal 2 (for the Rust/App hot-reload) +npm run tauri dev ``` +## Database Pool as state + +Rather to have a simple Mutex for the state, database can be used. + +``` +sqlx = { version = "0.6", features = [ "runtime-tokio-rustls", "postgres" ] } +``` + +```rs +let con_string = format!("postgres://postgres:postgres@localhost/postgres"); +let db = PgPoolOptions::new() + .max_connections(5) + .connect(&con_string) + .await + .expect("Cannot create PgPool"); + +let arc_db = Arc::new(db); +``` + +Then + +```rs +tauri::Builder::default() + .manage(arc_db) +```
\ No newline at end of file |