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 returnsTruefor rows that should be deleted.
find(self, condition: Callable[[Row], bool] = lambda func: True, amount: int = 0) -> List[Row]
condition: A function that returnsTruefor 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file RelaDB-2.0.0.tar.gz.
File metadata
- Download URL: RelaDB-2.0.0.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e7bc843656738d1a55c45265bb2da7d36f53a57fbf98f32c2003930c57ab00b
|
|
| MD5 |
fc2bcd335e5249266d0143354830082a
|
|
| BLAKE2b-256 |
362837ac10bf09dac4a84ba4fb8efba2b9dd7e53e5f7381c8567407c37d2e67b
|
File details
Details for the file RelaDB-2.0.0-py3-none-any.whl.
File metadata
- Download URL: RelaDB-2.0.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bebd5298cc01c4dd73edcf3314bbf17db209b437cb2fbe14f349900f67744cf
|
|
| MD5 |
307d270dbab3479b3bd5caa4d5445059
|
|
| BLAKE2b-256 |
96816e4eff77cf93523769890b20bc916b45187a234e4a6bfaccce98cb746812
|