API

source: bluebase/api.py

The main API for creating, opening, and interacting with a database.

Example:

from pathlib import Path
from bluebase import BlueBase

bb = BlueBase(Path("test.db"))

bb.execute("CREATE TABLE student(id INT, name STRING(12));")
bb.execute("INSERT INTO student VALUES (1, 'Alice');")

result = bb.execute("SELECT name FROM student;")
for row in result:
    print(row)

bb.close()

dataclassclass Result(query: str, op: QlOp)[source]

Bases: object

An execution result.

Variables:
  • query (str) – the input query

  • op (QlOp) – the operation for the query

__iter__() → Iterator[tuple[bool | int | float | str, ...]][source]

Yield flattened rows from the operation.

class BlueBase(path: Path)[source]

Bases: object

The main API.

Open an existing database at the given path, or create a new one if it does not exist.

Variables:
close() → None[source]

Close the database.

execute(query: str) → Result | None[source]

Execute a query and return its result.

Raises:
  • ValueError – if a CLI-only feature is executed

  • NotImplementedError – if an unsupported feature is executed