sqliter-py 0.9.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.
- sqliter_py-0.9.0/PKG-INFO +209 -0
- sqliter_py-0.9.0/README.md +178 -0
- sqliter_py-0.9.0/pyproject.toml +172 -0
- sqliter_py-0.9.0/sqliter/__init__.py +9 -0
- sqliter_py-0.9.0/sqliter/constants.py +45 -0
- sqliter_py-0.9.0/sqliter/exceptions.py +168 -0
- sqliter_py-0.9.0/sqliter/helpers.py +100 -0
- sqliter_py-0.9.0/sqliter/model/__init__.py +11 -0
- sqliter_py-0.9.0/sqliter/model/model.py +236 -0
- sqliter_py-0.9.0/sqliter/model/unique.py +19 -0
- sqliter_py-0.9.0/sqliter/py.typed +0 -0
- sqliter_py-0.9.0/sqliter/query/__init__.py +9 -0
- sqliter_py-0.9.0/sqliter/query/query.py +762 -0
- sqliter_py-0.9.0/sqliter/sqliter.py +724 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sqliter-py
|
|
3
|
+
Version: 0.9.0
|
|
4
|
+
Summary: Interact with SQLite databases using Python and Pydantic
|
|
5
|
+
Author: Grant Ramsay
|
|
6
|
+
Author-email: Grant Ramsay <grant@gnramsay.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Database :: Front-Ends
|
|
19
|
+
Classifier: Topic :: Software Development
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Dist: pydantic==2.11.5
|
|
22
|
+
Requires-Dist: inflect==7.0.0 ; extra == 'extras'
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Project-URL: Bug Tracker, https://github.com/seapagan/sqliter-py/issues
|
|
25
|
+
Project-URL: Changelog, https://github.com/seapagan/sqliter-py/blob/main/CHANGELOG.md
|
|
26
|
+
Project-URL: Homepage, http://sqliter.grantramsay.dev
|
|
27
|
+
Project-URL: Pull Requests, https://github.com/seapagan/sqliter-py/pulls
|
|
28
|
+
Project-URL: Repository, https://github.com/seapagan/sqliter-py
|
|
29
|
+
Provides-Extra: extras
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# SQLiter <!-- omit in toc -->
|
|
33
|
+
|
|
34
|
+
[](https://badge.fury.io/py/sqliter-py)
|
|
35
|
+
[](https://github.com/seapagan/sqliter-py/actions/workflows/testing.yml)
|
|
36
|
+
[](https://github.com/seapagan/sqliter-py/actions/workflows/linting.yml)
|
|
37
|
+
[](https://github.com/seapagan/sqliter-py/actions/workflows/mypy.yml)
|
|
38
|
+

|
|
39
|
+
|
|
40
|
+
SQLiter is a lightweight Object-Relational Mapping (ORM) library for SQLite
|
|
41
|
+
databases in Python. It provides a simplified interface for interacting with
|
|
42
|
+
SQLite databases using Pydantic models. The only external run-time dependency
|
|
43
|
+
is Pydantic itself.
|
|
44
|
+
|
|
45
|
+
It does not aim to be a full-fledged ORM like SQLAlchemy, but rather a simple
|
|
46
|
+
and easy-to-use library for basic database operations, especially for small
|
|
47
|
+
projects. It is NOT asynchronous and does not support complex queries (at this
|
|
48
|
+
time).
|
|
49
|
+
|
|
50
|
+
The ideal use case is more for Python CLI tools that need to store data in a
|
|
51
|
+
database-like format without needing to learn SQL or use a full ORM.
|
|
52
|
+
|
|
53
|
+
Full documentation is available on the [Website](https://sqliter.grantramsay.dev)
|
|
54
|
+
|
|
55
|
+
> [!CAUTION]
|
|
56
|
+
>
|
|
57
|
+
> Currently NOT compatible with Python 3.14 (I need to refactor some code d/t
|
|
58
|
+
> changes in the latest Pydantic versions, this is a priority.)
|
|
59
|
+
>
|
|
60
|
+
> This project is still in the early stages of development and is lacking some
|
|
61
|
+
> planned functionality. Please use with caution - Classes and methods may
|
|
62
|
+
> change until a stable release is made. I'll try to keep this to an absolute
|
|
63
|
+
> minimum and the releases and documentation will be very clear about any
|
|
64
|
+
> breaking changes.
|
|
65
|
+
>
|
|
66
|
+
> See the [TODO](TODO.md) for planned features and improvements.
|
|
67
|
+
|
|
68
|
+
- [Features](#features)
|
|
69
|
+
- [Installation](#installation)
|
|
70
|
+
- [Optional Dependencies](#optional-dependencies)
|
|
71
|
+
- [Quick Start](#quick-start)
|
|
72
|
+
- [Contributing](#contributing)
|
|
73
|
+
- [License](#license)
|
|
74
|
+
|
|
75
|
+
## Features
|
|
76
|
+
|
|
77
|
+
- Table creation based on Pydantic models
|
|
78
|
+
- Supports `date` and `datetime` fields
|
|
79
|
+
- Support for complex data types (`list`, `dict`, `set`, `tuple`) stored as
|
|
80
|
+
BLOBs
|
|
81
|
+
- Automatic primary key generation
|
|
82
|
+
- User defined indexes on any field
|
|
83
|
+
- Set any field as UNIQUE
|
|
84
|
+
- CRUD operations (Create, Read, Update, Delete)
|
|
85
|
+
- Chained Query building with filtering, ordering, and pagination
|
|
86
|
+
- Transaction support
|
|
87
|
+
- Custom exceptions for better error handling
|
|
88
|
+
- Full type hinting and type checking
|
|
89
|
+
- Detailed documentation and examples
|
|
90
|
+
- No external dependencies other than Pydantic
|
|
91
|
+
- Full test coverage
|
|
92
|
+
- Can optionally output the raw SQL queries being executed for debugging
|
|
93
|
+
purposes.
|
|
94
|
+
|
|
95
|
+
## Installation
|
|
96
|
+
|
|
97
|
+
You can install SQLiter using whichever method you prefer or is compatible with
|
|
98
|
+
your project setup.
|
|
99
|
+
|
|
100
|
+
With `uv` which is rapidly becoming my favorite tool for managing projects and
|
|
101
|
+
virtual environments (`uv` is used for developing this project and in the CI):
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
uv add sqliter-py
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
With `Poetry`:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
poetry add sqliter-py
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Or with `pip`:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
pip install sqliter-py
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Optional Dependencies
|
|
120
|
+
|
|
121
|
+
Currently by default, the only external dependency is Pydantic. However, there
|
|
122
|
+
are some optional dependencies that can be installed to enable additional
|
|
123
|
+
features:
|
|
124
|
+
|
|
125
|
+
- `inflect`: For pluralizing the auto-generated table names (if not explicitly
|
|
126
|
+
set in the Model) This just offers a more-advanced pluralization than the
|
|
127
|
+
default method used. In most cases you will not need this.
|
|
128
|
+
|
|
129
|
+
See [Installing Optional
|
|
130
|
+
Dependencies](https://sqliter.grantramsay.dev/installation#optional-dependencies)
|
|
131
|
+
for more information.
|
|
132
|
+
|
|
133
|
+
## Quick Start
|
|
134
|
+
|
|
135
|
+
Here's a quick example of how to use SQLiter:
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
from sqliter import SqliterDB
|
|
139
|
+
from sqliter.model import BaseDBModel
|
|
140
|
+
|
|
141
|
+
# Define your model
|
|
142
|
+
class User(BaseDBModel):
|
|
143
|
+
name: str
|
|
144
|
+
age: int
|
|
145
|
+
|
|
146
|
+
# Create a database connection
|
|
147
|
+
db = SqliterDB("example.db")
|
|
148
|
+
|
|
149
|
+
# Create the table
|
|
150
|
+
db.create_table(User)
|
|
151
|
+
|
|
152
|
+
# Insert a record
|
|
153
|
+
user = User(name="John Doe", age=30)
|
|
154
|
+
new_user = db.insert(user)
|
|
155
|
+
|
|
156
|
+
# Query records
|
|
157
|
+
results = db.select(User).filter(name="John Doe").fetch_all()
|
|
158
|
+
for user in results:
|
|
159
|
+
print(f"User: {user.name}, Age: {user.age}")
|
|
160
|
+
|
|
161
|
+
# Update a record
|
|
162
|
+
new_user.age = 31
|
|
163
|
+
db.update(new_user)
|
|
164
|
+
|
|
165
|
+
# Delete a record by primary key
|
|
166
|
+
db.delete(User, new_user.pk)
|
|
167
|
+
|
|
168
|
+
# Delete all records returned from a query:
|
|
169
|
+
delete_count = db.select(User).filter(age__gt=30).delete()
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
See the [Guide](https://sqliter.grantramsay.dev/guide/guide/) section of the
|
|
173
|
+
documentation for more detailed information on how to use SQLiter, and advanced
|
|
174
|
+
features.
|
|
175
|
+
|
|
176
|
+
## Contributing
|
|
177
|
+
|
|
178
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
179
|
+
|
|
180
|
+
See the [CONTRIBUTING](CONTRIBUTING.md) guide for more information.
|
|
181
|
+
|
|
182
|
+
Please note that this project is released with a Contributor Code of Conduct,
|
|
183
|
+
which you can read in the [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) file.
|
|
184
|
+
|
|
185
|
+
## License
|
|
186
|
+
|
|
187
|
+
This project is licensed under the MIT License.
|
|
188
|
+
|
|
189
|
+
```pre
|
|
190
|
+
Copyright (c) 2024-2025 Grant Ramsay
|
|
191
|
+
|
|
192
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
193
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
194
|
+
in the Software without restriction, including without limitation the rights
|
|
195
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
196
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
197
|
+
furnished to do so, subject to the following conditions:
|
|
198
|
+
|
|
199
|
+
The above copyright notice and this permission notice shall be included in all
|
|
200
|
+
copies or substantial portions of the Software.
|
|
201
|
+
|
|
202
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
203
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
204
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
205
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
206
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
207
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
|
208
|
+
OR OTHER DEALINGS IN THE SOFTWARE.
|
|
209
|
+
```
|
|
@@ -0,0 +1,178 @@
|
|
|
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 [Website](https://sqliter.grantramsay.dev)
|
|
23
|
+
|
|
24
|
+
> [!CAUTION]
|
|
25
|
+
>
|
|
26
|
+
> Currently NOT compatible with Python 3.14 (I need to refactor some code d/t
|
|
27
|
+
> changes in the latest Pydantic versions, this is a priority.)
|
|
28
|
+
>
|
|
29
|
+
> This project is still in the early stages of development and is lacking some
|
|
30
|
+
> planned functionality. Please use with caution - Classes and methods may
|
|
31
|
+
> change until a stable release is made. I'll try to keep this to an absolute
|
|
32
|
+
> minimum and the releases and documentation will be very clear about any
|
|
33
|
+
> breaking changes.
|
|
34
|
+
>
|
|
35
|
+
> See the [TODO](TODO.md) for planned features and improvements.
|
|
36
|
+
|
|
37
|
+
- [Features](#features)
|
|
38
|
+
- [Installation](#installation)
|
|
39
|
+
- [Optional Dependencies](#optional-dependencies)
|
|
40
|
+
- [Quick Start](#quick-start)
|
|
41
|
+
- [Contributing](#contributing)
|
|
42
|
+
- [License](#license)
|
|
43
|
+
|
|
44
|
+
## Features
|
|
45
|
+
|
|
46
|
+
- Table creation based on Pydantic models
|
|
47
|
+
- Supports `date` and `datetime` fields
|
|
48
|
+
- Support for complex data types (`list`, `dict`, `set`, `tuple`) stored as
|
|
49
|
+
BLOBs
|
|
50
|
+
- Automatic primary key generation
|
|
51
|
+
- User defined indexes on any field
|
|
52
|
+
- Set any field as UNIQUE
|
|
53
|
+
- CRUD operations (Create, Read, Update, Delete)
|
|
54
|
+
- Chained Query building with filtering, ordering, and pagination
|
|
55
|
+
- Transaction support
|
|
56
|
+
- Custom exceptions for better error handling
|
|
57
|
+
- Full type hinting and type checking
|
|
58
|
+
- Detailed documentation and examples
|
|
59
|
+
- No external dependencies other than Pydantic
|
|
60
|
+
- Full test coverage
|
|
61
|
+
- Can optionally output the raw SQL queries being executed for debugging
|
|
62
|
+
purposes.
|
|
63
|
+
|
|
64
|
+
## Installation
|
|
65
|
+
|
|
66
|
+
You can install SQLiter using whichever method you prefer or is compatible with
|
|
67
|
+
your project setup.
|
|
68
|
+
|
|
69
|
+
With `uv` which is rapidly becoming my favorite tool for managing projects and
|
|
70
|
+
virtual environments (`uv` is used for developing this project and in the CI):
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
uv add sqliter-py
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
With `Poetry`:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
poetry add sqliter-py
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Or with `pip`:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
pip install sqliter-py
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Optional Dependencies
|
|
89
|
+
|
|
90
|
+
Currently by default, the only external dependency is Pydantic. However, there
|
|
91
|
+
are some optional dependencies that can be installed to enable additional
|
|
92
|
+
features:
|
|
93
|
+
|
|
94
|
+
- `inflect`: For pluralizing the auto-generated table names (if not explicitly
|
|
95
|
+
set in the Model) This just offers a more-advanced pluralization than the
|
|
96
|
+
default method used. In most cases you will not need this.
|
|
97
|
+
|
|
98
|
+
See [Installing Optional
|
|
99
|
+
Dependencies](https://sqliter.grantramsay.dev/installation#optional-dependencies)
|
|
100
|
+
for more information.
|
|
101
|
+
|
|
102
|
+
## Quick Start
|
|
103
|
+
|
|
104
|
+
Here's a quick example of how to use SQLiter:
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from sqliter import SqliterDB
|
|
108
|
+
from sqliter.model import BaseDBModel
|
|
109
|
+
|
|
110
|
+
# Define your model
|
|
111
|
+
class User(BaseDBModel):
|
|
112
|
+
name: str
|
|
113
|
+
age: int
|
|
114
|
+
|
|
115
|
+
# Create a database connection
|
|
116
|
+
db = SqliterDB("example.db")
|
|
117
|
+
|
|
118
|
+
# Create the table
|
|
119
|
+
db.create_table(User)
|
|
120
|
+
|
|
121
|
+
# Insert a record
|
|
122
|
+
user = User(name="John Doe", age=30)
|
|
123
|
+
new_user = db.insert(user)
|
|
124
|
+
|
|
125
|
+
# Query records
|
|
126
|
+
results = db.select(User).filter(name="John Doe").fetch_all()
|
|
127
|
+
for user in results:
|
|
128
|
+
print(f"User: {user.name}, Age: {user.age}")
|
|
129
|
+
|
|
130
|
+
# Update a record
|
|
131
|
+
new_user.age = 31
|
|
132
|
+
db.update(new_user)
|
|
133
|
+
|
|
134
|
+
# Delete a record by primary key
|
|
135
|
+
db.delete(User, new_user.pk)
|
|
136
|
+
|
|
137
|
+
# Delete all records returned from a query:
|
|
138
|
+
delete_count = db.select(User).filter(age__gt=30).delete()
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
See the [Guide](https://sqliter.grantramsay.dev/guide/guide/) section of the
|
|
142
|
+
documentation for more detailed information on how to use SQLiter, and advanced
|
|
143
|
+
features.
|
|
144
|
+
|
|
145
|
+
## Contributing
|
|
146
|
+
|
|
147
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
148
|
+
|
|
149
|
+
See the [CONTRIBUTING](CONTRIBUTING.md) guide for more information.
|
|
150
|
+
|
|
151
|
+
Please note that this project is released with a Contributor Code of Conduct,
|
|
152
|
+
which you can read in the [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) file.
|
|
153
|
+
|
|
154
|
+
## License
|
|
155
|
+
|
|
156
|
+
This project is licensed under the MIT License.
|
|
157
|
+
|
|
158
|
+
```pre
|
|
159
|
+
Copyright (c) 2024-2025 Grant Ramsay
|
|
160
|
+
|
|
161
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
162
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
163
|
+
in the Software without restriction, including without limitation the rights
|
|
164
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
165
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
166
|
+
furnished to do so, subject to the following conditions:
|
|
167
|
+
|
|
168
|
+
The above copyright notice and this permission notice shall be included in all
|
|
169
|
+
copies or substantial portions of the Software.
|
|
170
|
+
|
|
171
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
172
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
173
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
174
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
175
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
176
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
|
177
|
+
OR OTHER DEALINGS IN THE SOFTWARE.
|
|
178
|
+
```
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# Configuration file for the SQLiter project.
|
|
2
|
+
# This file defines project metadata, dependencies, and development tools.
|
|
3
|
+
|
|
4
|
+
[project]
|
|
5
|
+
name = "sqliter-py"
|
|
6
|
+
version = "0.9.0"
|
|
7
|
+
description = "Interact with SQLite databases using Python and Pydantic"
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
requires-python = ">=3.9"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
authors = [{ name = "Grant Ramsay", email = "grant@gnramsay.com" }]
|
|
12
|
+
dependencies = ["pydantic==2.11.5"]
|
|
13
|
+
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.9",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Topic :: Database :: Front-Ends",
|
|
26
|
+
"Topic :: Software Development",
|
|
27
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.optional-dependencies]
|
|
31
|
+
extras = ["inflect==7.0.0"]
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
"Homepage" = "http://sqliter.grantramsay.dev"
|
|
35
|
+
"Pull Requests" = "https://github.com/seapagan/sqliter-py/pulls"
|
|
36
|
+
"Bug Tracker" = "https://github.com/seapagan/sqliter-py/issues"
|
|
37
|
+
"Changelog" = "https://github.com/seapagan/sqliter-py/blob/main/CHANGELOG.md"
|
|
38
|
+
"Repository" = "https://github.com/seapagan/sqliter-py"
|
|
39
|
+
|
|
40
|
+
[build-system]
|
|
41
|
+
requires = ["uv_build>=0.9.9,<0.10.0"]
|
|
42
|
+
build-backend = "uv_build"
|
|
43
|
+
|
|
44
|
+
[tool.uv.build-backend]
|
|
45
|
+
module-name = "sqliter"
|
|
46
|
+
module-root = ""
|
|
47
|
+
|
|
48
|
+
[dependency-groups]
|
|
49
|
+
dev = [
|
|
50
|
+
"mock>=5.1.0",
|
|
51
|
+
"mypy>=1.11.2",
|
|
52
|
+
"pytest>=8.3.2",
|
|
53
|
+
"pytest-mock>=3.14.0",
|
|
54
|
+
"ruff>=0.6.4",
|
|
55
|
+
"pytest-sugar>=1.0.0",
|
|
56
|
+
"pytest-reverse>=1.7.0",
|
|
57
|
+
"pytest-randomly>=3.15.0",
|
|
58
|
+
"pytest-cov>=5.0.0",
|
|
59
|
+
"pytest-watcher>=0.4.3",
|
|
60
|
+
"pytest-clarity>=1.0.1",
|
|
61
|
+
"poethepoet>=0.28.0",
|
|
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",
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
[tool.poe.tasks]
|
|
72
|
+
pre.cmd = "pre-commit run --all-files"
|
|
73
|
+
pre.help = "Run pre-commit checks"
|
|
74
|
+
|
|
75
|
+
mypy.cmd = "mypy . --strict"
|
|
76
|
+
mypy.help = "Run mypy checks"
|
|
77
|
+
format.cmd = "ruff format ."
|
|
78
|
+
format.help = "Format code with Ruff"
|
|
79
|
+
ruff.cmd = "ruff check --output-format=concise ."
|
|
80
|
+
ruff.help = "Run Ruff checks"
|
|
81
|
+
|
|
82
|
+
test.cmd = "pytest"
|
|
83
|
+
test.help = "Run tests using Pytest"
|
|
84
|
+
"test:watch".cmd = "ptw . --now --clear"
|
|
85
|
+
"test:watch".help = "Run tests using Pytest in watch mode"
|
|
86
|
+
|
|
87
|
+
changelog.cmd = "github-changelog-md"
|
|
88
|
+
changelog.help = "Generate a changelog"
|
|
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
|
+
|
|
99
|
+
[tool.ruff]
|
|
100
|
+
line-length = 80
|
|
101
|
+
lint.select = ["ALL"] # we are being very strict!
|
|
102
|
+
lint.ignore = [
|
|
103
|
+
"PGH003",
|
|
104
|
+
"FBT002",
|
|
105
|
+
"FBT003",
|
|
106
|
+
"B006",
|
|
107
|
+
"S301", # in this library we use 'pickle' for saving and loading list etc
|
|
108
|
+
] # These rules are too strict even for us 😝
|
|
109
|
+
lint.extend-ignore = [
|
|
110
|
+
"COM812",
|
|
111
|
+
"ISC001",
|
|
112
|
+
] # these are ignored for ruff formatting
|
|
113
|
+
|
|
114
|
+
src = ["sqliter"]
|
|
115
|
+
target-version = "py39" # minimum python version supported
|
|
116
|
+
|
|
117
|
+
[tool.ruff.format]
|
|
118
|
+
indent-style = "space"
|
|
119
|
+
quote-style = "double"
|
|
120
|
+
|
|
121
|
+
[tool.ruff.lint.pylint]
|
|
122
|
+
max-args = 6
|
|
123
|
+
|
|
124
|
+
[tool.ruff.lint.pep8-naming]
|
|
125
|
+
classmethod-decorators = ["pydantic.validator", "pydantic.root_validator"]
|
|
126
|
+
|
|
127
|
+
[tool.ruff.lint.pydocstyle]
|
|
128
|
+
convention = "google"
|
|
129
|
+
|
|
130
|
+
[tool.ruff.lint.extend-per-file-ignores]
|
|
131
|
+
"tests/**/*.py" = [
|
|
132
|
+
"S101", # we can (and MUST!) use 'assert' in test files.
|
|
133
|
+
"ANN001", # annotations for fixtures are sometimes a pain for test files
|
|
134
|
+
"ARG00", # test fixtures often are not directly used
|
|
135
|
+
"PLR2004", # magic numbers are often used in test files
|
|
136
|
+
"SLF001", # sometimes we need to test private methods
|
|
137
|
+
]
|
|
138
|
+
|
|
139
|
+
[tool.ruff.lint.isort]
|
|
140
|
+
known-first-party = ["sqliter"]
|
|
141
|
+
|
|
142
|
+
[tool.ruff.lint.pyupgrade]
|
|
143
|
+
keep-runtime-typing = true
|
|
144
|
+
|
|
145
|
+
[tool.mypy]
|
|
146
|
+
plugins = ["pydantic.mypy"]
|
|
147
|
+
|
|
148
|
+
python_version = "3.9"
|
|
149
|
+
exclude = ["docs"]
|
|
150
|
+
[[tool.mypy.overrides]]
|
|
151
|
+
disable_error_code = ["method-assign", "no-untyped-def", "attr-defined"]
|
|
152
|
+
module = "tests.*"
|
|
153
|
+
|
|
154
|
+
[tool.pytest.ini_options]
|
|
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
|
+
]
|
|
167
|
+
mock_use_standalone_module = true
|
|
168
|
+
markers = []
|
|
169
|
+
|
|
170
|
+
[tool.coverage.run]
|
|
171
|
+
source = ["sqliter"]
|
|
172
|
+
omit = ["*/tests/*"]
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
import datetime
|
|
10
|
+
|
|
11
|
+
# A dictionary mapping SQLiter filter operators to their corresponding SQL
|
|
12
|
+
# operators.
|
|
13
|
+
OPERATOR_MAPPING = {
|
|
14
|
+
"__lt": "<",
|
|
15
|
+
"__lte": "<=",
|
|
16
|
+
"__gt": ">",
|
|
17
|
+
"__gte": ">=",
|
|
18
|
+
"__eq": "=",
|
|
19
|
+
"__ne": "!=",
|
|
20
|
+
"__in": "IN",
|
|
21
|
+
"__not_in": "NOT IN",
|
|
22
|
+
"__isnull": "IS NULL",
|
|
23
|
+
"__notnull": "IS NOT NULL",
|
|
24
|
+
"__startswith": "LIKE",
|
|
25
|
+
"__endswith": "LIKE",
|
|
26
|
+
"__contains": "LIKE",
|
|
27
|
+
"__istartswith": "LIKE",
|
|
28
|
+
"__iendswith": "LIKE",
|
|
29
|
+
"__icontains": "LIKE",
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
# A dictionary mapping Python types to their corresponding SQLite column types.
|
|
33
|
+
SQLITE_TYPE_MAPPING = {
|
|
34
|
+
int: "INTEGER",
|
|
35
|
+
float: "REAL",
|
|
36
|
+
str: "TEXT",
|
|
37
|
+
bool: "INTEGER", # SQLite stores booleans as integers (0 or 1)
|
|
38
|
+
bytes: "BLOB",
|
|
39
|
+
datetime.datetime: "INTEGER", # Store as Unix timestamp
|
|
40
|
+
datetime.date: "INTEGER", # Store as Unix timestamp
|
|
41
|
+
list: "BLOB",
|
|
42
|
+
dict: "BLOB",
|
|
43
|
+
set: "BLOB",
|
|
44
|
+
tuple: "BLOB",
|
|
45
|
+
}
|