Example:
from tokyo.dystopia import *
jdb = JDB()
# if need be, you should call tune/setcache before open,
# ex. with default values:
jdb.tune(0, 0, 0, 0)
jdb.setcache(0, 0)
# open the database
jdb.open("casket.tdj", JDBOWRITER | JDBOCREAT)
# store records
for key, value in [(1, ("hop", "step", "jump")),
(2, ("quick", "brown", "fox")),
(3, ("lazy", "dog"))]:
jdb[key] = value
# retrieve one record
print(jdb[1])
# traverse records
for key in jdb:
print(key, jdb[key])
# close the database
jdb.close()
Note
For all methods taking either a key argument or a pair (key, value):
Values will always be returned as a tuple of UTF-8 encoded unicode objects.
On top of that key must always be > 0.
See also
Tune a database.
| Parameters: |
|
|---|
Note
Tuning an open database is an invalid operation.
Set the cache size.
| Parameters: |
|
|---|
Note
Setting the cache size on an open database is an invalid operation.
Set the maximum number of forward matching expansion(?).
| Parameter: | fwmmax – the maximum number of forward matching expansion. |
|---|
Note
Setting this on an open database is an invalid operation.
Open a database.
| Parameters: |
|
|---|
Close the database.
Note
JDBs are closed when garbage-collected.
Copy the database directory.
| Parameter: | path – path to the destination directory. |
|---|
Search a database, return a frozenset of keys whose value match the expressed condition.
| Parameters: |
|
|---|
Conditions can be expressed in two ways:
See also
‘Compound Expression of Search’ at Tokyo Dystopia documentation.
Optimize a database.
Note
Optimizing a read only database is an invalid operation.
The following constants can only be combined with JDBOWRITER :
Create a new database file if it does not exists.
Create a new database file even if one already exists (truncates existing file).
The following constants can be combined with either JDBOREADER or JDBOWRITER :
expr in v for v in value
v.startswith(expr) for v in value
v.endswith(expr) for v in value
expr in value
| expr | meaning |
|---|---|
| 'expr' | expr in value
|
| 'expr1 expr2' | expr1 in value and expr2 in value
|
| '"expr1 expr2"' | "expr1 expr2" in value
|
| '[[*expr*]]' | expr in v for v in value
|
| '[[expr*]]' | v.startswith(expr) for v in value
|
| '[[*expr]]' | v.endswith(expr) for v in value
|
The expressions above can be combined with || and/or && (|| has a higher order of precedence).