diff options
| author | 2020-12-21 21:22:35 +0100 | |
|---|---|---|
| committer | 2020-12-21 21:22:35 +0100 | |
| commit | dd12833e3700a1bff4d6973e267fd822c8f09a55 (patch) | |
| tree | dffad6d197563c8e8b1add19f0436ce48229cce1 /README.md | |
| parent | Merge branch 'db-one' (diff) | |
| download | zig-sqlite-dd12833e3700a1bff4d6973e267fd822c8f09a55.tar.gz zig-sqlite-dd12833e3700a1bff4d6973e267fd822c8f09a55.tar.xz zig-sqlite-dd12833e3700a1bff4d6973e267fd822c8f09a55.zip | |
readme: document the one methods
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 29 |
1 files changed, 29 insertions, 0 deletions
| @@ -122,6 +122,35 @@ The type represents a "row", it can be: | |||
| 122 | 122 | ||
| 123 | Not all types are allowed, see the section "Bind parameters and resultset rows" for more information on the types mapping rules. | 123 | Not all types are allowed, see the section "Bind parameters and resultset rows" for more information on the types mapping rules. |
| 124 | 124 | ||
| 125 | The `one` method on a statement works the same way except it returns the first row of the result set: | ||
| 126 | |||
| 127 | ```zig | ||
| 128 | const query = | ||
| 129 | \\SELECT age FROM employees WHERE id = ? | ||
| 130 | ; | ||
| 131 | |||
| 132 | var stmt = try db.prepare(query); | ||
| 133 | defer stmt.deinit(); | ||
| 134 | |||
| 135 | const row = try stmt.one(usize, .{}, .{ .id = 20 }); | ||
| 136 | if (row) |age| { | ||
| 137 | std.log.debug("age: {}", .{age}); | ||
| 138 | } | ||
| 139 | ``` | ||
| 140 | |||
| 141 | The convienence function `sqlite.Db.one` works exactly the same way: | ||
| 142 | |||
| 143 | ```zig | ||
| 144 | const query = | ||
| 145 | \\SELECT age FROM employees WHERE id = ? | ||
| 146 | ; | ||
| 147 | |||
| 148 | const row = try db.one(usize, query, .{}, .{ .id = 20 }); | ||
| 149 | if (row) |age| { | ||
| 150 | std.log.debug("age: {}", .{age}); | ||
| 151 | } | ||
| 152 | ``` | ||
| 153 | |||
| 125 | ### Bind parameters and resultset rows | 154 | ### Bind parameters and resultset rows |
| 126 | 155 | ||
| 127 | Since sqlite doesn't have many [types](https://www.sqlite.org/datatype3.html) only a small number of Zig types are allowed in binding parameters and in resultset mapping types. | 156 | Since sqlite doesn't have many [types](https://www.sqlite.org/datatype3.html) only a small number of Zig types are allowed in binding parameters and in resultset mapping types. |