blob: 272d2dae60d43369b02ab48c5a8dcf843ddd5aa9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
Source code for the [Rust Tauri Introduction Video](https://www.youtube.com/watch?v=kRoGYgAuZQE&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q)
## Setup
```sh
npm install
```
## Run
```sh
# terminal 1 (UI localhost for hot-reload)
npm run ui-dev
# 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)
```
|