How to use the tinydb.where 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 msiemens / tinydb / tests / test_storages.py View on Github external
def get(s):
        return db.get(where('name') == s)
github oz123 / blogit / tests / test_all.py View on Github external
def test_find_new_posts_and_pages():
    entries = [e for e in find_new_posts_and_pages(DB)]
    assert len(entries)
    pages = [e[1] for e in entries if str(e[0]).endswith('page.md')]
    assert len(pages)

    assert len(DB.posts.all()) == 20

    new_entries = [e for e in find_new_posts_and_pages(DB)]

    # no new posts sould be found
    assert len(DB.posts.all()) == 20
    assert len(new_entries) == 0

    [e[0].tags for e in entries]
    foo = DB.tags.search(where('name') == 'foo')
    assert foo[0]['post_ids'] == list(range(1, 16))
github msiemens / tinydb / tests / test_tinydb.py View on Github external
def test_update(db: TinyDB):
    assert len(db) == 3

    db.update({'int': 2}, where('char') == 'a')

    assert db.count(where('int') == 2) == 1
    assert db.count(where('int') == 1) == 2
github msiemens / tinydb / tests / test_tinydb.py View on Github external
def test_update_all(db: TinyDB):
    assert db.count(where('int') == 1) == 3

    db.update({'newField': True})

    assert db.count(where('newField') == True) == 3  # noqa
github pycalphad / pycalphad / research / sedimodel.py View on Github external
def einstein_energy(self, phase, param_search):
        einstein_param_query = (
            (where('phase_name') == phase.name) & \
            (where('parameter_type') == 'THETA') & \
            (where('constituent_array').test(self._array_validity))
        )
        theta = self.redlich_kister_sum(phase, param_search, einstein_param_query)
        self.TE = self.einstein_temperature = theta
        x = theta / v.T
        self.testprop = 3.0 * v.R * ((x**2) * sympy.exp(x) / ((sympy.exp(x) - 1.0) ** 2))
        result = 3 * v.R * theta * (0.5 + 1./(sympy.exp(x) - 1))
        return result
github Tkd-Alex / Telegram-InstaPy-Scheduling / utils.py View on Github external
def delete_job(database, name, owner):
	database.remove((where('entity') == "job") & (where('owner') == owner) & (where('name') == name))
github PhasesResearchLab / ESPEI / espei / paramselect.py View on Github external
def _param_present_in_database(dbf, phase_name, configuration, param_type):
    const_arr = tuple([tuple(map(lambda x: v.Species(x), subl)) for subl in map(tuplify, configuration)])
    # parameter order doesn't matter here, since the generated might not exactly match. Always override.
    query = (where('phase_name') == phase_name) & \
            (where('parameter_type') == param_type) & \
            (where('constituent_array') == const_arr)
    search_result = dbf._parameters.search(query)
    if len(search_result) > 0:
        return True
github ParaToolsInc / taucmdr / packages / tau / core / database.py View on Github external
keys (dict): data keys to query.
            match_any (bool): If True then any key may match or if False then all keys must match.
        
        Returns:
            Query: The query object. 
        """
        def _and(lhs, rhs): 
            return lhs & rhs
        def _or(lhs, rhs): 
            return lhs | rhs
        join = _or if match_any else _and
        itr = keys.iteritems()
        key, val = itr.next()
        query = (tinydb.where(key) == val)
        for key, value in itr:
            query = join(query, (tinydb.where(key) == value))
        return query
github VirgilSecurity / virgil-iotkit / tools / virgil-trust-provisioner / virgil_trust_provisioner / storage / tl_version_tinydb_storage.py View on Github external
def get_release_version(self, suppress_db_warning=False):
        db = self._get_db(suppress_db_warning)
        version = db.table(self.__table_name).get(where("release_version").exists())
        db.close()
        return version["release_version"] if version else "0.0.0.0"