Friday, 16 February 2024

pdict: Persistent dict (python)

from sqlitedict import SqliteDict
import sqlite3

def pdict(db_path:str|Path):
    if not isinstance(db_path, Path):
        db_path = Path(db_path)
    if not db_path.exists():
        db_path.parent.mkdir(exist_ok=True, parents=True)
        conn = sqlite3.connect(db_path)
        conn.execute('PRAGMA journal_mode=WAL;')
        conn.commit()
        conn.close()
    return SqliteDict(db_path, autocommit=True)

No comments:

Post a Comment

How whey is made

Source: https://www.youtube.com/watch?v=LeUZmojH7p8 Start with Milk, homogenize, pasteurize. It is 87% water, 5% lactose, 3.5% fat, 3.5...