How to use the tinydb.operations function in tinydb

To help you get started, we’ve selected a few tinydb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ParaToolsInc / taucmdr / packages / tau / storage / local_file.py View on Github external
table_name (str): Name of the table to operate on.  See :any:`AbstractDatabase.table`.
            match_any (bool): Only applies if `keys` is a dictionary.  If True then any key 
                              in `keys` may match or if False then all keys in `keys` must match.
            
        Raises:
            ValueError: ``bool(keys) == False`` or invaild value for `keys`.
        """
        table = self.table(table_name)
        if isinstance(keys, self.Record.eid_type):
            for field in fields:
                LOGGER.debug("%s: unset(%s, eid=%r)", table_name, field, keys)
                table.update(operations.delete(field), eids=[keys])
        elif isinstance(keys, dict):
            for field in fields:
                LOGGER.debug("%s: unset(%s, keys=%r)", table_name, field, keys)
                table.update(operations.delete(field), self._query(keys, match_any))
        elif isinstance(keys, (list, tuple)):
            for field in fields:
                LOGGER.debug("%s: unset(%s, eids=%r)", table_name, field, keys)
                table.update(operations.delete(field), eids=keys)
        else:
            raise ValueError(keys)
github ParaToolsInc / taucmdr / packages / tau / core / database.py View on Github external
table = self.database.table(table_name)
        try:
            eid = int(keys)
        except TypeError:
            if isinstance(keys, list):
                LOGGER.debug("%s: unset(%r, eids=%r)", table_name, fields, keys)
                for field in fields:
                    table.update(tinydb.operations.delete(field), eids=keys)
            elif isinstance(keys, dict):
                LOGGER.debug("%s: unset(%r, keys=%r)", table_name, fields, keys)
                for field in fields:
                    table.update(tinydb.operations.delete(field), self._query(keys, match_any))
        else:
            LOGGER.debug("%s: unset(%r, eid=%r)", table_name, fields, eid)
            for field in fields:
                table.update(tinydb.operations.delete(field), eids=[eid])
github leon-ai / leon / bridges / python / utils.py View on Github external
def db(dbtype = 'tinydb'):
	"""Create a new dedicated database
	for a specific package"""

	if dbtype == 'tinydb':
		ext = '.json' if environ.get('LEON_NODE_ENV') != 'testing' else '.spec.json'
		db = TinyDB(dirname + '/../../packages/' + queryobj['package'] + '/data/db/' + queryobj['package'] + ext)
		return { 'db': db, 'query': Query, 'operations': operations }