pyworkflow.mapper.sqlite module
- class pyworkflow.mapper.sqlite.SqliteFlatDb(dbName, tablePrefix='', timeout=1000, pragmas=None, indexes=None)[source]
Bases:
SqliteDb
Class to handle a Sqlite database. It will create connection, execute queries and commands
- CLASS_MAP = {'Boolean': 'INTEGER', 'Float': 'REAL', 'Integer': 'INTEGER'}
- VERSION = 1
- aggregate(operations, operationLabel, groupByLabels=None)[source]
- Parameters
operations – string or LIST of operations: MIN, MAX, AVG, COUNT, SUM, TOTAL, GROUP_CONCAT. Any single argument function
defined for sqlite at https://www.sqlite.org/lang_aggfunc.html :param operationLabel: string or LIST of attributes to apply the functions on :param groupByLabels: (Optional) attribute or list of attributes to group by the data :return:
- createTables(objDict)[source]
Create the Classes and Object table to store items of a Set. Each object will be stored in a single row. Each nested property of the object will be stored as a column value.
- getProperty(key, defaultValue=None)[source]
Return the value of a given property with this key. If not found, the defaultValue will be returned.
- getSelfClassName()[source]
Return the class name of the attribute named ‘self’. This is the class of the items stored in a Set.
- insertObject(*args)[source]
Insert a new object as a row. *args: id, label, comment, … where … is the values of the objDict from which the tables where created.
- selectObjectsBy(iterate=False, **args)[source]
More flexible select where the constrains can be passed as a dictionary, the concatenation is done by an AND
- class pyworkflow.mapper.sqlite.SqliteFlatMapper(dbName, dictClasses=None, tablePrefix='', indexes=None)[source]
Bases:
Mapper
Specific Flat Mapper implementation using Sqlite database
- enableAppend()[source]
This will allow to append items to existing db. This is by default not allow, since most sets are not modified after creation.
- static fmtDate(date)[source]
Formats a python date into a valid string to be used in a where term Currently creation files is stored in utc time and is has no microseconds.
- Parameters
date – python date un utc. use datetime.datetime.utcnow() instead of now()
- selectAll(iterate=True, objectFilter=None, orderBy='id', direction='ASC', where='1', limit=None)[source]
Return all object from storage
- unique(labels, where=None)[source]
Returns a list (for a single label) or a dictionary with unique values for the passed labels. If more than one label is passed it will be unique rows similar ti SQL unique clause.
:param labels (string or list) item attribute/s to retrieve unique row values :param where (string) condition to filter the results
- class pyworkflow.mapper.sqlite.SqliteMapper(dbName, dictClasses=None)[source]
Bases:
Mapper
Specific Mapper implementation using Sqlite database
- fillObject(obj, objRow, includeChildren=True)[source]
Fills an already instantiated object the data in a row, including children
NOTE: This, incase children are included, makes a query to the db with all its children ‘like 2.*’. At some point it calls selectById triggering the loading of other protocols and ancestors.
- Parameters
obj – Object to fill
objRow – row with the values
includeChildren – (True). If true children are also populated
- getRelationChilds(relName, parentObj)[source]
Return all “child” objects for a given relation. Params:
relName: the name of the relation. parentObj: this is “parent” in the relation
- Returns:
a list of “child” objects.
- getRelationParents(relName, childObj)[source]
Return all “parent” objects for a given relation. Params:
relName: the name of the relation. childObj: this is “child” in the relation
- Returns:
a list of “parent” objects.
- insertChilds(obj, namePrefix=None)[source]
Insert childs of an object, if namePrefix is None, the it will be deduced from obj.
- insertRelation(relName, creatorObj, parentObj, childObj, parentExt=None, childExt=None)[source]
This function will add a new relation between two objects. Params:
relName: the name of the relation to be added. creatorObj: this object will be the one who register the relation. parentObj: this is “parent” in the relation childObj: this is “child” in the relation
- insertRelationData(relName, creatorId, parentId, childId, parentExtended=None, childExtended=None)[source]
- selectAllBatch(objectFilter=None)[source]
Select all the row at once for all the project
- Returns:
all the protocols populated with the data from the DB
- class pyworkflow.mapper.sqlite.SqliteObjectsDb(dbName, timeout=1000, pragmas=None)[source]
Bases:
SqliteDb
Class to handle a Sqlite database. It will create connection, execute queries and commands
- DELETE = 'DELETE FROM Objects WHERE '
- DELETE_SEQUENCE = "DELETE FROM SQLITE_SEQUENCE WHERE name='Objects'"
- EXISTS = 'SELECT EXISTS(SELECT 1 FROM Objects WHERE %s=? LIMIT 1)'
- SELECT = "SELECT id, parent_id, name, classname, value, label, comment, datetime(creation, 'localtime') as creation FROM Objects"
- SELECT_RELATION = 'SELECT object_%s_id AS id FROM Relations WHERE name=? AND object_%s_id=?'
- SELECT_RELATIONS = 'SELECT * FROM Relations WHERE '
- VERSION = 1
- deleteChildObjects(ancestor_namePrefix)[source]
Delete from db all objects that are childs of an ancestor, now them will have the same starting prefix
- deleteMissingObjectsByAncestor(ancestor_namePrefix, idList)[source]
Select all objects in the hierarchy of ancestor_id
- insertObject(name, classname, value, parent_id, label, comment)[source]
Execute command to insert a new object. Return the inserted object id
- insertRelation(relName, parent_id, object_parent_id, object_child_id, object_parent_extended=None, object_child_extended=None, **kwargs)[source]
Execute command to insert a new object. Return the inserted object id
- selectMissingObjectsByAncestor(ancestor_namePrefix, idList)[source]
Select all objects in the hierarchy of ancestor_id
- selectObjectsBy(iterate=False, **args)[source]
More flexible select where the constrains can be passed as a dictionary, the concatenation is done by an AND
- selectObjectsByAncestor(ancestor_namePrefix, iterate=False)[source]
Select all objects in the hierarchy of ancestor_id