Documentation
¶
Overview ¶
Package blobio provides an SQL interface to incremental BLOB I/O.
Example ¶
// Open the database, registering the extension. db, err := driver.Open("file:/test.db?vfs=memdb", func(conn *sqlite3.Conn) error { blobio.Register(conn) return nil }) if err != nil { log.Fatal(err) } defer db.Close() _, err = db.Exec(`CREATE TABLE IF NOT EXISTS test (col)`) if err != nil { log.Fatal(err) } const message = "Hello BLOB!" // Create the BLOB. _, err = db.Exec(`INSERT INTO test VALUES (?)`, sqlite3.ZeroBlob(len(message))) if err != nil { log.Fatal(err) } // Write the BLOB. _, err = db.Exec(`SELECT writeblob('main', 'test', 'col', last_insert_rowid(), 0, ?)`, message) if err != nil { log.Fatal(err) } // Read the BLOB. _, err = db.Exec(`SELECT openblob('main', 'test', 'col', rowid, false, ?) FROM test`, sqlite3.Pointer[blobio.OpenCallback](func(blob *sqlite3.Blob, _ ...sqlite3.Value) error { _, err = io.Copy(os.Stdout, blob) return err })) if err != nil { log.Fatal(err) }
Output: Hello BLOB!
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Register ¶
func Register(db *sqlite3.Conn)
Register registers the SQL functions:
readblob(schema, table, column, rowid, offset, n)
Reads n bytes of a blob, starting at offset.
writeblob(schema, table, column, rowid, offset, data)
Writes data into a blob, at the given offset.
openblob(schema, table, column, rowid, write, callback, args...)
Opens blobs for reading or writing. The callback is invoked for each open blob, and must be bound to an OpenCallback, using sqlite3.BindPointer or sqlite3.Pointer. The optional args will be passed to the callback, along with the sqlite3.Blob handle.
Types ¶
type OpenCallback ¶
type OpenCallback func(*sqlite3.Blob, ...sqlite3.Value) error
OpenCallback is the type for the openblob callback.
Click to show internal directories.
Click to hide internal directories.