summaryrefslogtreecommitdiff
path: root/sqlite.zig
diff options
context:
space:
mode:
Diffstat (limited to 'sqlite.zig')
-rw-r--r--sqlite.zig45
1 files changed, 26 insertions, 19 deletions
diff --git a/sqlite.zig b/sqlite.zig
index 4060ddb..b5f7b72 100644
--- a/sqlite.zig
+++ b/sqlite.zig
@@ -150,24 +150,6 @@ pub const Blob = struct {
150 } 150 }
151 151
152 /// open opens a blob for incremental i/o. 152 /// open opens a blob for incremental i/o.
153 ///
154 /// You can get a std.io.Writer to write data to the blob:
155 ///
156 /// var blob = try db.openBlob(.main, "mytable", "mycolumn", 1, .{ .write = true });
157 /// var blob_writer = blob.writer();
158 ///
159 /// try blob_writer.writeAll(my_data);
160 ///
161 /// Note that a blob is not extensible, if you want to change the blob size you must use an UPDATE statement.
162 ///
163 /// You can get a std.io.Reader to read the blob data:
164 ///
165 /// var blob = try db.openBlob(.main, "mytable", "mycolumn", 1, .{});
166 /// var blob_reader = blob.reader();
167 ///
168 /// const data = try blob_reader.readAlloc(allocator);
169 ///
170 /// See https://sqlite.org/c3ref/blob_open.html for more details.
171 fn open(db: *c.sqlite3, db_name: DatabaseName, table: [:0]const u8, column: [:0]const u8, row: i64, comptime flags: OpenFlags) !Blob { 153 fn open(db: *c.sqlite3, db_name: DatabaseName, table: [:0]const u8, column: [:0]const u8, row: i64, comptime flags: OpenFlags) !Blob {
172 comptime if (!flags.read and !flags.write) { 154 comptime if (!flags.read and !flags.write) {
173 @compileError("must open a blob for either read, write or both"); 155 @compileError("must open a blob for either read, write or both");
@@ -510,7 +492,32 @@ pub const Db = struct {
510 return @intCast(usize, c.sqlite3_changes(self.db)); 492 return @intCast(usize, c.sqlite3_changes(self.db));
511 } 493 }
512 494
513 /// openBlob opens a blob. 495 /// openBlob opens a blob for incremental i/o.
496 ///
497 /// Incremental i/o enables writing and reading data using a std.io.Writer and std.io.Reader:
498 /// * the writer type wraps sqlite3_blob_write, see https://sqlite.org/c3ref/blob_write.html
499 /// * the reader type wraps sqlite3_blob_read, see https://sqlite.org/c3ref/blob_read.html
500 ///
501 /// Note that:
502 /// * the blob must exist before writing; you must use INSERT to create one first (either with data or using a placeholder with ZeroBlob).
503 /// * the blob is not extensible, if you want to change the blob size you must use an UPDATE statement.
504 ///
505 /// You can get a std.io.Writer to write data to the blob:
506 ///
507 /// var blob = try db.openBlob(.main, "mytable", "mycolumn", 1, .{ .write = true });
508 /// var blob_writer = blob.writer();
509 ///
510 /// try blob_writer.writeAll(my_data);
511 ///
512 /// You can get a std.io.Reader to read the blob data:
513 ///
514 /// var blob = try db.openBlob(.main, "mytable", "mycolumn", 1, .{});
515 /// var blob_reader = blob.reader();
516 ///
517 /// const data = try blob_reader.readAlloc(allocator);
518 ///
519 /// See https://sqlite.org/c3ref/blob_open.html for more details on incremental i/o.
520 ///
514 pub fn openBlob(self: *Self, db_name: Blob.DatabaseName, table: [:0]const u8, column: [:0]const u8, row: i64, comptime flags: Blob.OpenFlags) !Blob { 521 pub fn openBlob(self: *Self, db_name: Blob.DatabaseName, table: [:0]const u8, column: [:0]const u8, row: i64, comptime flags: Blob.OpenFlags) !Blob {
515 return Blob.open(self.db, db_name, table, column, row, flags); 522 return Blob.open(self.db, db_name, table, column, row, flags);
516 } 523 }