Storq logoStorq
example_2.py
example/example_2.pyPython41 lines

example_2.py

Storq format creation/inspection and record CRUD

example/example_2.py
Python
from pathlib import Path
from tempfile import TemporaryDirectory

import storq
from storq import format as storq_format


def main() -> None:
    print("Supported page sizes:", storq_format.supported_page_sizes())

    with TemporaryDirectory() as directory:
        database = Path(directory) / "demo.storq"
        storq_format.create(database, page_size=4096)

        metadata = storq.inspect_storq_database(database)
        print(
            "Storq file:",
            metadata.database_uuid_string,
            metadata.version,
            metadata.page_size,
        )

        records = storq.RecordManager(str(database))
        records.open()
        try:
            record_id = records.insert({"name": "sample", "active": True})
            print("Inserted:", record_id, records.read(record_id))
            print("Exists:", records.exists(record_id))

            records.update(record_id, {"name": "updated"})
            print("Updated:", records.read(record_id))

            records.delete(record_id)
            print("Exists after delete:", records.exists(record_id))
        finally:
            records.close()


if __name__ == "__main__":
    main()