Various useful functions. Some can be imported from doqu.utils, some are available directly at doqu.
These utilities are either stable and well-tested or possible changes in their API are not considered harmful (i.e. they are marginal). Important functions which design is likely to change or which lack proper tests are located in doqu.future.
Returns a multi-line string with document keys and values nicely formatted and aligned.
Parameters: |
|
---|---|
Prarm as_repr: | If True, uses repr() for values; if not, coerces them to Unicode. Default if False. |
Storage adapter factory. Expects path to storage backend module and optional backend-specific settings. Returns storage adapter instance. If required underlying library is not found, exception pkg_resources.DistributionNotFound is raised with package name and version as the message.
Parameters: | backend – string, dotted path to a Doqu storage backend (e.g. doqu.ext.tokyo_tyrant). See Extensions for a list of bundled backends or Backend API for backend API reference. |
---|
Usage:
import doqu
db = doqu.get_db(backend='doqu.ext.shelve', path='test.db')
query = SomeDocument.objects(db)
Settings can be also passed as a dictionary:
SETTINGS = {
'backend': 'doqu.ext.tokyo_cabinet',
'path': 'test.tct',
}
db = doqu.get_db(SETTINGS)
The two methods can be combined to override certain settings:
db = doqu.get_db(SETTINGS, path='another_db.tct')
Returns a pretty readable name based on the class name. For example, “SomeClass” is translated to “some_class”.
Reads given file (assuming it is in a known format), loads it into given storage adapter instance and returns that instance.
Parameters: |
|
---|
Usage:
import doqu
db = doqu.load_fixture('account.csv')
query = SomeDocument.objects(db)