Part of vmc.contrib.axiom.store View In Hierarchy
Implements interfaces: vmc.contrib.axiom.iaxiom.IBeneficiary
I am a database that Axiom Items can be stored in. Store an item in me by setting its 'store' attribute to be me. I can be created one of two ways: Store() # Create an in-memory database Store("/path/to/file.axiom") # create an on-disk database in the # directory /path/to/file.axiom @ivar typeToTableNameCache: a dictionary mapping Item subclass type objects to the fully-qualified sqlite table name where items of that type are stored. This cache is generated from the saved schema metadata when this store is opened and updated when schema changes from other store objects (such as in other processes) are detected.
Method | __init__ | Create a store. |
Method | attachToParent | Undocumented |
Method | __repr__ | Undocumented |
Method | findOrCreate | Usage: |
Method | newFilePath | Undocumented |
Method | newTemporaryFilePath | Undocumented |
Method | newFile | Open a new file somewhere in this Store's file area. |
Method | newDirectory | Undocumented |
Method | checkTypeSchemaConsistency | Called for all known types at database startup: make sure that what we know |
Method | whenFullyUpgraded | Return a Deferred which fires when this Store has been fully upgraded. |
Method | getOldVersionOf | Undocumented |
Method | findUnique | Find an Item in the database which should be unique. If it is found, |
Method | findFirst | Usage: |
Method | query | Return a generator of instances of tableClass ,
|
Method | sum | Undocumented |
Method | count | Undocumented |
Method | batchInsert | Create multiple items in the store without loading |
Method | changed | Undocumented |
Method | checkpoint | Undocumented |
Method | transact | Undocumented |
Method | revert | Undocumented |
Method | close | Undocumented |
Method | avgms | Undocumented |
Method | getTableName | Retrieve the fully qualified name of the table holding items |
Method | getShortColumnName | Retreive the column name for a particular attribute in this |
Method | getColumnName | Retreive the fully qualified column name for a particular |
Method | getTypeID | Retrieve the typeID associated with a particular table in the |
Method | getTableQuery | Undocumented |
Method | getItemByID | Retrieve an item by its storeID, and return it. |
Method | querySchemaSQL | Undocumented |
Method | querySQL | For use with SELECT (or SELECT-like PRAGMA) statements. |
Method | createSQL | For use with auto-committing statements such as CREATE TABLE or CREATE |
Method | executeSchemaSQL | Undocumented |
Method | executeSQL | For use with UPDATE or INSERT statements. |
Inherited from Empowered:
Method | powerUp | Installs a powerup (e.g. plugin) on an item or store. |
Method | powerDown | Remove a powerup. |
Method | __conform__ | For 'normal' interfaces, returns the first powerup found when doing |
Method | powerupsFor | Returns powerups installed using powerUp , in order of
descending
|
Method | interfacesFor | Undocumented |
Parameters | dbdir | A name of an existing Axiom directory, or the name of a directory that does not exist yet which will be created as this Store is instantiated. If unspecified, this database will be kept in memory. |
filesdir | A name of a directory to keep files in for in-memory stores. An
exception will be raised if both this attribute and dbdir are
specified.
| |
debug | set to True if this Store should print out every SQL statement it sends to SQLite. | |
parent | (internal) If this is opened using an
axiom.substore.Substore , a reference to its parent.
| |
idInParent | (internal) If this is opened using an
axiom.substore.Substore , the storeID of the item within its
parent which opened it.
| |
Raises | ValueError if both dbdir and
filesdir are specified
|
Usage: s.findOrCreate(userItemClass [, function] [, x=1, y=2, ...]) Example: class YourItemType(Item): a = integer() b = text() c = integer() def f(x): print x, "-- it's new!" s.findOrCreate(YourItemType, f, a=1, b=u'2') Search for an item with columns in the database that match the passed set of keyword arguments, returning the first match if one is found, creating one with the given attributes if not. Takes an optional positional argument function to call on the new item if it is new.
Parameters | path | a sequence of path segments. |
Returns | an AtomicFile .
|
errors.ItemNotFound
.
If more than one item is found, raise errors.DuplicateUniqueItem
.
Parameters | comparison | implementor of iaxiom.IComparison .
|
default | value to use if the item is not found. |
Usage: s.findFirst(tableClass [, query arguments except 'limit']) Example: class YourItemType(Item): a = integer() b = text() c = integer() ... it = s.findFirst(YourItemType, AND(YourItemType.a == 1, YourItemType.b == u'2'), sort=YourItemType.c.descending) Search for an item with columns in the database that match the passed comparison, offset and sort, returning the first match if one is found, or the passed default (None if none is passed) if one is not found.
Return a generator of instances of tableClass
, or tuples of
instances if tableClass
is a tuple of classes.
fastCars = s.query(Vehicle, axiom.attributes.AND( Vehicle.wheels == 4, Vehicle.maxKPH > 200), limit=100, sort=Vehicle.maxKPH.descending) quotesByClient = s.query( (Client, Quote), axiom.attributes.AND( Client.active == True, Quote.client == Client.storeID, Quote.created >= someDate), limit=10, sort=(Client.name.ascending, Quote.created.descending))
Parameters | tableClass | a subclass of Item to look for instances of, or a tuple of subclasses. |
comparison | a provider of IComparison ,
or None, to match all items available in the store. If tableClass is a
tuple, then the comparison must refer to all Item subclasses in that tuple,
and specify the relationships between them.
| |
limit | an int to limit the total length of the results, or None for all available results. | |
offset | an int to specify a starting point within the available results, or None to start at 0. | |
sort | an ISort , something that comes from an SQLAttribute's
'ascending' or 'descending' attribute.
| |
Returns | an ItemQuery
object, which is an iterable of Items or tuples of Items, according to
tableClass.
|
Create multiple items in the store without loading corresponding Python objects into memory.
the items' stored
callback will not be called.
myData = [(37, u"Fred", u"Wichita"), (28, u"Jim", u"Fresno"), (43, u"Betty", u"Dubuque")] myStore.batchInsert(FooItem, [FooItem.age, FooItem.name, FooItem.city], myData)
Parameters | itemType | an Item subclass to create instances of. |
itemAttributes | an iterable of attributes on the Item subclass. | |
dataRows | an iterable of iterables, each the same length as
itemAttributes and containing data corresponding to each
attribute in it.
| |
Returns | None. |
Retrieve the fully qualified name of the table holding items of a particular class in this store. If the table does not exist in the database, it will be created as a side-effect. @param tableClass: an Item subclass @raises L{axiom.errors.ItemClassesOnly}: if an object other than a subclass of Item is passed. @return: a string
Parameters | tableClass | an Item subclass |
Returns | a string XXX: The current implementation does not really match the description, which is actually more restrictive. But it will be true soon, so I guess it is ok for now. The reason is that this method is used during table creation. |
Parameters | tableClass | an Item subclass |
Returns | a string |
Parameters | tableClass | a subclass of Item |
Returns | an integer |
A type ID has been requested for an Item subclass whose table was not present when this Store was opened. Attempt to create the table, and if that fails because another Store object (perhaps in another process) has created the table, re-read the schema. When that's done, return the typeID.
This method is internal to the implementation of getTypeID. It must be run in a transaction.Parameters | tableClass | an Item subclass |
key | a 2-tuple of the tableClass's typeName and schemaVersion | |
Returns | a typeID for the table; a new one if no table exists, or the existing one if the table was created by another Store object referencing this database. |
Retrieve an item by its storeID, and return it.
Note: most of the failure modes of this method are catastrophic and should not be handled by application code. The only one that application programmers should be concerned with is KeyError. They are listed for educational purposes.Parameters | storeID | an int which refers to the store.
|
default | if passed, return this value rather than raising in the case where no Item is found. | |
Returns | an Item, or the given default, if it was passed and no row corresponding to the given storeID can be located in the database. | |
Raises | TypeError | if storeID is not an integer. |
UnknownItemType | if the storeID refers to an item row in the database, but the corresponding type information is not available to Python. | |
RuntimeError | if the found item's class version is higher than the current application is aware of. (In other words, if you have upgraded a database to a new schema and then attempt to open it with a previous version of the code.) | |
KeyError | if no item corresponded to the given storeID. |