sqliter-py 0.3.0__tar.gz → 0.5.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.

@@ -65,6 +65,7 @@ htmlcov/
65
65
  .cache
66
66
  nosetests.xml
67
67
  coverage.xml
68
+ coverage.lcov
68
69
  *.cover
69
70
  *.py,cover
70
71
  .hypothesis/
@@ -0,0 +1,199 @@
1
+ Metadata-Version: 2.3
2
+ Name: sqliter-py
3
+ Version: 0.5.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
+ [![PyPI version](https://badge.fury.io/py/sqliter-py.svg)](https://badge.fury.io/py/sqliter-py)
32
+ [![Test Suite](https://github.com/seapagan/sqliter-py/actions/workflows/testing.yml/badge.svg)](https://github.com/seapagan/sqliter-py/actions/workflows/testing.yml)
33
+ [![Linting](https://github.com/seapagan/sqliter-py/actions/workflows/linting.yml/badge.svg)](https://github.com/seapagan/sqliter-py/actions/workflows/linting.yml)
34
+ [![Type Checking](https://github.com/seapagan/sqliter-py/actions/workflows/mypy.yml/badge.svg)](https://github.com/seapagan/sqliter-py/actions/workflows/mypy.yml)
35
+ ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sqliter-py)
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 - Classes and methods may
56
+ > change until a stable release is made. I'll try to keep this to an absolute
57
+ > minimum and the releases and documentation will be very clear about any
58
+ > breaking changes.
59
+ >
60
+ > Also, structures like `list`, `dict`, `set` etc are not supported **at this
61
+ > time** as field types, since SQLite does not have a native column type for
62
+ > these. This is the **next planned enhancement**. These will need to be
63
+ > `pickled` first then stored as a BLOB in the database . Also support `date`
64
+ > which can be stored as a Unix timestamp in an integer field.
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
+ - CRUD operations (Create, Read, Update, Delete)
79
+ - Chained Query building with filtering, ordering, and pagination
80
+ - Transaction support
81
+ - Custom exceptions for better error handling
82
+ - Full type hinting and type checking
83
+ - Detailed documentation and examples
84
+ - No external dependencies other than Pydantic
85
+ - Full test coverage
86
+ - Can optionally output the raw SQL queries being executed for debugging
87
+ purposes.
88
+
89
+ ## Installation
90
+
91
+ You can install SQLiter using whichever method you prefer or is compatible with
92
+ your project setup.
93
+
94
+ With `uv` which is rapidly becoming my favorite tool for managing projects and
95
+ virtual environments (`uv` is used for developing this project and in the CI):
96
+
97
+ ```bash
98
+ uv add sqliter-py
99
+ ```
100
+
101
+ With `pip`:
102
+
103
+ ```bash
104
+ pip install sqliter-py
105
+ ```
106
+
107
+ Or with `Poetry`:
108
+
109
+ ```bash
110
+ poetry add sqliter-py
111
+ ```
112
+
113
+ ### Optional Dependencies
114
+
115
+ Currently by default, the only external dependency is Pydantic. However, there
116
+ are some optional dependencies that can be installed to enable additional
117
+ features:
118
+
119
+ - `inflect`: For pluralizing table names (if not specified). This just offers a
120
+ more-advanced pluralization than the default method used. In most cases you
121
+ will not need this.
122
+
123
+ See [Installing Optional
124
+ Dependencies](https://sqliter.grantramsay.dev/installation#optional-dependencies)
125
+ for more information.
126
+
127
+ ## Quick Start
128
+
129
+ Here's a quick example of how to use SQLiter:
130
+
131
+ ```python
132
+ from sqliter import SqliterDB
133
+ from sqliter.model import BaseDBModel
134
+
135
+ # Define your model
136
+ class User(BaseDBModel):
137
+ name: str
138
+ age: int
139
+
140
+ # Create a database connection
141
+ db = SqliterDB("example.db")
142
+
143
+ # Create the table
144
+ db.create_table(User)
145
+
146
+ # Insert a record
147
+ user = User(name="John Doe", age=30)
148
+ new_user = db.insert(user)
149
+
150
+ # Query records
151
+ results = db.select(User).filter(name="John Doe").fetch_all()
152
+ for user in results:
153
+ print(f"User: {user.name}, Age: {user.age}")
154
+
155
+ # Update a record
156
+ new_user.age = 31
157
+ db.update(new_user)
158
+
159
+ # Delete a record
160
+ db.delete(User, new_user.pk)
161
+ ```
162
+
163
+ See the [Usage](https://sqliter.grantramsay.dev/usage) section of the documentation
164
+ for more detailed information on how to use SQLiter, and advanced features.
165
+
166
+ ## Contributing
167
+
168
+ Contributions are welcome! Please feel free to submit a Pull Request.
169
+
170
+ See the [CONTRIBUTING](CONTRIBUTING.md) guide for more information.
171
+
172
+ Please note that this project is released with a Contributor Code of Conduct,
173
+ which you can read in the [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) file.
174
+
175
+ ## License
176
+
177
+ This project is licensed under the MIT License.
178
+
179
+ ```pre
180
+ Copyright (c) 2024 Grant Ramsay
181
+
182
+ Permission is hereby granted, free of charge, to any person obtaining a copy
183
+ of this software and associated documentation files (the "Software"), to deal
184
+ in the Software without restriction, including without limitation the rights
185
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
186
+ copies of the Software, and to permit persons to whom the Software is
187
+ furnished to do so, subject to the following conditions:
188
+
189
+ The above copyright notice and this permission notice shall be included in all
190
+ copies or substantial portions of the Software.
191
+
192
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
193
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
194
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
195
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
196
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
197
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
198
+ OR OTHER DEALINGS IN THE SOFTWARE.
199
+ ```
@@ -0,0 +1,171 @@
1
+ # SQLiter <!-- omit in toc -->
2
+
3
+ [![PyPI version](https://badge.fury.io/py/sqliter-py.svg)](https://badge.fury.io/py/sqliter-py)
4
+ [![Test Suite](https://github.com/seapagan/sqliter-py/actions/workflows/testing.yml/badge.svg)](https://github.com/seapagan/sqliter-py/actions/workflows/testing.yml)
5
+ [![Linting](https://github.com/seapagan/sqliter-py/actions/workflows/linting.yml/badge.svg)](https://github.com/seapagan/sqliter-py/actions/workflows/linting.yml)
6
+ [![Type Checking](https://github.com/seapagan/sqliter-py/actions/workflows/mypy.yml/badge.svg)](https://github.com/seapagan/sqliter-py/actions/workflows/mypy.yml)
7
+ ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sqliter-py)
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 - Classes and methods may
28
+ > change until a stable release is made. I'll try to keep this to an absolute
29
+ > minimum and the releases and documentation will be very clear about any
30
+ > breaking changes.
31
+ >
32
+ > Also, structures like `list`, `dict`, `set` etc are not supported **at this
33
+ > time** as field types, since SQLite does not have a native column type for
34
+ > these. This is the **next planned enhancement**. These will need to be
35
+ > `pickled` first then stored as a BLOB in the database . Also support `date`
36
+ > which can be stored as a Unix timestamp in an integer field.
37
+ >
38
+ > See the [TODO](TODO.md) for planned features and improvements.
39
+
40
+ - [Features](#features)
41
+ - [Installation](#installation)
42
+ - [Optional Dependencies](#optional-dependencies)
43
+ - [Quick Start](#quick-start)
44
+ - [Contributing](#contributing)
45
+ - [License](#license)
46
+
47
+ ## Features
48
+
49
+ - Table creation based on Pydantic models
50
+ - CRUD operations (Create, Read, Update, Delete)
51
+ - Chained Query building with filtering, ordering, and pagination
52
+ - Transaction support
53
+ - Custom exceptions for better error handling
54
+ - Full type hinting and type checking
55
+ - Detailed documentation and examples
56
+ - No external dependencies other than Pydantic
57
+ - Full test coverage
58
+ - Can optionally output the raw SQL queries being executed for debugging
59
+ purposes.
60
+
61
+ ## Installation
62
+
63
+ You can install SQLiter using whichever method you prefer or is compatible with
64
+ your project setup.
65
+
66
+ With `uv` which is rapidly becoming my favorite tool for managing projects and
67
+ virtual environments (`uv` is used for developing this project and in the CI):
68
+
69
+ ```bash
70
+ uv add sqliter-py
71
+ ```
72
+
73
+ With `pip`:
74
+
75
+ ```bash
76
+ pip install sqliter-py
77
+ ```
78
+
79
+ Or with `Poetry`:
80
+
81
+ ```bash
82
+ poetry add sqliter-py
83
+ ```
84
+
85
+ ### Optional Dependencies
86
+
87
+ Currently by default, the only external dependency is Pydantic. However, there
88
+ are some optional dependencies that can be installed to enable additional
89
+ features:
90
+
91
+ - `inflect`: For pluralizing table names (if not specified). This just offers a
92
+ more-advanced pluralization than the default method used. In most cases you
93
+ will not need this.
94
+
95
+ See [Installing Optional
96
+ Dependencies](https://sqliter.grantramsay.dev/installation#optional-dependencies)
97
+ for more information.
98
+
99
+ ## Quick Start
100
+
101
+ Here's a quick example of how to use SQLiter:
102
+
103
+ ```python
104
+ from sqliter import SqliterDB
105
+ from sqliter.model import BaseDBModel
106
+
107
+ # Define your model
108
+ class User(BaseDBModel):
109
+ name: str
110
+ age: int
111
+
112
+ # Create a database connection
113
+ db = SqliterDB("example.db")
114
+
115
+ # Create the table
116
+ db.create_table(User)
117
+
118
+ # Insert a record
119
+ user = User(name="John Doe", age=30)
120
+ new_user = db.insert(user)
121
+
122
+ # Query records
123
+ results = db.select(User).filter(name="John Doe").fetch_all()
124
+ for user in results:
125
+ print(f"User: {user.name}, Age: {user.age}")
126
+
127
+ # Update a record
128
+ new_user.age = 31
129
+ db.update(new_user)
130
+
131
+ # Delete a record
132
+ db.delete(User, new_user.pk)
133
+ ```
134
+
135
+ See the [Usage](https://sqliter.grantramsay.dev/usage) section of the documentation
136
+ for more detailed information on how to use SQLiter, and advanced features.
137
+
138
+ ## Contributing
139
+
140
+ Contributions are welcome! Please feel free to submit a Pull Request.
141
+
142
+ See the [CONTRIBUTING](CONTRIBUTING.md) guide for more information.
143
+
144
+ Please note that this project is released with a Contributor Code of Conduct,
145
+ which you can read in the [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) file.
146
+
147
+ ## License
148
+
149
+ This project is licensed under the MIT License.
150
+
151
+ ```pre
152
+ Copyright (c) 2024 Grant Ramsay
153
+
154
+ Permission is hereby granted, free of charge, to any person obtaining a copy
155
+ of this software and associated documentation files (the "Software"), to deal
156
+ in the Software without restriction, including without limitation the rights
157
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
158
+ copies of the Software, and to permit persons to whom the Software is
159
+ furnished to do so, subject to the following conditions:
160
+
161
+ The above copyright notice and this permission notice shall be included in all
162
+ copies or substantial portions of the Software.
163
+
164
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
165
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
166
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
167
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
168
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
169
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
170
+ OR OTHER DEALINGS IN THE SOFTWARE.
171
+ ```
@@ -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.3.0"
6
+ version = "0.5.0"
4
7
  description = "Interact with SQLite databases using Python and Pydantic"
5
8
  readme = "README.md"
6
9
  requires-python = ">=3.9"
@@ -58,6 +61,11 @@ dev-dependencies = [
58
61
  "poethepoet>=0.28.0",
59
62
  "github-changelog-md>=0.9.5",
60
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",
61
69
  ]
62
70
 
63
71
  [tool.poe.tasks]
@@ -66,19 +74,28 @@ pre.help = "Run pre-commit checks"
66
74
 
67
75
  mypy.cmd = "mypy . --strict"
68
76
  mypy.help = "Run mypy checks"
69
- format.help = "Format code with Ruff"
70
77
  format.cmd = "ruff format ."
71
- ruff.help = "Run Ruff checks"
78
+ format.help = "Format code with Ruff"
72
79
  ruff.cmd = "ruff check --output-format=concise ."
80
+ ruff.help = "Run Ruff checks"
73
81
 
74
- test.help = "Run tests using Pytest"
75
82
  test.cmd = "pytest"
83
+ test.help = "Run tests using Pytest"
76
84
  "test:watch".cmd = "ptw . --now --clear"
77
85
  "test:watch".help = "Run tests using Pytest in watch mode"
78
86
 
79
87
  changelog.cmd = "github-changelog-md"
80
88
  changelog.help = "Generate a changelog"
81
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
+
82
99
  [tool.ruff]
83
100
  line-length = 80
84
101
  lint.select = ["ALL"] # we are being very strict!
@@ -102,6 +119,9 @@ target-version = "py39" # minimum python version supported
102
119
  indent-style = "space"
103
120
  quote-style = "double"
104
121
 
122
+ [tool.ruff.lint.pylint]
123
+ max-args = 6
124
+
105
125
  [tool.ruff.lint.pep8-naming]
106
126
  classmethod-decorators = ["pydantic.validator", "pydantic.root_validator"]
107
127
 
@@ -124,18 +144,29 @@ known-first-party = ["sqliter"]
124
144
  keep-runtime-typing = true
125
145
 
126
146
  [tool.mypy]
127
- python_version = "3.9"
147
+ plugins = ["pydantic.mypy"]
128
148
 
149
+ python_version = "3.9"
150
+ exclude = ["docs"]
129
151
  [[tool.mypy.overrides]]
130
152
  disable_error_code = ["method-assign", "no-untyped-def", "attr-defined"]
131
153
  module = "tests.*"
132
154
 
133
155
  [tool.pytest.ini_options]
134
- addopts = ["--cov", "--cov-report", "term-missing", "--cov-report", "html"]
156
+ addopts = [
157
+ "--cov",
158
+ "--cov-report",
159
+ "term-missing",
160
+ "--cov-report",
161
+ "html",
162
+ "--cov-report",
163
+ "lcov",
164
+ ]
135
165
  filterwarnings = [
136
166
  "ignore:'direction' argument is deprecated:DeprecationWarning",
137
167
  ]
138
168
  mock_use_standalone_module = true
169
+ markers = []
139
170
 
140
171
  [tool.coverage.run]
141
172
  source = ["sqliter"]
@@ -0,0 +1,9 @@
1
+ """SQLiter: A lightweight ORM-like library for SQLite databases in Python.
2
+
3
+ This module provides the main SqliterDB class for interacting with
4
+ SQLite databases using Pydantic models.
5
+ """
6
+
7
+ from .sqliter import SqliterDB
8
+
9
+ __all__ = ["SqliterDB"]
@@ -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
- """Define custom exceptions for the sqliter package."""
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 exceptions raised by the sqliter package."""
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
- """Raised when the SQLite database connection fails."""
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
- """Raised when an invalid offset value (0 or negative) is used."""
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
- """Raised when an invalid order value is used."""
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
- """Raised when a table cannot be created in the database."""
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
- """Raised when an error occurs during record insertion."""
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
- """Raised when an error occurs during record update."""
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
- """Raised when a record with the specified primary key is not found."""
115
+ """Exception raised when a requested record is not found in the database."""
101
116
 
102
- message_template = "Failed to find a record for key '{}' "
117
+ message_template = "Failed to find that record in the table (key '{}') "
103
118
 
104
119
 
105
120
  class RecordFetchError(SqliterError):
106
- """Raised when an error occurs during record fetching."""
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
- """Raised when an error occurs during record deletion."""
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
- """Raised when an invalid filter field is used in a query."""
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: '{}'"
@@ -0,0 +1,35 @@
1
+ """Utility functions for SQLiter internal operations.
2
+
3
+ This module provides helper functions used across the SQLiter library,
4
+ primarily for type inference and mapping between Python and SQLite
5
+ data types. These utilities support the core functionality of model
6
+ to database schema translation.
7
+ """
8
+
9
+ from typing import Union
10
+
11
+ from sqliter.constants import SQLITE_TYPE_MAPPING
12
+
13
+
14
+ def infer_sqlite_type(field_type: Union[type, None]) -> str:
15
+ """Infer the SQLite column type based on the Python type.
16
+
17
+ This function maps Python types to their corresponding SQLite column
18
+ types. It's used when creating database tables to ensure that the
19
+ correct SQLite types are used for each field.
20
+
21
+ Args:
22
+ field_type: The Python type of the field, or None.
23
+
24
+ Returns:
25
+ A string representing the corresponding SQLite column type.
26
+
27
+ Note:
28
+ If the input type is None or not recognized, it defaults to 'TEXT'.
29
+ """
30
+ # If field_type is None, default to TEXT
31
+ if field_type is None:
32
+ return "TEXT"
33
+
34
+ # Map the simplified type to an SQLite type
35
+ return SQLITE_TYPE_MAPPING.get(field_type, "TEXT")
@@ -0,0 +1,9 @@
1
+ """This module provides the base model class for SQLiter database models.
2
+
3
+ It exports the BaseDBModel class, which is used to define database
4
+ models in SQLiter applications.
5
+ """
6
+
7
+ from .model import BaseDBModel
8
+
9
+ __all__ = ["BaseDBModel"]