@@ -4,66 +4,31 @@ Use SQLite with Diesel ORM in your web apps!
4
4
5
5
## Quickstart
6
6
7
- Add ` diesel-wasm- sqlite` to your project. SQLite is automatically bundled with
8
- the library.
7
+ Add ` sqlite-web ` to your project. SQLite is automatically bundled with the
8
+ library.
9
9
10
10
``` toml
11
11
[dependencies ]
12
12
diesel = { version = " 2.2" }
13
- diesel-wasm- sqlite = { git = " https://github.com/xmtp/libxmtp " , branch = " wasm-backend " }
13
+ sqlite-web = { git = " https://github.com/xmtp/sqlite-web-rs " , branch = " main " }
14
14
wasm-bindgen = " 0.2"
15
15
```
16
16
17
- ``` rust
18
- use diesel_wasm_sqlite :: {connection :: WasmSqliteConnection , WasmSqlite };
19
- use wasm_bindgen :: prelude :: * ;
20
-
21
- pub const MIGRATIONS : EmbeddedMigrations = embed_migrations! (" ./tests/web/migrations/" );
22
-
23
- mod schema {
24
- diesel :: table! {
25
- books {
26
- id -> Integer ,
27
- title -> Text ,
28
- author -> Nullable <Text >,
29
- }
30
- }
31
- }
32
-
33
-
34
- #[derive(Deserialize , Insertable , Debug , PartialEq , Clone )]
35
- #[diesel(table_name = books)]
36
- pub struct BookForm {
37
- title : String ,
38
- author : Option <String >,
39
- }
40
-
41
- // SQLite must be instantiated in a web-worker
42
- // to take advantage of OPFS
43
- #[wasm_bindgen]
44
- async fn code_in_web_worker () -> Result <i32 , diesel :: QueryResult <usize >> {
45
- use schema :: books :: dsl :: * ;
46
- // `init_sqlite` sets up OPFS and SQLite. It must be ran before anything else,
47
- // or we crash once we start trying to do queries.
48
- diesel_wasm_sqlite :: init_sqlite (). await ;
49
-
50
- // create a new persistent SQLite database with OPFS
51
- let result = WasmSqliteConnection :: establish (& format! (" test-{}" , rng ));
52
- let query = insert_into (books ). values (vec! [
53
- BookForm {
54
- title : " Game of Thrones" . into (),
55
- author : Some (" George R.R" . into ()),
56
- },
57
- BookForm {
58
- title : " The Hobbit" . into (),
59
- author : Some (" J.R.R. Tolkien" . into ()),
60
- },
61
- ]);
62
- Ok (query . execute (conn )? )
63
- }
64
- ```
17
+ ## Try It Out!
18
+
19
+ Try out SQLite on the web with rust at this
20
+ [ example app] ( https://sqlite-web-example.netlify.app/ )
21
+
22
+ ## Running the Example
23
+
24
+ Look in ` examples/web-sqlite ` for a working example!
65
25
66
- Look in ` tests/test/web.rs ` for a working example!
26
+ - run ` yarn ` in the root of the repo
27
+ - navigate to ` examples/web-sqlite `
28
+ - make sure the [ ` miniserve ` ] ( https://github.com/svenstaro/miniserve ) crate is
29
+ installed locally
30
+ - run ` ./build.sh && ./run.sh `
31
+ - navigate to ` localhost:8080 `
67
32
68
33
## Contributing
69
34
0 commit comments