sqliter-py 0.3.0__py3-none-any.whl → 0.4.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.
Potentially problematic release.
This version of sqliter-py might be problematic. Click here for more details.
- sqliter/__init__.py +5 -1
- sqliter/constants.py +18 -1
- sqliter/exceptions.py +39 -12
- sqliter/helpers.py +35 -0
- sqliter/model/__init__.py +3 -2
- sqliter/model/model.py +50 -10
- sqliter/query/__init__.py +5 -1
- sqliter/query/query.py +278 -36
- sqliter/sqliter.py +317 -38
- sqliter_py-0.4.0.dist-info/METADATA +196 -0
- sqliter_py-0.4.0.dist-info/RECORD +13 -0
- sqliter_py-0.3.0.dist-info/METADATA +0 -601
- sqliter_py-0.3.0.dist-info/RECORD +0 -12
- {sqliter_py-0.3.0.dist-info → sqliter_py-0.4.0.dist-info}/WHEEL +0 -0
- {sqliter_py-0.3.0.dist-info → sqliter_py-0.4.0.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -1,601 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.3
|
|
2
|
-
Name: sqliter-py
|
|
3
|
-
Version: 0.3.0
|
|
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: Changelog, https://github.com/seapagan/sqliter-py/blob/main/CHANGELOG.md
|
|
8
|
-
Project-URL: Repository, https://github.com/seapagan/sqliter-py
|
|
9
|
-
Author-email: Grant Ramsay <grant@gnramsay.com>
|
|
10
|
-
License-Expression: MIT
|
|
11
|
-
License-File: LICENSE.txt
|
|
12
|
-
Classifier: Development Status :: 4 - Beta
|
|
13
|
-
Classifier: Intended Audience :: Developers
|
|
14
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
-
Classifier: Operating System :: OS Independent
|
|
16
|
-
Classifier: Programming Language :: Python :: 3
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
-
Classifier: Topic :: Software Development
|
|
22
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
-
Requires-Python: >=3.9
|
|
24
|
-
Requires-Dist: pydantic>=2.9.0
|
|
25
|
-
Provides-Extra: extras
|
|
26
|
-
Requires-Dist: inflect==7.0.0; extra == 'extras'
|
|
27
|
-
Description-Content-Type: text/markdown
|
|
28
|
-
|
|
29
|
-
# SQLiter <!-- omit in toc -->
|
|
30
|
-
|
|
31
|
-

|
|
32
|
-
[](https://github.com/seapagan/sqliter-py/actions/workflows/testing.yml)
|
|
33
|
-
[](https://github.com/seapagan/sqliter-py/actions/workflows/linting.yml)
|
|
34
|
-
[](https://github.com/seapagan/sqliter-py/actions/workflows/mypy.yml)
|
|
35
|
-

|
|
36
|
-
|
|
37
|
-
SQLiter is a lightweight Object-Relational Mapping (ORM) library for SQLite
|
|
38
|
-
databases in Python. It provides a simplified interface for interacting with
|
|
39
|
-
SQLite databases using Pydantic models. The only external run-time dependency
|
|
40
|
-
is Pydantic itself.
|
|
41
|
-
|
|
42
|
-
It does not aim to be a full-fledged ORM like SQLAlchemy, but rather a simple
|
|
43
|
-
and easy-to-use library for basic database operations, especially for small
|
|
44
|
-
projects. It is NOT asynchronous and does not support complex queries (at this
|
|
45
|
-
time).
|
|
46
|
-
|
|
47
|
-
The ideal use case is more for Python CLI tools that need to store data in a
|
|
48
|
-
database-like format without needing to learn SQL or use a full ORM.
|
|
49
|
-
|
|
50
|
-
> [!IMPORTANT]
|
|
51
|
-
> This project is still in the early stages of development and is lacking some
|
|
52
|
-
> planned functionality. Please use with caution.
|
|
53
|
-
>
|
|
54
|
-
> Also, structures like `list`, `dict`, `set` etc are not supported **at this
|
|
55
|
-
> time** as field types, since SQLite does not have a native column type for
|
|
56
|
-
> these. I will look at implementing these in the future, probably by
|
|
57
|
-
> serializing them to JSON or pickling them and storing in a text field. For
|
|
58
|
-
> now, you can actually do this manually when creating your Model (use `TEXT` or
|
|
59
|
-
> `BLOB` fields), then serialize before saving after and retrieving data.
|
|
60
|
-
>
|
|
61
|
-
> See the [TODO](TODO.md) for planned features and improvements.
|
|
62
|
-
|
|
63
|
-
- [Features](#features)
|
|
64
|
-
- [Installation](#installation)
|
|
65
|
-
- [Optional Dependencies](#optional-dependencies)
|
|
66
|
-
- [Quick Start](#quick-start)
|
|
67
|
-
- [Detailed Usage](#detailed-usage)
|
|
68
|
-
- [Defining Models](#defining-models)
|
|
69
|
-
- [Database Operations](#database-operations)
|
|
70
|
-
- [Creating a Connection](#creating-a-connection)
|
|
71
|
-
- [Using an In-Memory Database](#using-an-in-memory-database)
|
|
72
|
-
- [Creating Tables](#creating-tables)
|
|
73
|
-
- [Inserting Records](#inserting-records)
|
|
74
|
-
- [Querying Records](#querying-records)
|
|
75
|
-
- [Updating Records](#updating-records)
|
|
76
|
-
- [Deleting Records](#deleting-records)
|
|
77
|
-
- [Commit your changes](#commit-your-changes)
|
|
78
|
-
- [Close the Connection](#close-the-connection)
|
|
79
|
-
- [Transactions](#transactions)
|
|
80
|
-
- [Ordering](#ordering)
|
|
81
|
-
- [Field Control](#field-control)
|
|
82
|
-
- [Selecting Specific Fields](#selecting-specific-fields)
|
|
83
|
-
- [Excluding Specific Fields](#excluding-specific-fields)
|
|
84
|
-
- [Returning exactly one explicit field only](#returning-exactly-one-explicit-field-only)
|
|
85
|
-
- [Filter Options](#filter-options)
|
|
86
|
-
- [Basic Filters](#basic-filters)
|
|
87
|
-
- [Null Checks](#null-checks)
|
|
88
|
-
- [Comparison Operators](#comparison-operators)
|
|
89
|
-
- [List Operations](#list-operations)
|
|
90
|
-
- [String Operations (Case-Sensitive)](#string-operations-case-sensitive)
|
|
91
|
-
- [String Operations (Case-Insensitive)](#string-operations-case-insensitive)
|
|
92
|
-
- [Contributing](#contributing)
|
|
93
|
-
- [Exceptions](#exceptions)
|
|
94
|
-
- [License](#license)
|
|
95
|
-
- [Acknowledgements](#acknowledgements)
|
|
96
|
-
|
|
97
|
-
## Features
|
|
98
|
-
|
|
99
|
-
- Table creation based on Pydantic models
|
|
100
|
-
- CRUD operations (Create, Read, Update, Delete)
|
|
101
|
-
- Basic query building with filtering, ordering, and pagination
|
|
102
|
-
- Transaction support
|
|
103
|
-
- Custom exceptions for better error handling
|
|
104
|
-
- Full type hinting and type checking
|
|
105
|
-
- No external dependencies other than Pydantic
|
|
106
|
-
- Full test coverage
|
|
107
|
-
|
|
108
|
-
## Installation
|
|
109
|
-
|
|
110
|
-
You can install SQLiter using whichever method you prefer or is compatible with
|
|
111
|
-
your project setup.
|
|
112
|
-
|
|
113
|
-
With `uv` which is rapidly becoming my favorite tool for managing projects and
|
|
114
|
-
virtual environments (`uv` is used for developing this project and in the CI):
|
|
115
|
-
|
|
116
|
-
```bash
|
|
117
|
-
uv add sqliter-py
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
With `pip`:
|
|
121
|
-
|
|
122
|
-
```bash
|
|
123
|
-
pip install sqliter-py
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
Or with `Poetry`:
|
|
127
|
-
|
|
128
|
-
```bash
|
|
129
|
-
poetry add sqliter-py
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### Optional Dependencies
|
|
133
|
-
|
|
134
|
-
Currently by default, the only external dependency is Pydantic. However, there
|
|
135
|
-
are some optional dependencies that can be installed to enable additional
|
|
136
|
-
features:
|
|
137
|
-
|
|
138
|
-
- `inflect`: For pluralizing table names (if not specified). This just offers a
|
|
139
|
-
more-advanced pluralization than the default method used. In most cases you
|
|
140
|
-
will not need this.
|
|
141
|
-
|
|
142
|
-
These can be installed using `uv`:
|
|
143
|
-
|
|
144
|
-
```bash
|
|
145
|
-
uv add 'sqliter-py[extras]'
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
Or with `pip`:
|
|
149
|
-
|
|
150
|
-
```bash
|
|
151
|
-
pip install 'sqliter-py[extras]'
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
Or with `Poetry`:
|
|
155
|
-
|
|
156
|
-
```bash
|
|
157
|
-
poetry add 'sqliter-py[extras]'
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
## Quick Start
|
|
161
|
-
|
|
162
|
-
Here's a quick example of how to use SQLiter:
|
|
163
|
-
|
|
164
|
-
```python
|
|
165
|
-
from sqliter import SqliterDB
|
|
166
|
-
from sqliter.model import BaseDBModel
|
|
167
|
-
|
|
168
|
-
# Define your model
|
|
169
|
-
class User(BaseDBModel):
|
|
170
|
-
name: str
|
|
171
|
-
age: int
|
|
172
|
-
|
|
173
|
-
class Meta:
|
|
174
|
-
table_name = "users"
|
|
175
|
-
|
|
176
|
-
# Create a database connection
|
|
177
|
-
db = SqliterDB("example.db")
|
|
178
|
-
|
|
179
|
-
# Create the table
|
|
180
|
-
db.create_table(User)
|
|
181
|
-
|
|
182
|
-
# Insert a record
|
|
183
|
-
user = User(name="John Doe", age=30)
|
|
184
|
-
db.insert(user)
|
|
185
|
-
|
|
186
|
-
# Query records
|
|
187
|
-
results = db.select(User).filter(name="John Doe").fetch_all()
|
|
188
|
-
for user in results:
|
|
189
|
-
print(f"User: {user.name}, Age: {user.age}")
|
|
190
|
-
|
|
191
|
-
# Update a record
|
|
192
|
-
user.age = 31
|
|
193
|
-
db.update(user)
|
|
194
|
-
|
|
195
|
-
# Delete a record
|
|
196
|
-
db.delete(User, "John Doe")
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
## Detailed Usage
|
|
200
|
-
|
|
201
|
-
### Defining Models
|
|
202
|
-
|
|
203
|
-
Models in SQLiter are based on Pydantic's `BaseModel`. You can define your
|
|
204
|
-
models like this:
|
|
205
|
-
|
|
206
|
-
```python
|
|
207
|
-
from sqliter.model import BaseDBModel
|
|
208
|
-
|
|
209
|
-
class User(BaseDBModel):
|
|
210
|
-
name: str
|
|
211
|
-
age: int
|
|
212
|
-
email: str
|
|
213
|
-
|
|
214
|
-
class Meta:
|
|
215
|
-
table_name = "users"
|
|
216
|
-
primary_key = "name" # Default is "id"
|
|
217
|
-
create_pk = False # disable auto-creating an incrementing primary key - default is True
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
For a standard database with an auto-incrementing integer 'id' primary key, you
|
|
221
|
-
do not need to specify the `primary_key` or `create_pk` fields. If you want to
|
|
222
|
-
specify a different primary key field name, you can do so using the
|
|
223
|
-
`primary_key` field in the `Meta` class.
|
|
224
|
-
|
|
225
|
-
If `table_name` is not specified, the table name will be the same as the model
|
|
226
|
-
name, converted to 'snake_case' and pluralized (e.g., `User` -> `users`). Also,
|
|
227
|
-
any 'Model' suffix will be removed (e.g., `UserModel` -> `users`). To override
|
|
228
|
-
this behavior, you can specify the `table_name` in the `Meta` class manually as
|
|
229
|
-
above.
|
|
230
|
-
|
|
231
|
-
> [!NOTE]
|
|
232
|
-
>
|
|
233
|
-
> The pluralization is pretty basic by default, and just consists of adding an
|
|
234
|
-
> 's' if not already there. This will fail on words like 'person' or 'child'. If
|
|
235
|
-
> you need more advanced pluralization, you can install the `extras` package as
|
|
236
|
-
> mentioned above. Of course, you can always specify the `table_name` manually
|
|
237
|
-
> in this case!
|
|
238
|
-
|
|
239
|
-
### Database Operations
|
|
240
|
-
|
|
241
|
-
#### Creating a Connection
|
|
242
|
-
|
|
243
|
-
```python
|
|
244
|
-
from sqliter import SqliterDB
|
|
245
|
-
|
|
246
|
-
db = SqliterDB("your_database.db")
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
The default behavior is to automatically commit changes to the database after
|
|
250
|
-
each operation. If you want to disable this behavior, you can set `auto_commit=False`
|
|
251
|
-
when creating the database connection:
|
|
252
|
-
|
|
253
|
-
```python
|
|
254
|
-
db = SqliterDB("your_database.db", auto_commit=False)
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
It is then up to you to manually commit changes using the `commit()` method.
|
|
258
|
-
This can be useful when you want to perform multiple operations in a single
|
|
259
|
-
transaction without the overhead of committing after each operation.
|
|
260
|
-
|
|
261
|
-
#### Using an In-Memory Database
|
|
262
|
-
|
|
263
|
-
If you want to use an in-memory database, you can set `memory=True` when
|
|
264
|
-
creating the database connection:
|
|
265
|
-
|
|
266
|
-
```python
|
|
267
|
-
db = SqliterDB(memory=True)
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
This will create an in-memory database that is not persisted to disk. If you
|
|
271
|
-
also specify a database name, it will be ignored.
|
|
272
|
-
|
|
273
|
-
```python
|
|
274
|
-
db = SqliterDB("ignored.db", memory=True)
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
The `ignored.db` file will not be created, and the database will be in-memory.
|
|
278
|
-
If you do not specify a database name, and do NOT set `memory=True`, an
|
|
279
|
-
exception will be raised.
|
|
280
|
-
|
|
281
|
-
> [!NOTE]
|
|
282
|
-
>
|
|
283
|
-
> You can also use `":memory:"` as the database name (same as normal with
|
|
284
|
-
> Sqlite) to create an in-memory database, this is just a cleaner and more
|
|
285
|
-
> descriptive way to do it.
|
|
286
|
-
>
|
|
287
|
-
> ```python
|
|
288
|
-
> db = SqliterDB(":memory:")
|
|
289
|
-
> ```
|
|
290
|
-
|
|
291
|
-
#### Creating Tables
|
|
292
|
-
|
|
293
|
-
```python
|
|
294
|
-
db.create_table(User)
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
#### Inserting Records
|
|
298
|
-
|
|
299
|
-
```python
|
|
300
|
-
user = User(name="Jane Doe", age=25, email="jane@example.com")
|
|
301
|
-
db.insert(user)
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
#### Querying Records
|
|
305
|
-
|
|
306
|
-
```python
|
|
307
|
-
# Fetch all users
|
|
308
|
-
all_users = db.select(User).fetch_all()
|
|
309
|
-
|
|
310
|
-
# Filter users
|
|
311
|
-
young_users = db.select(User).filter(age=25).fetch_all()
|
|
312
|
-
|
|
313
|
-
# Order users
|
|
314
|
-
ordered_users = db.select(User).order("age", reverse=True).fetch_all()
|
|
315
|
-
|
|
316
|
-
# Limit and offset
|
|
317
|
-
paginated_users = db.select(User).limit(10).offset(20).fetch_all()
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
> [!IMPORTANT]
|
|
321
|
-
>
|
|
322
|
-
> The `select()` MUST come first, before any filtering, ordering, or pagination
|
|
323
|
-
> etc. This is the starting point for building your query.
|
|
324
|
-
|
|
325
|
-
See below for more advanced filtering options.
|
|
326
|
-
|
|
327
|
-
#### Updating Records
|
|
328
|
-
|
|
329
|
-
```python
|
|
330
|
-
user.age = 26
|
|
331
|
-
db.update(user)
|
|
332
|
-
```
|
|
333
|
-
|
|
334
|
-
#### Deleting Records
|
|
335
|
-
|
|
336
|
-
```python
|
|
337
|
-
db.delete(User, "Jane Doe")
|
|
338
|
-
```
|
|
339
|
-
|
|
340
|
-
#### Commit your changes
|
|
341
|
-
|
|
342
|
-
By default, SQLiter will automatically commit changes to the database after each
|
|
343
|
-
operation. If you want to disable this behavior, you can set `auto_commit=False`
|
|
344
|
-
when creating the database connection:
|
|
345
|
-
|
|
346
|
-
```python
|
|
347
|
-
db = SqliterDB("your_database.db", auto_commit=False)
|
|
348
|
-
```
|
|
349
|
-
|
|
350
|
-
You can then manually commit changes using the `commit()` method:
|
|
351
|
-
|
|
352
|
-
```python
|
|
353
|
-
db.commit()
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
#### Close the Connection
|
|
357
|
-
|
|
358
|
-
When you're done with the database connection, you should close it to release
|
|
359
|
-
resources:
|
|
360
|
-
|
|
361
|
-
```python
|
|
362
|
-
db.close()
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
Note that closing the connection will also commit any pending changes, unless
|
|
366
|
-
`auto_commit` is set to `False`.
|
|
367
|
-
|
|
368
|
-
### Transactions
|
|
369
|
-
|
|
370
|
-
SQLiter supports transactions using Python's context manager:
|
|
371
|
-
|
|
372
|
-
```python
|
|
373
|
-
with db:
|
|
374
|
-
db.insert(User(name="Alice", age=30, email="alice@example.com"))
|
|
375
|
-
db.insert(User(name="Bob", age=35, email="bob@example.com"))
|
|
376
|
-
# If an exception occurs, the transaction will be rolled back
|
|
377
|
-
```
|
|
378
|
-
|
|
379
|
-
> [!WARNING]
|
|
380
|
-
> Using the context manager will automatically commit the transaction
|
|
381
|
-
> at the end (unless an exception occurs), regardless of the `auto_commit`
|
|
382
|
-
> setting.
|
|
383
|
-
>
|
|
384
|
-
> the `close()` method will also be called when the context manager exits, so you
|
|
385
|
-
> do not need to call it manually.
|
|
386
|
-
|
|
387
|
-
### Ordering
|
|
388
|
-
|
|
389
|
-
For now we only support ordering by the single field. You can specify the
|
|
390
|
-
field to order by and whether to reverse the order:
|
|
391
|
-
|
|
392
|
-
```python
|
|
393
|
-
results = db.select(User).order("age", reverse=True).fetch_all()
|
|
394
|
-
```
|
|
395
|
-
|
|
396
|
-
This will order the results by the `age` field in descending order.
|
|
397
|
-
|
|
398
|
-
> [!WARNING]
|
|
399
|
-
>
|
|
400
|
-
> Previously ordering was done using the `direction` parameter with `asc` or
|
|
401
|
-
> `desc`, but this has been deprecated in favor of using the `reverse`
|
|
402
|
-
> parameter. The `direction` parameter still works, but will raise a
|
|
403
|
-
> `DeprecationWarning` and will be removed in a future release.
|
|
404
|
-
|
|
405
|
-
### Field Control
|
|
406
|
-
|
|
407
|
-
#### Selecting Specific Fields
|
|
408
|
-
|
|
409
|
-
By default, all commands query and return all fields in the table. If you want
|
|
410
|
-
to select only specific fields, you can pass them using the `fields()`
|
|
411
|
-
method:
|
|
412
|
-
|
|
413
|
-
```python
|
|
414
|
-
results = db.select(User).fields(["name", "age"]).fetch_all()
|
|
415
|
-
```
|
|
416
|
-
|
|
417
|
-
This will return only the `name` and `age` fields for each record.
|
|
418
|
-
|
|
419
|
-
You can also pass this as a parameter to the `select()` method:
|
|
420
|
-
|
|
421
|
-
```python
|
|
422
|
-
results = db.select(User, fields=["name", "age"]).fetch_all()
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
Note that using the `fields()` method will override any fields specified in the
|
|
426
|
-
'select()' method.
|
|
427
|
-
|
|
428
|
-
#### Excluding Specific Fields
|
|
429
|
-
|
|
430
|
-
If you want to exclude specific fields from the results, you can use the
|
|
431
|
-
`exclude()` method:
|
|
432
|
-
|
|
433
|
-
```python
|
|
434
|
-
results = db.select(User).exclude(["email"]).fetch_all()
|
|
435
|
-
```
|
|
436
|
-
|
|
437
|
-
This will return all fields except the `email` field.
|
|
438
|
-
|
|
439
|
-
You can also pass this as a parameter to the `select()` method:
|
|
440
|
-
|
|
441
|
-
```python
|
|
442
|
-
results = db.select(User, exclude=["email"]).fetch_all()
|
|
443
|
-
```
|
|
444
|
-
|
|
445
|
-
#### Returning exactly one explicit field only
|
|
446
|
-
|
|
447
|
-
If you only want to return a single field from the results, you can use the
|
|
448
|
-
`only()` method:
|
|
449
|
-
|
|
450
|
-
```python
|
|
451
|
-
result = db.select(User).only("name").fetch_first()
|
|
452
|
-
```
|
|
453
|
-
|
|
454
|
-
This will return only the `name` field for the first record.
|
|
455
|
-
|
|
456
|
-
This is exactly the same as using the `fields()` method with a single field, but
|
|
457
|
-
very specific and obvious. **There is NO equivalent argument to this in the
|
|
458
|
-
`select()` method**. An exception **WILL** be raised if you try to use this method
|
|
459
|
-
with more than one field.
|
|
460
|
-
|
|
461
|
-
### Filter Options
|
|
462
|
-
|
|
463
|
-
The `filter()` method in SQLiter supports various filter options to query records.
|
|
464
|
-
|
|
465
|
-
#### Basic Filters
|
|
466
|
-
|
|
467
|
-
- `__eq`: Equal to (default if no operator is specified)
|
|
468
|
-
- Example: `name="John"` or `name__eq="John"`
|
|
469
|
-
|
|
470
|
-
#### Null Checks
|
|
471
|
-
|
|
472
|
-
- `__isnull`: Is NULL
|
|
473
|
-
- Example: `email__isnull=True`
|
|
474
|
-
- `__notnull`: Is NOT NULL
|
|
475
|
-
- Example: `email__notnull=True`
|
|
476
|
-
|
|
477
|
-
#### Comparison Operators
|
|
478
|
-
|
|
479
|
-
- `__lt`: Less than
|
|
480
|
-
- Example: `age__lt=30`
|
|
481
|
-
- `__lte`: Less than or equal to
|
|
482
|
-
- Example: `age__lte=30`
|
|
483
|
-
- `__gt`: Greater than
|
|
484
|
-
- Example: `age__gt=30`
|
|
485
|
-
- `__gte`: Greater than or equal to
|
|
486
|
-
- Example: `age__gte=30`
|
|
487
|
-
- `__ne`: Not equal to
|
|
488
|
-
- Example: `status__ne="inactive"`
|
|
489
|
-
|
|
490
|
-
#### List Operations
|
|
491
|
-
|
|
492
|
-
- `__in`: In a list of values
|
|
493
|
-
- Example: `status__in=["active", "pending"]`
|
|
494
|
-
- `__not_in`: Not in a list of values
|
|
495
|
-
- Example: `category__not_in=["archived", "deleted"]`
|
|
496
|
-
|
|
497
|
-
#### String Operations (Case-Sensitive)
|
|
498
|
-
|
|
499
|
-
- `__startswith`: Starts with
|
|
500
|
-
- Example: `name__startswith="A"`
|
|
501
|
-
- `__endswith`: Ends with
|
|
502
|
-
- Example: `email__endswith=".com"`
|
|
503
|
-
- `__contains`: Contains
|
|
504
|
-
- Example: `description__contains="important"`
|
|
505
|
-
|
|
506
|
-
#### String Operations (Case-Insensitive)
|
|
507
|
-
|
|
508
|
-
- `__istartswith`: Starts with (case-insensitive)
|
|
509
|
-
- Example: `name__istartswith="a"`
|
|
510
|
-
- `__iendswith`: Ends with (case-insensitive)
|
|
511
|
-
- Example: `email__iendswith=".COM"`
|
|
512
|
-
- `__icontains`: Contains (case-insensitive)
|
|
513
|
-
- Example: `description__icontains="IMPORTANT"`
|
|
514
|
-
|
|
515
|
-
## Contributing
|
|
516
|
-
|
|
517
|
-
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
518
|
-
|
|
519
|
-
See the [CONTRIBUTING](CONTRIBUTING.md) guide for more information.
|
|
520
|
-
|
|
521
|
-
Please note that this project is released with a Contributor Code of Conduct,
|
|
522
|
-
which you can read in the [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) file.
|
|
523
|
-
|
|
524
|
-
## Exceptions
|
|
525
|
-
|
|
526
|
-
SQLiter includes several custom exceptions to handle specific errors that may occur during database operations. These exceptions inherit from a common base class, `SqliterError`, to ensure consistency across error messages and behavior.
|
|
527
|
-
|
|
528
|
-
- **`SqliterError`**:
|
|
529
|
-
- The base class for all exceptions in SQLiter. It captures the exception context and chains any previous exceptions.
|
|
530
|
-
- **Message**: "An error occurred in the SQLiter package."
|
|
531
|
-
|
|
532
|
-
- **`DatabaseConnectionError`**:
|
|
533
|
-
- Raised when the SQLite database connection fails.
|
|
534
|
-
- **Message**: "Failed to connect to the database: '{}'."
|
|
535
|
-
|
|
536
|
-
- **`InvalidOffsetError`**:
|
|
537
|
-
- Raised when an invalid offset value (0 or negative) is used in queries.
|
|
538
|
-
- **Message**: "Invalid offset value: '{}'. Offset must be a positive integer."
|
|
539
|
-
|
|
540
|
-
- **`InvalidOrderError`**:
|
|
541
|
-
- Raised when an invalid order value is used in queries, such as a non-existent field or an incorrect sorting direction.
|
|
542
|
-
- **Message**: "Invalid order value - {}"
|
|
543
|
-
|
|
544
|
-
- **`TableCreationError`**:
|
|
545
|
-
- Raised when a table cannot be created in the database.
|
|
546
|
-
- **Message**: "Failed to create the table: '{}'."
|
|
547
|
-
|
|
548
|
-
- **`RecordInsertionError`**:
|
|
549
|
-
- Raised when an error occurs during record insertion.
|
|
550
|
-
- **Message**: "Failed to insert record into table: '{}'."
|
|
551
|
-
|
|
552
|
-
- **`RecordUpdateError`**:
|
|
553
|
-
- Raised when an error occurs during record update.
|
|
554
|
-
- **Message**: "Failed to update record in table: '{}'."
|
|
555
|
-
|
|
556
|
-
- **`RecordNotFoundError`**:
|
|
557
|
-
- Raised when a record with the specified primary key is not found.
|
|
558
|
-
- **Message**: "Failed to find a record for key '{}'".
|
|
559
|
-
|
|
560
|
-
- **`RecordFetchError`**:
|
|
561
|
-
- Raised when an error occurs while fetching records from the database.
|
|
562
|
-
- **Message**: "Failed to fetch record from table: '{}'."
|
|
563
|
-
|
|
564
|
-
- **`RecordDeletionError`**:
|
|
565
|
-
- Raised when an error occurs during record deletion.
|
|
566
|
-
- **Message**: "Failed to delete record from table: '{}'."
|
|
567
|
-
|
|
568
|
-
- **`InvalidFilterError`**:
|
|
569
|
-
- Raised when an invalid filter field is used in a query.
|
|
570
|
-
- **Message**: "Failed to apply filter: invalid field '{}'".
|
|
571
|
-
|
|
572
|
-
## License
|
|
573
|
-
|
|
574
|
-
This project is licensed under the MIT License.
|
|
575
|
-
|
|
576
|
-
Copyright (c) 2024 Grant Ramsay
|
|
577
|
-
|
|
578
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
579
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
580
|
-
in the Software without restriction, including without limitation the rights
|
|
581
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
582
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
583
|
-
furnished to do so, subject to the following conditions:
|
|
584
|
-
|
|
585
|
-
The above copyright notice and this permission notice shall be included in all
|
|
586
|
-
copies or substantial portions of the Software.
|
|
587
|
-
|
|
588
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
589
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
590
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
591
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
592
|
-
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
593
|
-
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
|
594
|
-
OR OTHER DEALINGS IN THE SOFTWARE.
|
|
595
|
-
|
|
596
|
-
## Acknowledgements
|
|
597
|
-
|
|
598
|
-
SQLiter was initially developed as an experiment to see how helpful ChatGPT and
|
|
599
|
-
Claud AI can be to speed up the development process. The initial version of the
|
|
600
|
-
code was generated by ChatGPT, with subsequent manual/AI refinements and
|
|
601
|
-
improvements.
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
sqliter/__init__.py,sha256=L8R0uvCbbbACwaI5xtd3khtvpNhlPRgHJAaYZvqjzig,134
|
|
2
|
-
sqliter/constants.py,sha256=QEUC6kPkwYItgFRUmV6qfK9YV1PcUyUoBwj34yhAyik,441
|
|
3
|
-
sqliter/exceptions.py,sha256=RP1T67PkJMOgkT7yIjES1xil832_UmuAeABtNiv-RKE,3756
|
|
4
|
-
sqliter/sqliter.py,sha256=upUrUmHW6Us8AlIRB6EHDL3cEkjO-tbaRz6q1yGkxGo,8916
|
|
5
|
-
sqliter/model/__init__.py,sha256=Ovpkbyx2-T6Oee0qFNgUBBc2M0uwK-cdG0pigG3mkd8,179
|
|
6
|
-
sqliter/model/model.py,sha256=_-vJ6E38GN8Sxao-etqd6mu5Sy-zkBYsRhFVz5k_yjI,3516
|
|
7
|
-
sqliter/query/__init__.py,sha256=BluNMJpuoo2PsYN-bL7fXlEc02O_8LgOMsvCmyv04ao,125
|
|
8
|
-
sqliter/query/query.py,sha256=nsOKocZk7HZQgTckyae2RGpCPG4Y4wui7nTvqOk510Y,15851
|
|
9
|
-
sqliter_py-0.3.0.dist-info/METADATA,sha256=2uDuEiSjE_2yNgt825liES8lnh5jKW9IjcAAY01KBMc,18890
|
|
10
|
-
sqliter_py-0.3.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
11
|
-
sqliter_py-0.3.0.dist-info/licenses/LICENSE.txt,sha256=-r4mvgoEWzkl1hPO5k8I_iMwJate7zDj8p_Fmn7dhVg,1078
|
|
12
|
-
sqliter_py-0.3.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|