sqliter-py 0.3.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.

@@ -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,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
+ [![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.
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
+ [![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.
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.3.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"
@@ -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
 
@@ -125,17 +145,27 @@ keep-runtime-typing = true
125
145
 
126
146
  [tool.mypy]
127
147
  python_version = "3.9"
148
+ exclude = ["docs"]
128
149
 
129
150
  [[tool.mypy.overrides]]
130
151
  disable_error_code = ["method-assign", "no-untyped-def", "attr-defined"]
131
152
  module = "tests.*"
132
153
 
133
154
  [tool.pytest.ini_options]
134
- addopts = ["--cov", "--cov-report", "term-missing", "--cov-report", "html"]
155
+ addopts = [
156
+ "--cov",
157
+ "--cov-report",
158
+ "term-missing",
159
+ "--cov-report",
160
+ "html",
161
+ "--cov-report",
162
+ "lcov",
163
+ ]
135
164
  filterwarnings = [
136
165
  "ignore:'direction' argument is deprecated:DeprecationWarning",
137
166
  ]
138
167
  mock_use_standalone_module = true
168
+ markers = []
139
169
 
140
170
  [tool.coverage.run]
141
171
  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
117
  message_template = "Failed to find a record for 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"]