sqliter-py 0.2.0__tar.gz → 0.4.0__tar.gz
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_py-0.2.0 → sqliter_py-0.4.0}/.gitignore +3 -0
- sqliter_py-0.4.0/LICENSE.txt +20 -0
- sqliter_py-0.4.0/PKG-INFO +196 -0
- sqliter_py-0.4.0/README.md +168 -0
- {sqliter_py-0.2.0 → sqliter_py-0.4.0}/pyproject.toml +50 -8
- sqliter_py-0.4.0/sqliter/__init__.py +9 -0
- sqliter_py-0.4.0/sqliter/constants.py +37 -0
- {sqliter_py-0.2.0 → sqliter_py-0.4.0}/sqliter/exceptions.py +39 -12
- sqliter_py-0.4.0/sqliter/helpers.py +35 -0
- sqliter_py-0.4.0/sqliter/model/__init__.py +9 -0
- sqliter_py-0.4.0/sqliter/model/model.py +144 -0
- sqliter_py-0.4.0/sqliter/query/__init__.py +9 -0
- sqliter_py-0.4.0/sqliter/query/query.py +703 -0
- sqliter_py-0.4.0/sqliter/sqliter.py +554 -0
- sqliter_py-0.2.0/PKG-INFO +0 -351
- sqliter_py-0.2.0/README.md +0 -326
- sqliter_py-0.2.0/sqliter/__init__.py +0 -5
- sqliter_py-0.2.0/sqliter/constants.py +0 -20
- sqliter_py-0.2.0/sqliter/model/__init__.py +0 -8
- sqliter_py-0.2.0/sqliter/model/model.py +0 -38
- sqliter_py-0.2.0/sqliter/query/__init__.py +0 -5
- sqliter_py-0.2.0/sqliter/query/query.py +0 -336
- sqliter_py-0.2.0/sqliter/sqliter.py +0 -236
|
@@ -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.
|
|
@@ -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,168 @@
|
|
|
1
|
+
# SQLiter <!-- omit in toc -->
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/py/sqliter-py)
|
|
4
|
+
[](https://github.com/seapagan/sqliter-py/actions/workflows/testing.yml)
|
|
5
|
+
[](https://github.com/seapagan/sqliter-py/actions/workflows/linting.yml)
|
|
6
|
+
[](https://github.com/seapagan/sqliter-py/actions/workflows/mypy.yml)
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
SQLiter is a lightweight Object-Relational Mapping (ORM) library for SQLite
|
|
10
|
+
databases in Python. It provides a simplified interface for interacting with
|
|
11
|
+
SQLite databases using Pydantic models. The only external run-time dependency
|
|
12
|
+
is Pydantic itself.
|
|
13
|
+
|
|
14
|
+
It does not aim to be a full-fledged ORM like SQLAlchemy, but rather a simple
|
|
15
|
+
and easy-to-use library for basic database operations, especially for small
|
|
16
|
+
projects. It is NOT asynchronous and does not support complex queries (at this
|
|
17
|
+
time).
|
|
18
|
+
|
|
19
|
+
The ideal use case is more for Python CLI tools that need to store data in a
|
|
20
|
+
database-like format without needing to learn SQL or use a full ORM.
|
|
21
|
+
|
|
22
|
+
Full documentation is available on the [Documentation
|
|
23
|
+
Website](https://sqliter.grantramsay.dev)
|
|
24
|
+
|
|
25
|
+
> [!CAUTION]
|
|
26
|
+
> This project is still in the early stages of development and is lacking some
|
|
27
|
+
> planned functionality. Please use with caution.
|
|
28
|
+
>
|
|
29
|
+
> Also, structures like `list`, `dict`, `set` etc are not supported **at this
|
|
30
|
+
> time** as field types, since SQLite does not have a native column type for
|
|
31
|
+
> these. I will look at implementing these in the future, probably by
|
|
32
|
+
> serializing them to JSON or pickling them and storing in a text field. For
|
|
33
|
+
> now, you can actually do this manually when creating your Model (use `TEXT` or
|
|
34
|
+
> `BLOB` fields), then serialize before saving after and retrieving data.
|
|
35
|
+
>
|
|
36
|
+
> See the [TODO](TODO.md) for planned features and improvements.
|
|
37
|
+
|
|
38
|
+
- [Features](#features)
|
|
39
|
+
- [Installation](#installation)
|
|
40
|
+
- [Optional Dependencies](#optional-dependencies)
|
|
41
|
+
- [Quick Start](#quick-start)
|
|
42
|
+
- [Contributing](#contributing)
|
|
43
|
+
- [License](#license)
|
|
44
|
+
|
|
45
|
+
## Features
|
|
46
|
+
|
|
47
|
+
- Table creation based on Pydantic models
|
|
48
|
+
- CRUD operations (Create, Read, Update, Delete)
|
|
49
|
+
- Basic query building with filtering, ordering, and pagination
|
|
50
|
+
- Transaction support
|
|
51
|
+
- Custom exceptions for better error handling
|
|
52
|
+
- Full type hinting and type checking
|
|
53
|
+
- No external dependencies other than Pydantic
|
|
54
|
+
- Full test coverage
|
|
55
|
+
- Can optionally output the raw SQL queries being executed for debugging
|
|
56
|
+
purposes.
|
|
57
|
+
|
|
58
|
+
## Installation
|
|
59
|
+
|
|
60
|
+
You can install SQLiter using whichever method you prefer or is compatible with
|
|
61
|
+
your project setup.
|
|
62
|
+
|
|
63
|
+
With `uv` which is rapidly becoming my favorite tool for managing projects and
|
|
64
|
+
virtual environments (`uv` is used for developing this project and in the CI):
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
uv add sqliter-py
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
With `pip`:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pip install sqliter-py
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Or with `Poetry`:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
poetry add sqliter-py
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Optional Dependencies
|
|
83
|
+
|
|
84
|
+
Currently by default, the only external dependency is Pydantic. However, there
|
|
85
|
+
are some optional dependencies that can be installed to enable additional
|
|
86
|
+
features:
|
|
87
|
+
|
|
88
|
+
- `inflect`: For pluralizing table names (if not specified). This just offers a
|
|
89
|
+
more-advanced pluralization than the default method used. In most cases you
|
|
90
|
+
will not need this.
|
|
91
|
+
|
|
92
|
+
See [Installing Optional
|
|
93
|
+
Dependencies](https://sqliter.grantramsay.dev/installation#optional-dependencies)
|
|
94
|
+
for more information.
|
|
95
|
+
|
|
96
|
+
## Quick Start
|
|
97
|
+
|
|
98
|
+
Here's a quick example of how to use SQLiter:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from sqliter import SqliterDB
|
|
102
|
+
from sqliter.model import BaseDBModel
|
|
103
|
+
|
|
104
|
+
# Define your model
|
|
105
|
+
class User(BaseDBModel):
|
|
106
|
+
name: str
|
|
107
|
+
age: int
|
|
108
|
+
|
|
109
|
+
# Create a database connection
|
|
110
|
+
db = SqliterDB("example.db")
|
|
111
|
+
|
|
112
|
+
# Create the table
|
|
113
|
+
db.create_table(User)
|
|
114
|
+
|
|
115
|
+
# Insert a record
|
|
116
|
+
user = User(name="John Doe", age=30)
|
|
117
|
+
db.insert(user)
|
|
118
|
+
|
|
119
|
+
# Query records
|
|
120
|
+
results = db.select(User).filter(name="John Doe").fetch_all()
|
|
121
|
+
for user in results:
|
|
122
|
+
print(f"User: {user.name}, Age: {user.age}")
|
|
123
|
+
|
|
124
|
+
# Update a record
|
|
125
|
+
user.age = 31
|
|
126
|
+
db.update(user)
|
|
127
|
+
|
|
128
|
+
# Delete a record
|
|
129
|
+
db.delete(User, "John Doe")
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
See the [Usage](https://sqliter.grantramsay.dev/usage) section of the documentation
|
|
133
|
+
for more detailed information on how to use SQLiter, and advanced features.
|
|
134
|
+
|
|
135
|
+
## Contributing
|
|
136
|
+
|
|
137
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
138
|
+
|
|
139
|
+
See the [CONTRIBUTING](CONTRIBUTING.md) guide for more information.
|
|
140
|
+
|
|
141
|
+
Please note that this project is released with a Contributor Code of Conduct,
|
|
142
|
+
which you can read in the [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) file.
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
This project is licensed under the MIT License.
|
|
147
|
+
|
|
148
|
+
```pre
|
|
149
|
+
Copyright (c) 2024 Grant Ramsay
|
|
150
|
+
|
|
151
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
152
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
153
|
+
in the Software without restriction, including without limitation the rights
|
|
154
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
155
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
156
|
+
furnished to do so, subject to the following conditions:
|
|
157
|
+
|
|
158
|
+
The above copyright notice and this permission notice shall be included in all
|
|
159
|
+
copies or substantial portions of the Software.
|
|
160
|
+
|
|
161
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
162
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
163
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
164
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
165
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
166
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
|
167
|
+
OR OTHER DEALINGS IN THE SOFTWARE.
|
|
168
|
+
```
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
# Configuration file for the SQLiter project.
|
|
2
|
+
# This file defines project metadata, dependencies, and development tools.
|
|
3
|
+
|
|
1
4
|
[project]
|
|
2
5
|
name = "sqliter-py"
|
|
3
|
-
version = "0.
|
|
6
|
+
version = "0.4.0"
|
|
4
7
|
description = "Interact with SQLite databases using Python and Pydantic"
|
|
5
8
|
readme = "README.md"
|
|
6
9
|
requires-python = ">=3.9"
|
|
@@ -22,6 +25,9 @@ classifiers = [
|
|
|
22
25
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
23
26
|
]
|
|
24
27
|
|
|
28
|
+
[project.optional-dependencies]
|
|
29
|
+
extras = ["inflect==7.0.0"]
|
|
30
|
+
|
|
25
31
|
[project.urls]
|
|
26
32
|
# "HomeHage" = "https://xxxxxx"
|
|
27
33
|
"Pull Requests" = "https://github.com/seapagan/sqliter-py/pulls"
|
|
@@ -54,22 +60,42 @@ dev-dependencies = [
|
|
|
54
60
|
"pytest-clarity>=1.0.1",
|
|
55
61
|
"poethepoet>=0.28.0",
|
|
56
62
|
"github-changelog-md>=0.9.5",
|
|
63
|
+
"pre-commit>=3.8.0",
|
|
64
|
+
"mkdocs>=1.6.1",
|
|
65
|
+
"mkdocs-material>=9.5.36",
|
|
66
|
+
"pygments>=2.18.0",
|
|
67
|
+
"mkdocs-minify-plugin>=0.8.0",
|
|
68
|
+
"mdx-truly-sane-lists>=1.3",
|
|
57
69
|
]
|
|
58
70
|
|
|
59
71
|
[tool.poe.tasks]
|
|
72
|
+
pre.cmd = "pre-commit run --all-files"
|
|
73
|
+
pre.help = "Run pre-commit checks"
|
|
74
|
+
|
|
60
75
|
mypy.cmd = "mypy . --strict"
|
|
61
76
|
mypy.help = "Run mypy checks"
|
|
62
|
-
format.help = "Format code with Ruff"
|
|
63
77
|
format.cmd = "ruff format ."
|
|
78
|
+
format.help = "Format code with Ruff"
|
|
79
|
+
ruff.cmd = "ruff check --output-format=concise ."
|
|
64
80
|
ruff.help = "Run Ruff checks"
|
|
65
|
-
|
|
66
|
-
test.help = "Run tests using Pytest"
|
|
81
|
+
|
|
67
82
|
test.cmd = "pytest"
|
|
83
|
+
test.help = "Run tests using Pytest"
|
|
68
84
|
"test:watch".cmd = "ptw . --now --clear"
|
|
69
85
|
"test:watch".help = "Run tests using Pytest in watch mode"
|
|
86
|
+
|
|
70
87
|
changelog.cmd = "github-changelog-md"
|
|
71
88
|
changelog.help = "Generate a changelog"
|
|
72
89
|
|
|
90
|
+
"docs:publish".cmd = "mkdocs gh-deploy"
|
|
91
|
+
"docs:publish".help = "Publish documentation to GitHub Pages"
|
|
92
|
+
"docs:build".cmd = "mkdocs build"
|
|
93
|
+
"docs:build".help = "Build documentation locally to './site' folder"
|
|
94
|
+
"docs:serve".cmd = "mkdocs serve -w TODO.md -w CHANGELOG.md -w CONTRIBUTING.md"
|
|
95
|
+
"docs:serve".help = "Serve documentation locally"
|
|
96
|
+
"docs:serve:all".cmd = "mkdocs serve -w TODO.md -w CHANGELOG.md -w CONTRIBUTING.md -a 0.0.0.0:9000"
|
|
97
|
+
"docs:serve:all".help = "Serve documentation locally on all interfaces"
|
|
98
|
+
|
|
73
99
|
[tool.ruff]
|
|
74
100
|
line-length = 80
|
|
75
101
|
lint.select = ["ALL"] # we are being very strict!
|
|
@@ -86,13 +112,16 @@ lint.extend-ignore = [
|
|
|
86
112
|
"ISC001",
|
|
87
113
|
] # these are ignored for ruff formatting
|
|
88
114
|
|
|
89
|
-
src = ["
|
|
115
|
+
src = ["sqliter"]
|
|
90
116
|
target-version = "py39" # minimum python version supported
|
|
91
117
|
|
|
92
118
|
[tool.ruff.format]
|
|
93
119
|
indent-style = "space"
|
|
94
120
|
quote-style = "double"
|
|
95
121
|
|
|
122
|
+
[tool.ruff.lint.pylint]
|
|
123
|
+
max-args = 6
|
|
124
|
+
|
|
96
125
|
[tool.ruff.lint.pep8-naming]
|
|
97
126
|
classmethod-decorators = ["pydantic.validator", "pydantic.root_validator"]
|
|
98
127
|
|
|
@@ -105,25 +134,38 @@ convention = "google"
|
|
|
105
134
|
"ANN001", # annotations for fixtures are sometimes a pain for test files
|
|
106
135
|
"ARG00", # test fixtures often are not directly used
|
|
107
136
|
"PLR2004", # magic numbers are often used in test files
|
|
137
|
+
"SLF001", # sometimes we need to test private methods
|
|
108
138
|
]
|
|
109
139
|
|
|
110
140
|
[tool.ruff.lint.isort]
|
|
111
|
-
known-first-party = ["
|
|
141
|
+
known-first-party = ["sqliter"]
|
|
112
142
|
|
|
113
143
|
[tool.ruff.lint.pyupgrade]
|
|
114
144
|
keep-runtime-typing = true
|
|
115
145
|
|
|
116
146
|
[tool.mypy]
|
|
117
147
|
python_version = "3.9"
|
|
148
|
+
exclude = ["docs"]
|
|
118
149
|
|
|
119
150
|
[[tool.mypy.overrides]]
|
|
120
151
|
disable_error_code = ["method-assign", "no-untyped-def", "attr-defined"]
|
|
121
152
|
module = "tests.*"
|
|
122
153
|
|
|
123
154
|
[tool.pytest.ini_options]
|
|
124
|
-
addopts = [
|
|
125
|
-
|
|
155
|
+
addopts = [
|
|
156
|
+
"--cov",
|
|
157
|
+
"--cov-report",
|
|
158
|
+
"term-missing",
|
|
159
|
+
"--cov-report",
|
|
160
|
+
"html",
|
|
161
|
+
"--cov-report",
|
|
162
|
+
"lcov",
|
|
163
|
+
]
|
|
164
|
+
filterwarnings = [
|
|
165
|
+
"ignore:'direction' argument is deprecated:DeprecationWarning",
|
|
166
|
+
]
|
|
126
167
|
mock_use_standalone_module = true
|
|
168
|
+
markers = []
|
|
127
169
|
|
|
128
170
|
[tool.coverage.run]
|
|
129
171
|
source = ["sqliter"]
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Constant values and mappings used throughout SQLiter.
|
|
2
|
+
|
|
3
|
+
This module defines constant dictionaries that map SQLiter-specific
|
|
4
|
+
concepts to their SQLite equivalents. It includes mappings for query
|
|
5
|
+
operators and data types, which are crucial for translating between
|
|
6
|
+
Pydantic models and SQLite database operations.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
# A dictionary mapping SQLiter filter operators to their corresponding SQL
|
|
10
|
+
# operators.
|
|
11
|
+
OPERATOR_MAPPING = {
|
|
12
|
+
"__lt": "<",
|
|
13
|
+
"__lte": "<=",
|
|
14
|
+
"__gt": ">",
|
|
15
|
+
"__gte": ">=",
|
|
16
|
+
"__eq": "=",
|
|
17
|
+
"__ne": "!=",
|
|
18
|
+
"__in": "IN",
|
|
19
|
+
"__not_in": "NOT IN",
|
|
20
|
+
"__isnull": "IS NULL",
|
|
21
|
+
"__notnull": "IS NOT NULL",
|
|
22
|
+
"__startswith": "LIKE",
|
|
23
|
+
"__endswith": "LIKE",
|
|
24
|
+
"__contains": "LIKE",
|
|
25
|
+
"__istartswith": "LIKE",
|
|
26
|
+
"__iendswith": "LIKE",
|
|
27
|
+
"__icontains": "LIKE",
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
# A dictionary mapping Python types to their corresponding SQLite column types.
|
|
31
|
+
SQLITE_TYPE_MAPPING = {
|
|
32
|
+
int: "INTEGER",
|
|
33
|
+
float: "REAL",
|
|
34
|
+
str: "TEXT",
|
|
35
|
+
bool: "INTEGER", # SQLite stores booleans as integers (0 or 1)
|
|
36
|
+
bytes: "BLOB",
|
|
37
|
+
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Custom exception classes for SQLiter error handling.
|
|
2
|
+
|
|
3
|
+
This module defines a hierarchy of exception classes specific to
|
|
4
|
+
SQLiter operations. These exceptions provide detailed error information
|
|
5
|
+
for various scenarios such as connection issues, invalid queries,
|
|
6
|
+
and CRUD operation failures, enabling more precise error handling
|
|
7
|
+
in applications using SQLiter.
|
|
8
|
+
"""
|
|
2
9
|
|
|
3
10
|
import os
|
|
4
11
|
import sys
|
|
@@ -6,7 +13,15 @@ import traceback
|
|
|
6
13
|
|
|
7
14
|
|
|
8
15
|
class SqliterError(Exception):
|
|
9
|
-
"""Base class for all
|
|
16
|
+
"""Base exception class for all SQLiter-specific errors.
|
|
17
|
+
|
|
18
|
+
This class serves as the parent for all custom exceptions in SQLiter,
|
|
19
|
+
providing a consistent interface and message formatting.
|
|
20
|
+
|
|
21
|
+
Attributes:
|
|
22
|
+
message_template (str): A template string for the error message.
|
|
23
|
+
original_exception (Exception): The original exception that was caught.
|
|
24
|
+
"""
|
|
10
25
|
|
|
11
26
|
message_template: str = "An error occurred in the SQLiter package."
|
|
12
27
|
|
|
@@ -59,13 +74,13 @@ class SqliterError(Exception):
|
|
|
59
74
|
|
|
60
75
|
|
|
61
76
|
class DatabaseConnectionError(SqliterError):
|
|
62
|
-
"""
|
|
77
|
+
"""Exception raised when a database connection cannot be established."""
|
|
63
78
|
|
|
64
79
|
message_template = "Failed to connect to the database: '{}'"
|
|
65
80
|
|
|
66
81
|
|
|
67
82
|
class InvalidOffsetError(SqliterError):
|
|
68
|
-
"""
|
|
83
|
+
"""Exception raised when an invalid offset value is provided."""
|
|
69
84
|
|
|
70
85
|
message_template = (
|
|
71
86
|
"Invalid offset value: '{}'. Offset must be a positive integer."
|
|
@@ -73,48 +88,60 @@ class InvalidOffsetError(SqliterError):
|
|
|
73
88
|
|
|
74
89
|
|
|
75
90
|
class InvalidOrderError(SqliterError):
|
|
76
|
-
"""
|
|
91
|
+
"""Exception raised when an invalid order specification is provided."""
|
|
77
92
|
|
|
78
93
|
message_template = "Invalid order value - {}"
|
|
79
94
|
|
|
80
95
|
|
|
81
96
|
class TableCreationError(SqliterError):
|
|
82
|
-
"""
|
|
97
|
+
"""Exception raised when a table cannot be created in the database."""
|
|
83
98
|
|
|
84
99
|
message_template = "Failed to create the table: '{}'"
|
|
85
100
|
|
|
86
101
|
|
|
87
102
|
class RecordInsertionError(SqliterError):
|
|
88
|
-
"""
|
|
103
|
+
"""Exception raised when a record cannot be inserted into the database."""
|
|
89
104
|
|
|
90
105
|
message_template = "Failed to insert record into table: '{}'"
|
|
91
106
|
|
|
92
107
|
|
|
93
108
|
class RecordUpdateError(SqliterError):
|
|
94
|
-
"""
|
|
109
|
+
"""Exception raised when a record cannot be updated in the database."""
|
|
95
110
|
|
|
96
111
|
message_template = "Failed to update record in table: '{}'"
|
|
97
112
|
|
|
98
113
|
|
|
99
114
|
class RecordNotFoundError(SqliterError):
|
|
100
|
-
"""
|
|
115
|
+
"""Exception raised when a requested record is not found in the database."""
|
|
101
116
|
|
|
102
117
|
message_template = "Failed to find a record for key '{}' "
|
|
103
118
|
|
|
104
119
|
|
|
105
120
|
class RecordFetchError(SqliterError):
|
|
106
|
-
"""
|
|
121
|
+
"""Exception raised on an error fetching records from the database."""
|
|
107
122
|
|
|
108
123
|
message_template = "Failed to fetch record from table: '{}'"
|
|
109
124
|
|
|
110
125
|
|
|
111
126
|
class RecordDeletionError(SqliterError):
|
|
112
|
-
"""
|
|
127
|
+
"""Exception raised when a record cannot be deleted from the database."""
|
|
113
128
|
|
|
114
129
|
message_template = "Failed to delete record from table: '{}'"
|
|
115
130
|
|
|
116
131
|
|
|
117
132
|
class InvalidFilterError(SqliterError):
|
|
118
|
-
"""
|
|
133
|
+
"""Exception raised when an invalid filter is applied to a query."""
|
|
119
134
|
|
|
120
135
|
message_template = "Failed to apply filter: invalid field '{}'"
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
class TableDeletionError(SqliterError):
|
|
139
|
+
"""Raised when a table cannot be deleted from the database."""
|
|
140
|
+
|
|
141
|
+
message_template = "Failed to delete the table: '{}'"
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
class SqlExecutionError(SqliterError):
|
|
145
|
+
"""Raised when an SQL execution fails."""
|
|
146
|
+
|
|
147
|
+
message_template = "Failed to execute SQL: '{}'"
|