How to use the tinydb.middlewares.CachingMiddleware 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_middlewares.py View on Github external
path = str(tmpdir.join('test.db'))

    with TinyDB(path, storage=CachingMiddleware(JSONStorage)) as db:
        db.insert({'key': 'value'})

    # Verify database filesize
    statinfo = os.stat(path)
    assert statinfo.st_size != 0

    # Assert JSON file has been closed
    assert db._storage._handle.closed

    del db

    # Repoen database
    with TinyDB(path, storage=CachingMiddleware(JSONStorage)) as db:
        assert db.all() == [{'key': 'value'}]
github msiemens / tinydb / tests / test_middlewares.py View on Github external
def test_caching_read():
    db = TinyDB(storage=CachingMiddleware(MemoryStorage))
    assert db.all() == []
github msiemens / tinydb / tests / test_tinydb.py View on Github external
def test_access_storage():
    assert isinstance(TinyDB(storage=MemoryStorage).storage,
                      MemoryStorage)
    assert isinstance(TinyDB(storage=CachingMiddleware(MemoryStorage)).storage,
                      CachingMiddleware)
github CentOS-PaaS-SIG / linchpin / linchpin / rundb / tinydb.py View on Github external
def _opendb(self):
        self.middleware = CachingMiddleware(JSONStorage)
        self.middleware.WRITE_CACHE_SIZE = 4096
        tinydb_version = tinydb.version.__version__
        if int(tinydb_version.split(".")[0]) == 3:
            self.db = TinyDB(self.conn_str, storage=self.middleware,
                             default_table=self.default_table_name)
        else:
            self.db = TinyDB(self.conn_str, storage=self.middleware)
            self.db.default_table_name = self.default_table_name
github subsyncit / subsyncit / subsyncit.py View on Github external
if not config.args.verify_ssl_cert:
        requests.packages.urllib3.disable_warnings()
        verifySetting = config.args.verify_ssl_cert

    subsyncit_settings_dir = home_dir + os.sep + ".subsyncit"
    if not os.path.exists(subsyncit_settings_dir):
        os.mkdir(subsyncit_settings_dir)
    make_hidden_on_windows_too(subsyncit_settings_dir)

    config.db_dir = subsyncit_settings_dir + os.sep + config.args.absolute_local_root_path.replace("/","%47").replace(":","%58").replace("\\","%92") + "/"

    if not os.path.exists(config.db_dir):
        os.mkdir(config.db_dir)


    db = TinyDB(config.db_dir + os.sep + "subsyncit.db", storage=CachingMiddleware(JSONStorage))
    state = State(config.db_dir, MyTinyDBTrace(db.table('files')))

    with open(config.db_dir + os.sep + "INFO.TXT", "w") as text_file:
        text_file.write(config.args.absolute_local_root_path + "is the Subsyncit path that this pertains to")

    local_adds_chgs_deletes_queue = IndexedSet()

    class NUllObject(object):

        def is_alive(self):
            return True

        def stop(self):
            pass

        def join(self):
github signetlabdei / sem / sem / database.py View on Github external
# Allow hidden files (like .DS_STORE in macos)
                [os.path.basename(os.path.normpath(f)) for f in
                 glob.glob(os.path.join(campaign_dir, ".*"))])

            if(not folder_contents.issubset(allowed_files)):
                raise ValueError("The specified directory cannot be overwritten"
                                 " because it contains user files.")
            # This operation destroys data.
            shutil.rmtree(campaign_dir)

        # Create the directory and database file in it
        # The indent and separators ensure the database is human readable.
        os.makedirs(campaign_dir)
        tinydb = TinyDB(os.path.join(campaign_dir, "%s.json" %
                                     os.path.basename(campaign_dir)),
                        storage=CachingMiddleware(JSONStorage))

        # Save the configuration in the database
        config = {
            'script': script,
            'commit': commit,
            'params': sorted(params)
        }

        tinydb.table('config').insert(config)

        tinydb.storage.flush()

        return cls(tinydb, campaign_dir)
github cogent3 / cogent3 / src / cogent3 / app / data_store.py View on Github external
def db(self):
        if self._db is None:
            storage = CachingMiddleware(JSONStorage)
            storage.WRITE_CACHE_SIZE = 50  # todo support for user specifying
            self._db = TinyDB(self.source, storage=storage)
            name = self.__class__.__name__
            if "readonly" in name.lower():
                # remove interface for inserting records making this a read only db
                self._db.insert = None
            else:
                self.lock()

            self._finish = weakref.finalize(self, self._close, self._db)

        return self._db
github ncrocfer / whatportis / whatportis / db.py View on Github external
def get_database():
    return TinyDB(path, storage=CachingMiddleware(JSONStorage))