sqliter-py 0.1.1__py3-none-any.whl → 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sqliter/constants.py +20 -0
- sqliter/exceptions.py +6 -0
- sqliter/model/model.py +74 -8
- sqliter/query/query.py +362 -84
- sqliter/sqliter.py +71 -19
- sqliter_py-0.3.0.dist-info/METADATA +601 -0
- sqliter_py-0.3.0.dist-info/RECORD +12 -0
- sqliter_py-0.3.0.dist-info/licenses/LICENSE.txt +20 -0
- sqliter_py-0.1.1.dist-info/METADATA +0 -204
- sqliter_py-0.1.1.dist-info/RECORD +0 -10
- {sqliter_py-0.1.1.dist-info → sqliter_py-0.3.0.dist-info}/WHEEL +0 -0
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.3
|
|
2
|
-
Name: sqliter-py
|
|
3
|
-
Version: 0.1.1
|
|
4
|
-
Summary: Interact with SQLite databases using Python and Pydantic
|
|
5
|
-
Project-URL: Pull Requests, https://github.com/seapagan/sqliter-py/pulls
|
|
6
|
-
Project-URL: Bug Tracker, https://github.com/seapagan/sqliter-py/issues
|
|
7
|
-
Project-URL: Repository, https://github.com/seapagan/sqliter-py
|
|
8
|
-
Author-email: Grant Ramsay <grant@gnramsay.com>
|
|
9
|
-
License-Expression: MIT
|
|
10
|
-
Classifier: Development Status :: 4 - Beta
|
|
11
|
-
Classifier: Intended Audience :: Developers
|
|
12
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
-
Classifier: Operating System :: OS Independent
|
|
14
|
-
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
-
Classifier: Topic :: Software Development
|
|
20
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
-
Requires-Python: >=3.9
|
|
22
|
-
Requires-Dist: pydantic>=2.9.0
|
|
23
|
-
Description-Content-Type: text/markdown
|
|
24
|
-
|
|
25
|
-
# SQLiter
|
|
26
|
-
|
|
27
|
-
<!--  -->
|
|
28
|
-
[](https://github.com/seapagan/sqliter-py/actions/workflows/testing.yml)
|
|
29
|
-
[](https://github.com/seapagan/sqliter-py/actions/workflows/linting.yml)
|
|
30
|
-
[](https://github.com/seapagan/sqliter-py/actions/workflows/mypy.yml)
|
|
31
|
-
<!--  -->
|
|
32
|
-
|
|
33
|
-
SQLiter is a lightweight Object-Relational Mapping (ORM) library for SQLite
|
|
34
|
-
databases in Python. It provides a simplified interface for interacting with
|
|
35
|
-
SQLite databases using Pydantic models.
|
|
36
|
-
|
|
37
|
-
It does not aim to be a full-fledged ORM like SQLAlchemy, but rather a simple
|
|
38
|
-
and easy-to-use library for basic database operations, especially for small
|
|
39
|
-
projects. It is NOT asynchronous and does not support complex queries (at this
|
|
40
|
-
time).
|
|
41
|
-
|
|
42
|
-
The ideal use case is more for Python CLI tools that need to store data in a
|
|
43
|
-
database-like format without needing to learn SQL or use a full ORM.
|
|
44
|
-
|
|
45
|
-
> [!NOTE]
|
|
46
|
-
> This project is still in the early stages of development and is lacking some
|
|
47
|
-
> planned functionality. Please use with caution.
|
|
48
|
-
>
|
|
49
|
-
> See the [TODO](TODO.md) for planned features and improvements.
|
|
50
|
-
|
|
51
|
-
## Features
|
|
52
|
-
|
|
53
|
-
- Table creation based on Pydantic models
|
|
54
|
-
- CRUD operations (Create, Read, Update, Delete)
|
|
55
|
-
- Basic query building with filtering, ordering, and pagination
|
|
56
|
-
- Transaction support
|
|
57
|
-
- Custom exceptions for better error handling
|
|
58
|
-
|
|
59
|
-
## Installation
|
|
60
|
-
|
|
61
|
-
You can install SQLiter using pip:
|
|
62
|
-
|
|
63
|
-
```bash
|
|
64
|
-
pip install sqliter-py
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
## Quick Start
|
|
68
|
-
|
|
69
|
-
Here's a quick example of how to use SQLiter:
|
|
70
|
-
|
|
71
|
-
```python
|
|
72
|
-
from sqliter import SqliterDB
|
|
73
|
-
from sqliter.model import BaseDBModel
|
|
74
|
-
|
|
75
|
-
# Define your model
|
|
76
|
-
class User(BaseDBModel):
|
|
77
|
-
name: str
|
|
78
|
-
age: int
|
|
79
|
-
|
|
80
|
-
class Meta:
|
|
81
|
-
table_name = "users"
|
|
82
|
-
|
|
83
|
-
# Create a database connection
|
|
84
|
-
db = SqliterDB("example.db", auto_commit=True)
|
|
85
|
-
|
|
86
|
-
# Create the table
|
|
87
|
-
db.create_table(User)
|
|
88
|
-
|
|
89
|
-
# Insert a record
|
|
90
|
-
user = User(name="John Doe", age=30)
|
|
91
|
-
db.insert(user)
|
|
92
|
-
|
|
93
|
-
# Query records
|
|
94
|
-
results = db.select(User).filter(name="John Doe").fetch_all()
|
|
95
|
-
for user in results:
|
|
96
|
-
print(f"User: {user.name}, Age: {user.age}")
|
|
97
|
-
|
|
98
|
-
# Update a record
|
|
99
|
-
user.age = 31
|
|
100
|
-
db.update(user)
|
|
101
|
-
|
|
102
|
-
# Delete a record
|
|
103
|
-
db.delete(User, "John Doe")
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
## Detailed Usage
|
|
107
|
-
|
|
108
|
-
### Defining Models
|
|
109
|
-
|
|
110
|
-
Models in SQLiter are based on Pydantic's `BaseModel`. You can define your
|
|
111
|
-
models like this:
|
|
112
|
-
|
|
113
|
-
```python
|
|
114
|
-
from sqliter.model import BaseDBModel
|
|
115
|
-
|
|
116
|
-
class User(BaseDBModel):
|
|
117
|
-
name: str
|
|
118
|
-
age: int
|
|
119
|
-
email: str
|
|
120
|
-
|
|
121
|
-
class Meta:
|
|
122
|
-
table_name = "users"
|
|
123
|
-
primary_key = "name" # Default is "id"
|
|
124
|
-
create_id = False # Set to True to auto-create an ID field
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
### Database Operations
|
|
128
|
-
|
|
129
|
-
#### Creating a Connection
|
|
130
|
-
|
|
131
|
-
```python
|
|
132
|
-
from sqliter import SqliterDB
|
|
133
|
-
|
|
134
|
-
db = SqliterDB("your_database.db", auto_commit=True)
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
#### Creating Tables
|
|
138
|
-
|
|
139
|
-
```python
|
|
140
|
-
db.create_table(User)
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
#### Inserting Records
|
|
144
|
-
|
|
145
|
-
```python
|
|
146
|
-
user = User(name="Jane Doe", age=25, email="jane@example.com")
|
|
147
|
-
db.insert(user)
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
#### Querying Records
|
|
151
|
-
|
|
152
|
-
```python
|
|
153
|
-
# Fetch all users
|
|
154
|
-
all_users = db.select(User).fetch_all()
|
|
155
|
-
|
|
156
|
-
# Filter users
|
|
157
|
-
young_users = db.select(User).filter(age=25).fetch_all()
|
|
158
|
-
|
|
159
|
-
# Order users
|
|
160
|
-
ordered_users = db.select(User).order("age DESC").fetch_all()
|
|
161
|
-
|
|
162
|
-
# Limit and offset
|
|
163
|
-
paginated_users = db.select(User).limit(10).offset(20).fetch_all()
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
Note: The filtering in SQLiter is basic and supports exact matches. Complex
|
|
167
|
-
queries like `age__lt` are not supported in the current implementation.
|
|
168
|
-
|
|
169
|
-
#### Updating Records
|
|
170
|
-
|
|
171
|
-
```python
|
|
172
|
-
user.age = 26
|
|
173
|
-
db.update(user)
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
#### Deleting Records
|
|
177
|
-
|
|
178
|
-
```python
|
|
179
|
-
db.delete(User, "Jane Doe")
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
### Transactions
|
|
183
|
-
|
|
184
|
-
SQLiter supports transactions using Python's context manager:
|
|
185
|
-
|
|
186
|
-
```python
|
|
187
|
-
with db:
|
|
188
|
-
db.insert(User(name="Alice", age=30, email="alice@example.com"))
|
|
189
|
-
db.insert(User(name="Bob", age=35, email="bob@example.com"))
|
|
190
|
-
# If an exception occurs, the transaction will be rolled back
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
## Contributing
|
|
194
|
-
|
|
195
|
-
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
196
|
-
|
|
197
|
-
## License
|
|
198
|
-
|
|
199
|
-
This project is licensed under the MIT License.
|
|
200
|
-
|
|
201
|
-
## Acknowledgements
|
|
202
|
-
|
|
203
|
-
SQLiter was initially developed as an experiment using ChatGPT, with subsequent
|
|
204
|
-
manual refinements and improvements.
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
sqliter/__init__.py,sha256=L8R0uvCbbbACwaI5xtd3khtvpNhlPRgHJAaYZvqjzig,134
|
|
2
|
-
sqliter/exceptions.py,sha256=5NO9DwHMVKrDZP908G63J5-ANBJDCwbBkXL7h_Bit2Q,3610
|
|
3
|
-
sqliter/sqliter.py,sha256=R69oNusPEg0Q_zRPFetS9VUUCT5pjatXnUr3Tv6yzjE,7494
|
|
4
|
-
sqliter/model/__init__.py,sha256=Ovpkbyx2-T6Oee0qFNgUBBc2M0uwK-cdG0pigG3mkd8,179
|
|
5
|
-
sqliter/model/model.py,sha256=t1w38om37gma1gRk01Z_9II0h4g-l734ijN_8M1SYoY,1247
|
|
6
|
-
sqliter/query/__init__.py,sha256=BluNMJpuoo2PsYN-bL7fXlEc02O_8LgOMsvCmyv04ao,125
|
|
7
|
-
sqliter/query/query.py,sha256=BRKCdMBOlbcIU5CUxRyKBF4aFT2AboUPu7UwbJ1s5hs,5793
|
|
8
|
-
sqliter_py-0.1.1.dist-info/METADATA,sha256=ehe8KZXc08ftvn2i6FGiw3Qe8jK6QsqApDoDQm9p0XE,5477
|
|
9
|
-
sqliter_py-0.1.1.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
10
|
-
sqliter_py-0.1.1.dist-info/RECORD,,
|
|
File without changes
|