blob

package
v0.10.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package blob provides an alternative 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 {
	blob.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 blob_open('main', 'test', 'col', last_insert_rowid(), true, ?)`,
	sqlite3.Pointer[blob.OpenCallback](func(blob *sqlite3.Blob, _ ...sqlite3.Value) error {
		_, err = io.WriteString(blob, message)
		return err
	}))
if err != nil {
	log.Fatal(err)
}

// Read the BLOB.
_, err = db.Exec(`SELECT blob_open('main', 'test', 'col', rowid, false, ?) FROM test`,
	sqlite3.Pointer[blob.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 blob_open SQL function:

blob_open(schema, table, column, rowid, flags, callback, args...)

The callback must be an sqlite3.Pointer to an OpenCallback. Any optional args will be passed to the callback, along with the sqlite3.Blob handle.

https://sqlite.org/c3ref/blob.html

Types

type OpenCallback

type OpenCallback func(*sqlite3.Blob, ...sqlite3.Value) error

OpenCallback is the type for the blob_open callback.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL