API¶
DiskStore (MutableMapping) API.
Examples:
>>> from diskstore import DiskStore
>>> ds = DiskStore("/tmp/data.db")
>>> ds["one"] = 1
>>> ds["one"]
1
DiskStore
¶
Bases: DiskRead, MutableMapping
filename
property
¶
DiskStore filename for DB.
tablename
property
¶
Tablename used to get data from.
timeout
property
¶
SQLite connection timeout value in seconds.
__contains__(key)
¶
Check if key exists in the store.
__getitem__(key)
¶
Get value for key, raises KeyError if not found.
__init__(filename, config=None)
¶
SQLite based MutableMapping disk storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
PathLike | str
|
DiskStore DB filename. |
required |
config
|
ConfigProtocol | None
|
Configuration as specified in ConfigProtocol |
None
|
__iter__()
¶
Iterate over keys in insertion order.
__len__()
¶
Return the number of items in the store.
To do this count is used which is not a performant implementation.
__reversed__()
¶
Iterate over keys in reverse insertion order.
close()
¶
Close the database connection if open.
items()
¶
Return a set-like view of (key, value) pairs in the mapping.
keys()
¶
Return a set-like view of keys in the mapping.
open()
¶
Open (or re-open) the database connection and return self.
query(where=None, parameters=None, order=None, limit=None, offset=None)
¶
Query rows with optional filtering, ordering, limit and offset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
where
|
Optional[str]
|
SQL WHERE clause (without the WHERE keyword). |
None
|
parameters
|
Optional[Sequence | dict]
|
Parameters for the WHERE clause. |
None
|
order
|
Optional[str]
|
ORDER BY clause (without the ORDER BY keyword). |
None
|
limit
|
int | None
|
Maximum number of rows to return. |
None
|
offset
|
int | None
|
Number of rows to skip. |
None
|
Yields:
| Type | Description |
|---|---|
tuple
|
(key, value) tuples. |
Examples:
values()
¶
Return a set-like view of values in the mapping.
DiskRead (Mapping) API.
Examples:
>>> from diskstore import DiskRead
# DB must exist!
>>> ds = DiskRead("/tmp/data.db")
>>> ds["one"]
1
DiskRead
¶
Bases: Mapping
filename
property
¶
DiskStore filename for DB.
tablename
property
¶
Tablename used to get data from.
timeout
property
¶
SQLite connection timeout value in seconds.
__contains__(key)
¶
Check if key exists in the store.
__getitem__(key)
¶
Get value for key, raises KeyError if not found.
__init__(filename, config=None)
¶
SQLite read only disk storage.
Database is opened read only on demand.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
PathLike | str
|
filename for DB to use. |
required |
config
|
ConfigProtocol | None
|
Configuration |
None
|
__iter__()
¶
Iterate over keys in insertion order.
__len__()
¶
Return the number of items in the store.
To do this count is used which is not a performant implementation.
__reversed__()
¶
Iterate over keys in reverse insertion order.
close()
¶
Close the database connection if open.
items()
¶
Return a set-like view of (key, value) pairs in the mapping.
keys()
¶
Return a set-like view of keys in the mapping.
open()
¶
Open (or re-open) the database connection and return self.
query(where=None, parameters=None, order=None, limit=None, offset=None)
¶
Query rows with optional filtering, ordering, limit and offset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
where
|
Optional[str]
|
SQL WHERE clause (without the WHERE keyword). |
None
|
parameters
|
Optional[Sequence | dict]
|
Parameters for the WHERE clause. |
None
|
order
|
Optional[str]
|
ORDER BY clause (without the ORDER BY keyword). |
None
|
limit
|
int | None
|
Maximum number of rows to return. |
None
|
offset
|
int | None
|
Number of rows to skip. |
None
|
Yields:
| Type | Description |
|---|---|
tuple
|
(key, value) tuples. |
Examples:
values()
¶
Return a set-like view of values in the mapping.
DiskStore configuration classes and helpers for config.
BaseConfig
¶
ConfigProtocol
¶
Bases: Protocol
Configuration Protocol
Attributes:
| Name | Type | Description |
|---|---|---|
tablename |
str
|
Table name as string |
key_type |
str
|
key type as string or basic Python type like str, int, float |
timeout |
float
|
Timeout used to wait if someone blocks connections or with writes |
pragmas |
dict
|
Dictionary with PRAGMAs to set when connections is initialized |
fields |
Iterable
|
Iterable used for select, update and create statement with
field name, type and default. |