Py_Simple_Select is a lightweight Python library designed to simplify interactions with SQLite databases.
MIT License
Py_Simple_Select is a lightweight Python library designed to simplify interactions with SQLite databases. It provides a minimalistic ORM (Object-Relational Mapping) system that enables advanced querying and flexible data selection. This library is tailored to offer an easy-to-use interface while abstracting away database internals, such as primary keys and foreign keys, when they are not needed by the user.
You can install Py_Simple_Select directly from PyPI using pip
:
pip install Py_Simple_Select
First, let's create a database manager instance and set up our tables, including those with foreign keys:
from py_simple_select import Database_Manager
# Create a database manager instance
db : Database_Manager = Database_Manager("my_database")
# Create a table without foreign keys
db.create_table ("user", name = str, email = str)
# Create a table with a foreign key referencing the "users" table
db.create_table ("order", amount = float, user_id = int)
Next, we can insert data into our tables. The ORM makes it simple to add entries:
# Get the "users" table class
User : type = db.get_table_class ("user")
Order : type = db.get_table_class ("order")
# Insert records into the "users" table and records into the "orders" table with a reference to "users"
db.insert (
User (name = "Alice", email = "[email protected]"),
User (name = "Bob", email = "[email protected]"),
Order (amount = 250.75, user_id = 1),
Order (amount = 125.50, user_id = 2)
)
You can perform advanced queries that group results based on foreign keys:
# Get the "orders" table class
grouped_orders = db.advanced_select ("orders")
for group in grouped_orders:
print (group)
This will return a nested tuple structure where the orders are grouped by the values of their foreign keys (e.g., user_id).
This project is licensed under the MIT License. See the LICENSE file for more details.
For more detailed documentation, including API references and advanced usage, please visit the official documentation.
Thanks you for using Py_Simple_Select! I hope you find it useful.