TikiDB Module

class TikiDB.DB(db_name)
checkConsistency(obj, fix_missing=False, remove_extra=False)

will check all objects in their assigned container for the required fields

Parameters:
  • obj (String) – the object to be checked
  • fix_missing (Boolean) – if set to True correct the objects by adding the value specified in the object definition
  • remove_extra (Boolean) – if set to True the method will remove all fields that are not in the object definition
Returns:

dict of objects that are/were not consistent with the object definition

close()

Close the database connection

create_object(obj_name, data)

Create an object with data from the object_definitions container

Parameters:
  • obj_name (string) – the name of the definition that will create the object
  • data (dict or similar) – key/value pairs of data for the object. all of the keys in the object definition must be satisfied by the keys in the data
Returns:

added for ok otherwise error message

findObjectIdByField(obj, search_criteria)

find objects by looping through all data. obj is the containter, kwargs is the name and value of the field to be searched. returns a list of id numbers for the container. This is for non-indexed searches. may be slow due to looping through data sets but may be used to build ad hoc queries.

Parameters:
  • obj (string) – the data object type to be found
  • search_criteria – a list or tuple of dicts. Key is the field value is the search value. if value is None the key is an object that is to be searched. this allows for searching of sub-objects
  • value (string) – the value to search for can use wildcards. % for all characters before or after it. ? for a single character
Returns:

list of object ids(keys) which can be used to pull data

get_next_id(obj_name)

get the next object ID from a data container

Parameters:obj_name (string) – the name of the container
Returns:the next integer ID for a container
makeIndex(index_name, index_type, index_container, index_field, index_description, reindex=False)

Create an index of object IDs (integers) for objects in a container. if successful it will update the index_listing container and the appropriate object in the object_definitions container

Parameters:
  • index_name (String) – is the name of the index
  • index_type (String) – declares the type of btree to use. If keys are integer use IOBTree, otherwise use OOBTree
  • index_container (String) – the name container to be indexed
  • index_field (String) – The name of field to be indexed. this will be the key of the newly created index
  • reindex (Boolean) – recreate index if set to True
  • index_description – is the narrative of what the index is used for
pack(t=None, days=0)

pack the database using zodb pack

sortData(data, sort_fields, order='asc')

sort a list of data based on the sort fields. uses eval to create the lambda. Not sure if there is a better way....

Parameters:
  • data (dict) – a list of dictionary data
  • sort_fields (list) – a list of field names in the order to be sorted. first is most important
  • order (string) – the order the data should be sorted. asc= ascending otherwise descending

returns a list of dictionaries

Previous topic

Welcome to TikiDB’s documentation!

Next topic

TikiBuilder Module

This Page