summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md28
1 files changed, 9 insertions, 19 deletions
diff --git a/README.md b/README.md
index 7937862..2174697 100644
--- a/README.md
+++ b/README.md
@@ -46,20 +46,10 @@ sqlite works exclusively by using prepared statements. The wrapper type is `sqli
46 \\SELECT id, name, age, salary FROM employees WHERE age > ? AND age < ? 46 \\SELECT id, name, age, salary FROM employees WHERE age > ? AND age < ?
47 ; 47 ;
48 48
49 var stmt = try db.prepare(query, .{ 49 var stmt = try db.prepare(query);
50 .age1 = 20,
51 .age2 = 40,
52 });
53 defer stmt.deinit(); 50 defer stmt.deinit();
54 51
55The `Db.prepare` method takes a `comptime` query string and a tuple of bind parameters. 52The `Db.prepare` method takes a `comptime` query string.
56
57The number of bind parameters is comptime checked against the number of bind markers in the query string, so if you have 2 bind markers
58you must provide 2 bind parameters.
59
60Note that the fields name is irrelevant, only their order is relevant.
61
62See the section "Bind parameters and resultset rows" for more information on the types mapping rules.
63 53
64### Executing a statement 54### Executing a statement
65 55
@@ -69,13 +59,15 @@ For queries which do not return data (`INSERT`, `UPDATE`) you can use the `exec`
69 \\UPDATE foo SET salary = ? WHERE id = ? 59 \\UPDATE foo SET salary = ? WHERE id = ?
70 ; 60 ;
71 61
72 var stmt = try db.prepare(query, .{ 62 var stmt = try db.prepare(query);
63 defer stmt.deinit();
64
65 try stmt.exec({
73 .salary = 20000, 66 .salary = 20000,
74 .id = 40, 67 .id = 40,
75 }); 68 });
76 defer stmt.deinit();
77 69
78 try stmt.exec(); 70See the section "Bind parameters and resultset rows" for more information on the types mapping rules.
79 71
80### Reading data 72### Reading data
81 73
@@ -85,10 +77,7 @@ For queries which do return data you can use the `all` method:
85 \\SELECT id, name, age, salary FROM employees WHERE age > ? AND age < ? 77 \\SELECT id, name, age, salary FROM employees WHERE age > ? AND age < ?
86 ; 78 ;
87 79
88 var stmt = try db.prepare(query, .{ 80 var stmt = try db.prepare(query);
89 .age1 = 20,
90 .age2 = 40,
91 });
92 defer stmt.deinit(); 81 defer stmt.deinit();
93 82
94 const rows = try stmt.all( 83 const rows = try stmt.all(
@@ -99,6 +88,7 @@ For queries which do return data you can use the `all` method:
99 salary: u32, 88 salary: u32,
100 }, 89 },
101 .{ .allocator = allocator }, 90 .{ .allocator = allocator },
91 .{ .age1 = 20, .age2 = 40 },
102 ); 92 );
103 for (rows) |row| { 93 for (rows) |row| {
104 std.log.debug("id: {} ; name: {}; age: {}; salary: {}", .{ row.id, row.name, row.age, row.salary }); 94 std.log.debug("id: {} ; name: {}; age: {}; salary: {}", .{ row.id, row.name, row.age, row.salary });