diff options
Diffstat (limited to '')
| -rw-r--r-- | sqlite.zig | 14 |
1 files changed, 12 insertions, 2 deletions
| @@ -103,6 +103,9 @@ pub const Db = struct { | |||
| 103 | /// var stmt = try db.prepare("INSERT INTO foo(id, name) VALUES(?, ?)"); | 103 | /// var stmt = try db.prepare("INSERT INTO foo(id, name) VALUES(?, ?)"); |
| 104 | /// defer stmt.deinit(); | 104 | /// defer stmt.deinit(); |
| 105 | /// | 105 | /// |
| 106 | /// The statement returned is only compatible with the number of bind markers in the input query. | ||
| 107 | /// This is done because we type check the bind parameters when executing the statement later. | ||
| 108 | /// | ||
| 106 | pub fn prepare(self: *Self, comptime query: []const u8) !Statement(StatementOptions.from(query)) { | 109 | pub fn prepare(self: *Self, comptime query: []const u8) !Statement(StatementOptions.from(query)) { |
| 107 | return Statement(comptime StatementOptions.from(query)).prepare(self, 0, query); | 110 | return Statement(comptime StatementOptions.from(query)).prepare(self, 0, query); |
| 108 | } | 111 | } |
| @@ -251,6 +254,11 @@ pub fn Statement(comptime opts: StatementOptions) type { | |||
| 251 | } | 254 | } |
| 252 | } | 255 | } |
| 253 | 256 | ||
| 257 | /// exec executes a statement which does not return data. | ||
| 258 | /// | ||
| 259 | /// The `values` tuple is used for the bind parameters. It must have as many fields as there are bind markers | ||
| 260 | /// in the input query string. | ||
| 261 | /// | ||
| 254 | pub fn exec(self: *Self, values: anytype) !void { | 262 | pub fn exec(self: *Self, values: anytype) !void { |
| 255 | self.bind(values); | 263 | self.bind(values); |
| 256 | 264 | ||
| @@ -284,7 +292,8 @@ pub fn Statement(comptime opts: StatementOptions) type { | |||
| 284 | /// The `options` tuple is used to provide additional state in some cases, for example | 292 | /// The `options` tuple is used to provide additional state in some cases, for example |
| 285 | /// an allocator used to read text and blobs. | 293 | /// an allocator used to read text and blobs. |
| 286 | /// | 294 | /// |
| 287 | /// The `values` tuple is used for the bind parameters. | 295 | /// The `values` tuple is used for the bind parameters. It must have as many fields as there are bind markers |
| 296 | /// in the input query string. | ||
| 288 | /// | 297 | /// |
| 289 | pub fn one(self: *Self, comptime Type: type, options: anytype, values: anytype) !?Type { | 298 | pub fn one(self: *Self, comptime Type: type, options: anytype, values: anytype) !?Type { |
| 290 | if (!comptime std.meta.trait.is(.Struct)(@TypeOf(options))) { | 299 | if (!comptime std.meta.trait.is(.Struct)(@TypeOf(options))) { |
| @@ -333,7 +342,8 @@ pub fn Statement(comptime opts: StatementOptions) type { | |||
| 333 | /// The `options` tuple is used to provide additional state in some cases. | 342 | /// The `options` tuple is used to provide additional state in some cases. |
| 334 | /// Note that for this function the allocator is mandatory. | 343 | /// Note that for this function the allocator is mandatory. |
| 335 | /// | 344 | /// |
| 336 | /// The `values` tuple is used for the bind parameters. | 345 | /// The `values` tuple is used for the bind parameters. It must have as many fields as there are bind markers |
| 346 | /// in the input query string. | ||
| 337 | /// | 347 | /// |
| 338 | /// Note that this allocates all rows into a single slice: if you read a lot of data this can | 348 | /// Note that this allocates all rows into a single slice: if you read a lot of data this can |
| 339 | /// use a lot of memory. | 349 | /// use a lot of memory. |