Skip to content

API

log module-attribute

log = get_logger('ogc')

model_as_pickle

model_as_pickle(obj: object) -> bytes

Converts model object to bytes

Source code in ogc/db.py
def model_as_pickle(obj: object) -> bytes:
    """Converts model object to bytes"""
    output: bytes = dill.dumps(obj)
    return output

pickle_to_model

pickle_to_model(obj: bytes) -> t.Any

Converts pickled bytes to object

Source code in ogc/db.py
def pickle_to_model(obj: bytes) -> t.Any:
    """Converts pickled bytes to object"""
    return dill.loads(obj)

connect

connect() -> SqliteExtDatabase

Get the associated database file

Returns:

Type Description
SqliteExtDatabase

Connection to sqlite database

Source code in ogc/db.py
def connect() -> SqliteExtDatabase:
    """Get the associated database file

    Returns:
        Connection to sqlite database
    """
    p = Path(__file__).cwd() / ".ogc-cache"
    p.mkdir(parents=True, exist_ok=True)
    return SqliteExtDatabase(
        str(p / "data.db"), pragmas=(("journal_mode", "wal"), ("foreign_keys", 1))
    )

cache_path

cache_path() -> Path

Returns where to store files

Source code in ogc/db.py
def cache_path() -> Path:
    """Returns where to store files"""
    p = Path(__file__).cwd() / ".ogc-cache/nodes"
    p.mkdir(parents=True, exist_ok=True)
    return p