Skip to main content

RelaDB

🔥 RelaDB is a lightweight set of classes for a relational database system designed for simplicity and speed. It integrates with SQLite and provides an easy-to-use API for managing database schemas, tables, and records in Python.

Classes and Methods

Field

Represents a field (column) in a database table.

__init__(self, name: str, data_type: Type) -> None
  • name: The name of the field.
  • data_type: The Python type of the field (e.g., int, str, float, dict, list).

Row

Represents a row in a database table, allowing for dynamic field assignment.

__init__(self, **kwargs: Union[Dict[str, Any], Any]) -> None
  • **kwargs: Key-value pairs representing the field names and their values for the row.
get(self, field: str = '') -> Union[Dict[str, Any], Any]
  • field: Optional. The name of a specific field to retrieve. If not specified, returns a dictionary of all fields and values.
add_field(self, field_name: str, field_value: Any) -> None
  • field_name: The name of the field to add or update.
  • field_value: The value of the field.

Table

Represents a table in the database, including its schema (fields) and rows (records).

__init__(self, name: str) -> None
  • name: The name of the table.
add_fields(self, fields_dict: Dict[str, Type]) -> None
  • fields_dict: A dictionary mapping field names to their data types.
add_field(self, field_name: str, data_type: Type) -> None
  • field_name: The name of the field to add.
  • data_type: The data type of the field.
delete_fields(self, *field_names: str) -> None
  • *field_names: One or more field names to delete from the table schema.
add_row(self, **kwargs: Dict[str, Any]) -> None
  • **kwargs: Key-value pairs representing the field names and their values for the new row.
delete_row(self, condition: Callable[[Row], bool]) -> None
  • condition: A function that returns True for rows that should be deleted.
find(self, condition: Callable[[Row], bool] = lambda func: True, amount: int = 0) -> List[Row]
  • condition: A function that returns True for rows to include in the result.
  • amount: Optional. The maximum number of rows to return.

Database

Manages the connection to the SQLite database and provides methods for database operations.

__init__(self, db_file: str = '') -> None
  • db_file: Optional. The file path of the SQLite database. Defaults to in-memory operation if not specified.
create(self, table_name: str, fields: Dict[str, Type]) -> Table
  • table_name: The name of the table to create.
  • fields: A dictionary mapping field names to their data types.
delete(self, table_name: str) -> None
  • table_name: The name of the table to delete.
get(self, table_name: str) -> Table
  • table_name: The name of the table to retrieve.
save(self) -> None

Saves the database schema and data to the SQLite file specified in the db_file attribute.

load(self) -> None

Loads the database schema and data from the SQLite file specified in the db_file attribute.

Usage Example

from relaDB import Database

# Initialize database
db = Database()

# Create a table
users = db.create("users", {"name": str, "age": int})

# Add a row to the table
users.add_row(name="Alice", age=30)

# Find a row in the table
user = users.find(lambda row: row.get("name") == "Alice")[0]
print(user.get())

Happy programming!

Release files for RelaDB 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for RelaDB 2.0.1
File Size Uploaded
RelaDB-2.0.1.tar.gz 2.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for RelaDB 2.0.1
File Interpreter ABI Platform
RelaDB-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 4.8 kB

Release files / RelaDB-2.0.1.tar.gz

Download URL RelaDB-2.0.1.tar.gz
Size 2.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e117903a90b62abc4dabbd18b41b604f5fa553f3f718117af939e952e86ba7bb
BLAKE2b-256 checksum
How to use checksums
b35a7ca2b08e60e80cff0c4c8b19fe39b29137ab01e6b88fb3e59f72d0b02e06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / RelaDB-2.0.1-py3-none-any.whl

Download URL RelaDB-2.0.1-py3-none-any.whl
Size 2.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
00307b35d3ff3417c656d8b9e4ff68fc8ea63d2d01e3830943001b1764c420f4
BLAKE2b-256 checksum
How to use checksums
662278f1f105907e906690f09c3238a001c717f7c750e736e1035455fbd1fb89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

2.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page