You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/index.md
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ Add `include-sqlite-sql` as a dependency:
6
6
7
7
```toml
8
8
[dependencies]
9
-
include-sqlite-sql = "0.1"
9
+
include-sqlite-sql = "0.2"
10
10
```
11
11
12
12
Write your SQL and save it in a file. For example, let's say the following is the content of the `library.sql` file that is saved in the project's `src` folder:
@@ -19,17 +19,18 @@ Write your SQL and save it in a file. For example, let's say the following is th
19
19
SELECT book_title
20
20
FROM library
21
21
WHERE loaned_to = :user_id
22
-
ORDER BY1;
23
-
22
+
ORDER BY1
23
+
/
24
24
-- name: loan_books!
25
25
-- Updates the book records to reflect loan to a patron
26
26
-- # Parameters
27
+
-- param: book_titles: &str - book titles
27
28
-- param: user_id: &str - user ID
28
-
-- param: book_ids: u32 - book IDs
29
29
UPDATE library
30
30
SET loaned_to = :user_id
31
31
, loaned_on =current_timestamp
32
-
WHERE book_id IN (:book_ids);
32
+
WHERE book_title IN (:book_titles)
33
+
/
33
34
```
34
35
35
36
And then use it in Rust as:
@@ -41,15 +42,13 @@ use rusqlite::{Result, Connection};
41
42
include_sql!("src/library.sql");
42
43
43
44
fnmain() ->Result<()> {
44
-
letargs:Vec<String> =std::env::args().collect();
45
-
letdbpath=&args[1];
46
-
letuser_id=&args[2];
45
+
letdb=Connection::open("library.db")?;
47
46
48
-
letdb=Connection::open(dbpath)?;
47
+
db.loan_books(&["War and Peace", "Gone With the Wind"], "Sheldon Cooper")?;
For the "IN list" type of parameters **include-sqlite-sql** will generate a method parameter as a slice where each element is the same generic type supplied by **include-sql**:
0 commit comments