SQL-based storage of GC3pie objects.
SqlStore(url, table_name='store', idfactory=None, extra_fields=None, create=True, **extra_args)¶
Save and load objects in a SQL db, using python’s pickle module to serialize objects into a specific field.
Access to the DB is done via SQLAlchemy module, therefore any driver supported by SQLAlchemy will be supported by this class.
The url argument is used to access the store. It is supposed to be a
gc3libs.url.Urlclass, and therefore may contain username, password, host and port if they are needed by the db used.
The table_name argument is the name of the table to create. By default it’s
The constructor will create the table_name table if it does not exist, but if there already is such a table it will assume that its schema is compatible with our needs. A minimal table schema is as follows:
+-----------+--------------+------+-----+---------+ | Field | Type | Null | Key | Default | +-----------+--------------+------+-----+---------+ | id | int(11) | NO | PRI | NULL | | data | blob | YES | | NULL | | state | varchar(128) | YES | | NULL | +-----------+--------------+------+-----+---------+
The meaning of the fields is:
- id: this is the id returned by the save() method and uniquely identifies a stored object.
- data: serialized Python object.
- state: if the object is a
Taskinstance, this will be its current execution state.
The extra_fields constructor argument is used to extend the database. It must contain a mapping *column*: *function* where:
- column is a sqlalchemy.Column object.
- function is a function which takes the object to be saved as
argument and returns the value to be stored into the
database. Any exception raised by this function will be
getprovide convenient helpers to save object attributes into table columns.
For each extra column the save() method will call the corresponding function in order to get the correct value to store into the DB.
Any extra keyword arguments are ignored for compatibility with
Return list of IDs of saved Job objects.
This is an optional method; classes that do not implement it should raise a NotImplementedError exception.
Load a saved object given its ID, and return it.
Delete a given object from persistent storage, given its ID.
Replace the object already saved with the given ID with a copy of obj.
Save an object, and return an ID.
Deprecated compatibility alias for SqlStore._tables
make_sqlstore(url, *args, **extra_args)¶
SqlStoreinstance, given a SQLAlchemy URL and optional initialization arguments.
This function is a bridge between the generic factory functions provided by
gc3libs.persistence.register()and the class constructor SqlStore:class.
| >>> ss1 = make_sqlstore(gc3libs.url.Url('sqlite:////tmp/foo.db')) | >>> ss1.__class__.__name__ | 'SqlStore'
This function will return a function which can be used as next_id_fn argument for the IdFactory class constructor.
db is DB connection class conform to DB API2.0 specs (works also with SQLAlchemy engine types)
The function returned has signature:sql_next_id(n=1)
the id returned is the maximum id field in the store table plus 1.