A fluent and user-friendly SQLite library
Project description
easyLite
- Version 1.7
easyLite is a Python library designed to simplify interactions with SQLite databases. With its fluent and intuitive interface, easyLite makes it effortless to interacting with SQLite databases.
Features
- Fluent API: Chainable methods for database operations.
- Schema Management: Easily create and modify tables with constraints and foreign keys.
- Data Manipulation: Insert, update, delete, and query records with minimal boilerplate.
- Advanced Querying: Support for joins, sorting, and conditional selections.
- Data Export: Export query results to CSV or JSON.
- Schema Inspection: Retrieve and display the database schema.
Installation
To install easyLite, use:
pip install easyLite
Usage Guide
Below is a step-by-step guide to using easyLite based on the provided test script (which is recommended to try).
1. Initialization
from easyLite import eL
db = eL().connect('test_store.db')
Establish a connection to the SQLite database.
2. Creating a Table
db.newTable("users") \
.PK() \
.textCol("name", "NN") \
.textCol("email", "NN UQ") \
.dateCol("birth") \
.create()
Create a table named users with a primary key, non-nullable text columns, and a date column.
3. Adding Columns
db.addToTable("users") \
.intCol("age") \
.floatCol("height") \
.add()
Add integer and float columns to the users table.
4. Inserting Data
Using the .field Method
db.insertIn("users") \
.field('name', 'Mario') \
.field('email', 'mario@mail.com') \
.field('age', 19) \
.record()
Using the .row Method
db.insertIn("users") \
.row('Maria', 'maria@email.it', db.skip, 20) \
.record()
Using the .multiRows Method
db.insertIn("users") \
.multiRows([
("Luigi", "luigi@mail.it", db.null, 40, 1.80),
("Carla", "carla@mail.us", "1990", 35, db.skip),
("John", "john@mail.us", db.skip, 28, 1.75)
]) \
.record()
5. Querying Data
db.select('users').fetch().show()
Fetch and display all rows from the users table.
6. Updating Records
Using .field
db.updateIn("users") \
.where("name = ?", "Paolo") \
.field('age', 26) \
.field('birth', db.null) \
.record()
Using .row
db.updateIn("users") \
.where("age = 20") \
.row(db.skip, db.skip, '2005') \
.record()
7. Managing Tables
Renaming a Table
db.modTable("users").modName("customers")
Removing a Column
db.modTable("customers").remCol("birth")
8. Working with Foreign Keys
Creating a Related Table
db.newTable("countries") \
.PK() \
.textCol("name", "NN") \
.create()
Adding a Foreign Key
db.addToTable('customers').FK('country_id', 'countries').add()
Updating Foreign Key Relationships
db.updateIn('customers').where('email LIKE ?', '%it').field('country_id', 1).record()
9. Exporting Data
Export to CSV
res.exportCSV("output.csv")
Export to JSON
res.exportJSON("output.json")
10. Deleting and Closing
Drop table
db.dropTable("customers")
Delete .db file and close connection
db.deleteDatabaseFileAndClose(self)
Close connection
db.close("output.csv")
Development Status
easyLite is a work-in-progress personal project. Suggestions, feature requests, and constructive feedback are highly welcome. Feel free to open an issue or submit a pull request.
License
This project is licensed under the MIT License.
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 easylite-1.7.1.tar.gz.
File metadata
- Download URL: easylite-1.7.1.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be25c9a49ce120c87a1810d8407a88e8563166e5f89e41d8d7fc7b4617ee8a07
|
|
| MD5 |
b1fd4247a17f8e2f263b105f7b5efb1a
|
|
| BLAKE2b-256 |
969547d568eb66e22c3ec658c42b140d59815b66278886603919e2de42e9bf15
|
File details
Details for the file easyLite-1.7.1-py3-none-any.whl.
File metadata
- Download URL: easyLite-1.7.1-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
550ac16d53296ed1c55d8c35163c2d94915ac4be9e6e55b13c63f90b4e3303c8
|
|
| MD5 |
93f2683423af5aab9bc7c821ab3c894c
|
|
| BLAKE2b-256 |
149251d0e1366085c674526686885bffa58ac67a20ea182ae8ede2e6f9821574
|