sqliter-py 0.2.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 +119 -13
- sqliter/query/__init__.py +5 -1
- sqliter/query/query.py +444 -77
- sqliter/sqliter.py +360 -42
- sqliter_py-0.4.0.dist-info/METADATA +196 -0
- sqliter_py-0.4.0.dist-info/RECORD +13 -0
- sqliter_py-0.4.0.dist-info/licenses/LICENSE.txt +20 -0
- sqliter_py-0.2.0.dist-info/METADATA +0 -351
- sqliter_py-0.2.0.dist-info/RECORD +0 -11
- {sqliter_py-0.2.0.dist-info → sqliter_py-0.4.0.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: sqliter-py
|
|
3
|
+
Version: 0.4.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
|
+
[](https://badge.fury.io/py/sqliter-py)
|
|
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
|
+
Full documentation is available on the [Documentation
|
|
51
|
+
Website](https://sqliter.grantramsay.dev)
|
|
52
|
+
|
|
53
|
+
> [!CAUTION]
|
|
54
|
+
> This project is still in the early stages of development and is lacking some
|
|
55
|
+
> planned functionality. Please use with caution.
|
|
56
|
+
>
|
|
57
|
+
> Also, structures like `list`, `dict`, `set` etc are not supported **at this
|
|
58
|
+
> time** as field types, since SQLite does not have a native column type for
|
|
59
|
+
> these. I will look at implementing these in the future, probably by
|
|
60
|
+
> serializing them to JSON or pickling them and storing in a text field. For
|
|
61
|
+
> now, you can actually do this manually when creating your Model (use `TEXT` or
|
|
62
|
+
> `BLOB` fields), then serialize before saving after and retrieving data.
|
|
63
|
+
>
|
|
64
|
+
> See the [TODO](TODO.md) for planned features and improvements.
|
|
65
|
+
|
|
66
|
+
- [Features](#features)
|
|
67
|
+
- [Installation](#installation)
|
|
68
|
+
- [Optional Dependencies](#optional-dependencies)
|
|
69
|
+
- [Quick Start](#quick-start)
|
|
70
|
+
- [Contributing](#contributing)
|
|
71
|
+
- [License](#license)
|
|
72
|
+
|
|
73
|
+
## Features
|
|
74
|
+
|
|
75
|
+
- Table creation based on Pydantic models
|
|
76
|
+
- CRUD operations (Create, Read, Update, Delete)
|
|
77
|
+
- Basic query building with filtering, ordering, and pagination
|
|
78
|
+
- Transaction support
|
|
79
|
+
- Custom exceptions for better error handling
|
|
80
|
+
- Full type hinting and type checking
|
|
81
|
+
- No external dependencies other than Pydantic
|
|
82
|
+
- Full test coverage
|
|
83
|
+
- Can optionally output the raw SQL queries being executed for debugging
|
|
84
|
+
purposes.
|
|
85
|
+
|
|
86
|
+
## Installation
|
|
87
|
+
|
|
88
|
+
You can install SQLiter using whichever method you prefer or is compatible with
|
|
89
|
+
your project setup.
|
|
90
|
+
|
|
91
|
+
With `uv` which is rapidly becoming my favorite tool for managing projects and
|
|
92
|
+
virtual environments (`uv` is used for developing this project and in the CI):
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
uv add sqliter-py
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
With `pip`:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
pip install sqliter-py
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Or with `Poetry`:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
poetry add sqliter-py
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Optional Dependencies
|
|
111
|
+
|
|
112
|
+
Currently by default, the only external dependency is Pydantic. However, there
|
|
113
|
+
are some optional dependencies that can be installed to enable additional
|
|
114
|
+
features:
|
|
115
|
+
|
|
116
|
+
- `inflect`: For pluralizing table names (if not specified). This just offers a
|
|
117
|
+
more-advanced pluralization than the default method used. In most cases you
|
|
118
|
+
will not need this.
|
|
119
|
+
|
|
120
|
+
See [Installing Optional
|
|
121
|
+
Dependencies](https://sqliter.grantramsay.dev/installation#optional-dependencies)
|
|
122
|
+
for more information.
|
|
123
|
+
|
|
124
|
+
## Quick Start
|
|
125
|
+
|
|
126
|
+
Here's a quick example of how to use SQLiter:
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
from sqliter import SqliterDB
|
|
130
|
+
from sqliter.model import BaseDBModel
|
|
131
|
+
|
|
132
|
+
# Define your model
|
|
133
|
+
class User(BaseDBModel):
|
|
134
|
+
name: str
|
|
135
|
+
age: int
|
|
136
|
+
|
|
137
|
+
# Create a database connection
|
|
138
|
+
db = SqliterDB("example.db")
|
|
139
|
+
|
|
140
|
+
# Create the table
|
|
141
|
+
db.create_table(User)
|
|
142
|
+
|
|
143
|
+
# Insert a record
|
|
144
|
+
user = User(name="John Doe", age=30)
|
|
145
|
+
db.insert(user)
|
|
146
|
+
|
|
147
|
+
# Query records
|
|
148
|
+
results = db.select(User).filter(name="John Doe").fetch_all()
|
|
149
|
+
for user in results:
|
|
150
|
+
print(f"User: {user.name}, Age: {user.age}")
|
|
151
|
+
|
|
152
|
+
# Update a record
|
|
153
|
+
user.age = 31
|
|
154
|
+
db.update(user)
|
|
155
|
+
|
|
156
|
+
# Delete a record
|
|
157
|
+
db.delete(User, "John Doe")
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
See the [Usage](https://sqliter.grantramsay.dev/usage) section of the documentation
|
|
161
|
+
for more detailed information on how to use SQLiter, and advanced features.
|
|
162
|
+
|
|
163
|
+
## Contributing
|
|
164
|
+
|
|
165
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
166
|
+
|
|
167
|
+
See the [CONTRIBUTING](CONTRIBUTING.md) guide for more information.
|
|
168
|
+
|
|
169
|
+
Please note that this project is released with a Contributor Code of Conduct,
|
|
170
|
+
which you can read in the [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) file.
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
This project is licensed under the MIT License.
|
|
175
|
+
|
|
176
|
+
```pre
|
|
177
|
+
Copyright (c) 2024 Grant Ramsay
|
|
178
|
+
|
|
179
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
180
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
181
|
+
in the Software without restriction, including without limitation the rights
|
|
182
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
183
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
184
|
+
furnished to do so, subject to the following conditions:
|
|
185
|
+
|
|
186
|
+
The above copyright notice and this permission notice shall be included in all
|
|
187
|
+
copies or substantial portions of the Software.
|
|
188
|
+
|
|
189
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
190
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
191
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
192
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
193
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
194
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
|
195
|
+
OR OTHER DEALINGS IN THE SOFTWARE.
|
|
196
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
sqliter/__init__.py,sha256=ECfn02OPmiMCQvRYbfizKFhVDk00xV-HV1s2cH9037I,244
|
|
2
|
+
sqliter/constants.py,sha256=j0lE2cB1Uj8cNo40GGtCPdOR5asm-dHRDmGG0oyindA,1050
|
|
3
|
+
sqliter/exceptions.py,sha256=56yDixGEkfC-OHPG-8t067xzJhspXXoxQWFU5jkU-1M,4794
|
|
4
|
+
sqliter/helpers.py,sha256=75r4zMmGztVPm9_Bz3L1cSvBdx17uPEAnaggVhD70Pg,1138
|
|
5
|
+
sqliter/sqliter.py,sha256=n3EtU0Lj9tJaIZicapz1l6L5ofpcpmozmQ7O3QQ977A,18741
|
|
6
|
+
sqliter/model/__init__.py,sha256=GgULmKRn0Dq0Jz6LbHGPndS6GP3vd1uxI1KrEevofLs,237
|
|
7
|
+
sqliter/model/model.py,sha256=rzmYEpv28fXnLV9yuApjHyUj7bL4lkHWUzv8GXkk3kQ,4901
|
|
8
|
+
sqliter/query/__init__.py,sha256=MRajhjTPJqjbmmrwndVKj8vqMbK5-XufpwoIswQf5z4,239
|
|
9
|
+
sqliter/query/query.py,sha256=iUJ1jdp1vWp5n77by2LKjxdl0-SWEA7T01Uk2_gHvZ8,23547
|
|
10
|
+
sqliter_py-0.4.0.dist-info/METADATA,sha256=fmkuZ-W_ZBN7ycWuxnnxZ6FPcMe1DYRtdIBatG9otrI,7102
|
|
11
|
+
sqliter_py-0.4.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
12
|
+
sqliter_py-0.4.0.dist-info/licenses/LICENSE.txt,sha256=-r4mvgoEWzkl1hPO5k8I_iMwJate7zDj8p_Fmn7dhVg,1078
|
|
13
|
+
sqliter_py-0.4.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
Copyright (c) 2024 Grant Ramsay
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
18
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
19
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
|
20
|
+
OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.3
|
|
2
|
-
Name: sqliter-py
|
|
3
|
-
Version: 0.2.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
|
-
Classifier: Development Status :: 4 - Beta
|
|
12
|
-
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
-
Classifier: Operating System :: OS Independent
|
|
15
|
-
Classifier: Programming Language :: Python :: 3
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
-
Classifier: Topic :: Software Development
|
|
21
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
-
Requires-Python: >=3.9
|
|
23
|
-
Requires-Dist: pydantic>=2.9.0
|
|
24
|
-
Description-Content-Type: text/markdown
|
|
25
|
-
|
|
26
|
-
# SQLiter <!-- omit in toc -->
|
|
27
|
-
|
|
28
|
-

|
|
29
|
-
[](https://github.com/seapagan/sqliter-py/actions/workflows/testing.yml)
|
|
30
|
-
[](https://github.com/seapagan/sqliter-py/actions/workflows/linting.yml)
|
|
31
|
-
[](https://github.com/seapagan/sqliter-py/actions/workflows/mypy.yml)
|
|
32
|
-

|
|
33
|
-
|
|
34
|
-
SQLiter is a lightweight Object-Relational Mapping (ORM) library for SQLite
|
|
35
|
-
databases in Python. It provides a simplified interface for interacting with
|
|
36
|
-
SQLite databases using Pydantic models. The only external run-time dependency
|
|
37
|
-
is Pydantic itself.
|
|
38
|
-
|
|
39
|
-
It does not aim to be a full-fledged ORM like SQLAlchemy, but rather a simple
|
|
40
|
-
and easy-to-use library for basic database operations, especially for small
|
|
41
|
-
projects. It is NOT asynchronous and does not support complex queries (at this
|
|
42
|
-
time).
|
|
43
|
-
|
|
44
|
-
The ideal use case is more for Python CLI tools that need to store data in a
|
|
45
|
-
database-like format without needing to learn SQL or use a full ORM.
|
|
46
|
-
|
|
47
|
-
> [!NOTE]
|
|
48
|
-
> This project is still in the early stages of development and is lacking some
|
|
49
|
-
> planned functionality. Please use with caution.
|
|
50
|
-
>
|
|
51
|
-
> See the [TODO](TODO.md) for planned features and improvements.
|
|
52
|
-
|
|
53
|
-
- [Features](#features)
|
|
54
|
-
- [Installation](#installation)
|
|
55
|
-
- [Quick Start](#quick-start)
|
|
56
|
-
- [Detailed Usage](#detailed-usage)
|
|
57
|
-
- [Defining Models](#defining-models)
|
|
58
|
-
- [Database Operations](#database-operations)
|
|
59
|
-
- [Creating a Connection](#creating-a-connection)
|
|
60
|
-
- [Creating Tables](#creating-tables)
|
|
61
|
-
- [Inserting Records](#inserting-records)
|
|
62
|
-
- [Querying Records](#querying-records)
|
|
63
|
-
- [Updating Records](#updating-records)
|
|
64
|
-
- [Deleting Records](#deleting-records)
|
|
65
|
-
- [Commit your changes](#commit-your-changes)
|
|
66
|
-
- [Close the Connection](#close-the-connection)
|
|
67
|
-
- [Transactions](#transactions)
|
|
68
|
-
- [Filter Options](#filter-options)
|
|
69
|
-
- [Basic Filters](#basic-filters)
|
|
70
|
-
- [Null Checks](#null-checks)
|
|
71
|
-
- [Comparison Operators](#comparison-operators)
|
|
72
|
-
- [List Operations](#list-operations)
|
|
73
|
-
- [String Operations (Case-Sensitive)](#string-operations-case-sensitive)
|
|
74
|
-
- [String Operations (Case-Insensitive)](#string-operations-case-insensitive)
|
|
75
|
-
- [Contributing](#contributing)
|
|
76
|
-
- [License](#license)
|
|
77
|
-
- [Acknowledgements](#acknowledgements)
|
|
78
|
-
|
|
79
|
-
## Features
|
|
80
|
-
|
|
81
|
-
- Table creation based on Pydantic models
|
|
82
|
-
- CRUD operations (Create, Read, Update, Delete)
|
|
83
|
-
- Basic query building with filtering, ordering, and pagination
|
|
84
|
-
- Transaction support
|
|
85
|
-
- Custom exceptions for better error handling
|
|
86
|
-
|
|
87
|
-
## Installation
|
|
88
|
-
|
|
89
|
-
You can install SQLiter using whichever method you prefer or is compatible with
|
|
90
|
-
your project setup.
|
|
91
|
-
|
|
92
|
-
With `pip`:
|
|
93
|
-
|
|
94
|
-
```bash
|
|
95
|
-
pip install sqliter-py
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
Or `Poetry`:
|
|
99
|
-
|
|
100
|
-
```bash
|
|
101
|
-
poetry add sqliter-py
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
Or `uv` which is rapidly becoming my favorite tool for managing projects and
|
|
105
|
-
virtual environments (`uv` is used for developing this project and in the CI):
|
|
106
|
-
|
|
107
|
-
```bash
|
|
108
|
-
uv add sqliter-py
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
## Quick Start
|
|
112
|
-
|
|
113
|
-
Here's a quick example of how to use SQLiter:
|
|
114
|
-
|
|
115
|
-
```python
|
|
116
|
-
from sqliter import SqliterDB
|
|
117
|
-
from sqliter.model import BaseDBModel
|
|
118
|
-
|
|
119
|
-
# Define your model
|
|
120
|
-
class User(BaseDBModel):
|
|
121
|
-
name: str
|
|
122
|
-
age: int
|
|
123
|
-
|
|
124
|
-
class Meta:
|
|
125
|
-
table_name = "users"
|
|
126
|
-
|
|
127
|
-
# Create a database connection
|
|
128
|
-
db = SqliterDB("example.db")
|
|
129
|
-
|
|
130
|
-
# Create the table
|
|
131
|
-
db.create_table(User)
|
|
132
|
-
|
|
133
|
-
# Insert a record
|
|
134
|
-
user = User(name="John Doe", age=30)
|
|
135
|
-
db.insert(user)
|
|
136
|
-
|
|
137
|
-
# Query records
|
|
138
|
-
results = db.select(User).filter(name="John Doe").fetch_all()
|
|
139
|
-
for user in results:
|
|
140
|
-
print(f"User: {user.name}, Age: {user.age}")
|
|
141
|
-
|
|
142
|
-
# Update a record
|
|
143
|
-
user.age = 31
|
|
144
|
-
db.update(user)
|
|
145
|
-
|
|
146
|
-
# Delete a record
|
|
147
|
-
db.delete(User, "John Doe")
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
## Detailed Usage
|
|
151
|
-
|
|
152
|
-
### Defining Models
|
|
153
|
-
|
|
154
|
-
Models in SQLiter are based on Pydantic's `BaseModel`. You can define your
|
|
155
|
-
models like this:
|
|
156
|
-
|
|
157
|
-
```python
|
|
158
|
-
from sqliter.model import BaseDBModel
|
|
159
|
-
|
|
160
|
-
class User(BaseDBModel):
|
|
161
|
-
name: str
|
|
162
|
-
age: int
|
|
163
|
-
email: str
|
|
164
|
-
|
|
165
|
-
class Meta:
|
|
166
|
-
table_name = "users"
|
|
167
|
-
primary_key = "name" # Default is "id"
|
|
168
|
-
create_id = False # Set to True to auto-create an ID field
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
### Database Operations
|
|
172
|
-
|
|
173
|
-
#### Creating a Connection
|
|
174
|
-
|
|
175
|
-
```python
|
|
176
|
-
from sqliter import SqliterDB
|
|
177
|
-
|
|
178
|
-
db = SqliterDB("your_database.db")
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
The default behavior is to automatically commit changes to the database after
|
|
182
|
-
each operation. If you want to disable this behavior, you can set `auto_commit=False`
|
|
183
|
-
when creating the database connection:
|
|
184
|
-
|
|
185
|
-
```python
|
|
186
|
-
db = SqliterDB("your_database.db", auto_commit=False)
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
It is then up to you to manually commit changes using the `commit()` method.
|
|
190
|
-
This can be useful when you want to perform multiple operations in a single
|
|
191
|
-
transaction without the overhead of committing after each operation.
|
|
192
|
-
|
|
193
|
-
#### Creating Tables
|
|
194
|
-
|
|
195
|
-
```python
|
|
196
|
-
db.create_table(User)
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
#### Inserting Records
|
|
200
|
-
|
|
201
|
-
```python
|
|
202
|
-
user = User(name="Jane Doe", age=25, email="jane@example.com")
|
|
203
|
-
db.insert(user)
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
#### Querying Records
|
|
207
|
-
|
|
208
|
-
```python
|
|
209
|
-
# Fetch all users
|
|
210
|
-
all_users = db.select(User).fetch_all()
|
|
211
|
-
|
|
212
|
-
# Filter users
|
|
213
|
-
young_users = db.select(User).filter(age=25).fetch_all()
|
|
214
|
-
|
|
215
|
-
# Order users
|
|
216
|
-
ordered_users = db.select(User).order("age", direction="DESC").fetch_all()
|
|
217
|
-
|
|
218
|
-
# Limit and offset
|
|
219
|
-
paginated_users = db.select(User).limit(10).offset(20).fetch_all()
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
See below for more advanced filtering options.
|
|
223
|
-
|
|
224
|
-
#### Updating Records
|
|
225
|
-
|
|
226
|
-
```python
|
|
227
|
-
user.age = 26
|
|
228
|
-
db.update(user)
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
#### Deleting Records
|
|
232
|
-
|
|
233
|
-
```python
|
|
234
|
-
db.delete(User, "Jane Doe")
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
#### Commit your changes
|
|
238
|
-
|
|
239
|
-
By default, SQLiter will automatically commit changes to the database after each
|
|
240
|
-
operation. If you want to disable this behavior, you can set `auto_commit=False`
|
|
241
|
-
when creating the database connection:
|
|
242
|
-
|
|
243
|
-
```python
|
|
244
|
-
db = SqliterDB("your_database.db", auto_commit=False)
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
You can then manually commit changes using the `commit()` method:
|
|
248
|
-
|
|
249
|
-
```python
|
|
250
|
-
db.commit()
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
#### Close the Connection
|
|
254
|
-
|
|
255
|
-
When you're done with the database connection, you should close it to release
|
|
256
|
-
resources:
|
|
257
|
-
|
|
258
|
-
```python
|
|
259
|
-
db.close()
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
Note that closing the connection will also commit any pending changes, unless
|
|
263
|
-
`auto_commit` is set to `False`.
|
|
264
|
-
|
|
265
|
-
### Transactions
|
|
266
|
-
|
|
267
|
-
SQLiter supports transactions using Python's context manager:
|
|
268
|
-
|
|
269
|
-
```python
|
|
270
|
-
with db:
|
|
271
|
-
db.insert(User(name="Alice", age=30, email="alice@example.com"))
|
|
272
|
-
db.insert(User(name="Bob", age=35, email="bob@example.com"))
|
|
273
|
-
# If an exception occurs, the transaction will be rolled back
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
> [!WARNING]
|
|
277
|
-
> Using the context manager will automatically commit the transaction
|
|
278
|
-
> at the end (unless an exception occurs), regardless of the `auto_commit`
|
|
279
|
-
> setting.
|
|
280
|
-
>
|
|
281
|
-
> the 'close()' method will also be called when the context manager exits, so you
|
|
282
|
-
> do not need to call it manually.
|
|
283
|
-
|
|
284
|
-
### Filter Options
|
|
285
|
-
|
|
286
|
-
The `filter()` method in SQLiter supports various filter options to query records.
|
|
287
|
-
|
|
288
|
-
#### Basic Filters
|
|
289
|
-
|
|
290
|
-
- `__eq`: Equal to (default if no operator is specified)
|
|
291
|
-
- Example: `name="John"` or `name__eq="John"`
|
|
292
|
-
|
|
293
|
-
#### Null Checks
|
|
294
|
-
|
|
295
|
-
- `__isnull`: Is NULL
|
|
296
|
-
- Example: `email__isnull=True`
|
|
297
|
-
- `__notnull`: Is NOT NULL
|
|
298
|
-
- Example: `email__notnull=True`
|
|
299
|
-
|
|
300
|
-
#### Comparison Operators
|
|
301
|
-
|
|
302
|
-
- `__lt`: Less than
|
|
303
|
-
- Example: `age__lt=30`
|
|
304
|
-
- `__lte`: Less than or equal to
|
|
305
|
-
- Example: `age__lte=30`
|
|
306
|
-
- `__gt`: Greater than
|
|
307
|
-
- Example: `age__gt=30`
|
|
308
|
-
- `__gte`: Greater than or equal to
|
|
309
|
-
- Example: `age__gte=30`
|
|
310
|
-
- `__ne`: Not equal to
|
|
311
|
-
- Example: `status__ne="inactive"`
|
|
312
|
-
|
|
313
|
-
#### List Operations
|
|
314
|
-
|
|
315
|
-
- `__in`: In a list of values
|
|
316
|
-
- Example: `status__in=["active", "pending"]`
|
|
317
|
-
- `__not_in`: Not in a list of values
|
|
318
|
-
- Example: `category__not_in=["archived", "deleted"]`
|
|
319
|
-
|
|
320
|
-
#### String Operations (Case-Sensitive)
|
|
321
|
-
|
|
322
|
-
- `__startswith`: Starts with
|
|
323
|
-
- Example: `name__startswith="A"`
|
|
324
|
-
- `__endswith`: Ends with
|
|
325
|
-
- Example: `email__endswith=".com"`
|
|
326
|
-
- `__contains`: Contains
|
|
327
|
-
- Example: `description__contains="important"`
|
|
328
|
-
|
|
329
|
-
#### String Operations (Case-Insensitive)
|
|
330
|
-
|
|
331
|
-
- `__istartswith`: Starts with (case-insensitive)
|
|
332
|
-
- Example: `name__istartswith="a"`
|
|
333
|
-
- `__iendswith`: Ends with (case-insensitive)
|
|
334
|
-
- Example: `email__iendswith=".COM"`
|
|
335
|
-
- `__icontains`: Contains (case-insensitive)
|
|
336
|
-
- Example: `description__icontains="IMPORTANT"`
|
|
337
|
-
|
|
338
|
-
## Contributing
|
|
339
|
-
|
|
340
|
-
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
341
|
-
|
|
342
|
-
## License
|
|
343
|
-
|
|
344
|
-
This project is licensed under the MIT License.
|
|
345
|
-
|
|
346
|
-
## Acknowledgements
|
|
347
|
-
|
|
348
|
-
SQLiter was initially developed as an experiment to see how helpful ChatGPT and
|
|
349
|
-
Claud AI can be to speed up the development process. The initial version of the
|
|
350
|
-
code was generated by ChatGPT, with subsequent manual/AI refinements and
|
|
351
|
-
improvements.
|
|
@@ -1,11 +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=1MOa763OQdwkiAHHAitEKox5O9EV0FVMbMWC7pqyk9U,7823
|
|
5
|
-
sqliter/model/__init__.py,sha256=Ovpkbyx2-T6Oee0qFNgUBBc2M0uwK-cdG0pigG3mkd8,179
|
|
6
|
-
sqliter/model/model.py,sha256=t1w38om37gma1gRk01Z_9II0h4g-l734ijN_8M1SYoY,1247
|
|
7
|
-
sqliter/query/__init__.py,sha256=BluNMJpuoo2PsYN-bL7fXlEc02O_8LgOMsvCmyv04ao,125
|
|
8
|
-
sqliter/query/query.py,sha256=dRW-Y7X3qH4HrTw-oFbomnl4Kz7WOsImIfoKXZqkMKQ,11648
|
|
9
|
-
sqliter_py-0.2.0.dist-info/METADATA,sha256=OBYavQg-H3HipYh_mVkaJ4cL_EUpzqPk1MtypWUpwlg,9880
|
|
10
|
-
sqliter_py-0.2.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
11
|
-
sqliter_py-0.2.0.dist-info/RECORD,,
|
|
File without changes
|