Skip to content

gufo.blob.sync.sqlite

SQLiteBlob implementation.

SQLiteBlob

Bases: BlobBase

Sync SQLite backend for Gufo Blob.

URL format

sqlite:///path/to/db.sqlite

Options

table: table name (default: blobs) key: key column name (default: k) value: value column name (default: v) busy_timeout: Busy timeout (ms)

connection property

Get SQLite connection.

Connect and initialize database schema when necessary.

key_col property

Get key column name.

path property

Get database path.

table property

Get table name.

value_col property

Get value column name.

clean_db_item(name) staticmethod

Check database field or table name.

Parameters:

Name Type Description Default
name str

database object name.

required

Returns:

Type Description
str

database object name if valid.

Raises:

Type Description
BlobError

on invalid name

close()

Close connection.

delete(key)

Delete key.

Parameters:

Name Type Description Default
key str

Object key.

required

Raises:

Type Description
KeyError

If the key does not exist.

BlobError

On backend or I/O failure.

exists(key)

Check whether a key exists in the blob store.

Parameters:

Name Type Description Default
key str

Object key.

required

Returns:

Type Description
bool

True if the key exists, False otherwise.

Raises:

Type Description
BlobError

On backend or I/O failure.

get(key)

Retrieve data by key.

Parameters:

Name Type Description Default
key str

Object key.

required

Raises:

Type Description
BlobError

On backend or I/O failure.

iter_init_sql()

Iterate database initialization queries.

open()

Explicitly open connection.

parse_url(url) classmethod

Parse URL and extract parameters for constructor.

Parameters:

Name Type Description Default
url str

URL to parse.

required

Returns:

Type Description
dict[str, Any]

**kwargs for constructor.

put(key, data)

Store binary data under the given key.

If the key already exists, its value is overwritten.

Parameters:

Name Type Description Default
key str

Object key.

required
data bytes

Binary payload.

required

Raises:

Type Description
BlobError

On backend or I/O failure.

scan(prefix)

Iterate all keys within prefix.

Parameters:

Name Type Description Default
prefix str

Prefix to scan.

required

Returns:

Type Description
Iterator[str]

Yields matched keys.

Raises:

Type Description
BlobError

On backend or I/O failure.