Skip to content
Snippets Groups Projects
Commit d7e0716d authored by Pascal Jürgens's avatar Pascal Jürgens
Browse files

Allow multiple dbs in same project

parent 5154656c
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,7 @@ from pip._internal.utils.appdirs import user_cache_dir
from peewee import *
from playhouse.sqlite_ext import *
db = None
dbs = {}
def setup_db(db_path=None):
......@@ -21,13 +21,15 @@ def setup_db(db_path=None):
cache_dir.mkdir(exist_ok=True, parents=True)
db_path = db_path or (cache_dir / 'db.sqlite3')
global db
global dbs
if not dbs.get(db_path):
db = SqliteDatabase(db_path,
pragmas={'journal_mode': 'wal',
'cache_size': -1024 * 1000})
with db.bind_ctx([MemoizedCall]):
MemoizedCall.create_table(True)
return db
dbs[db_path] = db
return dbs[db_path]
class MemoizedCall(Model):
......@@ -96,8 +98,7 @@ def memoize(remember="forever",
"""
def decorator(fn):
# Code smell, should get rid of global var
global db
db = db or setup_db(db_path)
db = setup_db(db_path)
@functools.wraps(fn)
def inner(*args, **kwargs):
......
[tool.poetry]
name = "hippocampus"
version = "0.1.2"
version = "0.1.4"
description = "simple memoization with sqlite3 and expiry"
authors = ["Pascal Jürgens <juergens@uni-trier.de>"]
readme = "README.md"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment