go-sqlite3
go-sqlite3 copied to clipboard
Blob I/O
Would it be possible to implement the blob i/o API just as the backup API ?
mxk/go-sqlite has it but is a little out of date. gwenn/gosqlite has it too.
database/sql doesn't provide Blob APIs. they provide Blob APIs for native driver (not database/sql).
Yes, but we can provide it aside from database/sql, like backup (backup.go) ? I may try to make it work locally, if it works i'll submit the patch - if that's interesting enough.
No way to pass the Blob type into database.sql.
To make it work, you need access from sql.DB to the underlying/wrapped sqlite3.SQLiteConn...
I don't want to access it from sql.DB, rather add an API to the lib in a similar way to sqlite3.SQLiteBackup, such as sqlite3.SQLiteBlob; and corresponding method in sqlite3.SQLiteConn such as Blob(db, table, column, rowid) (similar to SQLiteConn.Backup(...))
You would need to get the rowid from a query first, but it's also intended this way in SQLite C API : int sqlite3_blob_open( sqlite3*, const char *zDb, const char *zTable, const char *zColumn, sqlite3_int64 iRow, int flags, sqlite3_blob **ppBlob );.
I'll give it a try ...
:+1:
Any progress on this @smhmw ?
@smhmw Any update ?
I think I came up with a nice API for this in my SQLite driver, which could be implemented for this driver as well: https://github.com/ncruces/go-sqlite3/blob/main/ext/blobio/blob_test.go
This would require wrapping the pointer passing APIs, on top of blob IO.
PS: the example shows writing/reading a single blob, but it easily supports reading/writing multiple blobs in one go (callback gets called repeatedly for each blob).
Blob API reference in SQLite documentation: https://sqlite.org/c3ref/blob.html