Skip to main content

A fast and lightweight relational db

Project description

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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

RelaDB-2.0.1.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

RelaDB-2.0.1-py3-none-any.whl (2.3 kB view details)

Uploaded Python 3

File details

Details for the file RelaDB-2.0.1.tar.gz.

File metadata

  • Download URL: RelaDB-2.0.1.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for RelaDB-2.0.1.tar.gz
Algorithm Hash digest
SHA256 e117903a90b62abc4dabbd18b41b604f5fa553f3f718117af939e952e86ba7bb
MD5 5c37ae9f08b5674dd61c19830dace593
BLAKE2b-256 b35a7ca2b08e60e80cff0c4c8b19fe39b29137ab01e6b88fb3e59f72d0b02e06

See more details on using hashes here.

File details

Details for the file RelaDB-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: RelaDB-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 2.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for RelaDB-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 00307b35d3ff3417c656d8b9e4ff68fc8ea63d2d01e3830943001b1764c420f4
MD5 8ed2f133e4db5bcc3534330641e59716
BLAKE2b-256 662278f1f105907e906690f09c3238a001c717f7c750e736e1035455fbd1fb89

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page