sqlite7 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sqlite7/exc.py ADDED
@@ -0,0 +1,101 @@
1
+ """Package-specific exceptions for sqlite7.
2
+
3
+ This module mirrors the familiar DB-API exception hierarchy for the native SQLite backend.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from dataclasses import dataclass
9
+ from typing import Optional
10
+
11
+
12
+ @dataclass(slots=True)
13
+ class SQLiteErrorDetails:
14
+ """Extra metadata captured from a native SQLite failure.
15
+
16
+ Attributes:
17
+ errorcode: SQLite numeric error code, when available.
18
+ errorname: SQLite symbolic error name, when available.
19
+ """
20
+
21
+ errorcode: Optional[int] = None
22
+ errorname: Optional[str] = None
23
+
24
+
25
+ class SQLite7Error(Exception):
26
+ """Base exception for all package-defined errors.
27
+
28
+ Args:
29
+ message: Human-readable error message.
30
+ original: Original backend exception, when present.
31
+ details: Structured SQLite metadata, when present.
32
+ """
33
+
34
+ def __init__(
35
+ self,
36
+ message: str,
37
+ *,
38
+ original: BaseException | None = None,
39
+ details: SQLiteErrorDetails | None = None,
40
+ ) -> None:
41
+ super().__init__(message)
42
+ self.original = original
43
+ self.details = details or SQLiteErrorDetails()
44
+ self.sqlite_errorcode = self.details.errorcode
45
+ self.sqlite_errorname = self.details.errorname
46
+
47
+
48
+ class Warning(SQLite7Error):
49
+ """Raised for important non-fatal conditions."""
50
+
51
+
52
+ class Error(SQLite7Error):
53
+ """Base class for database-related errors."""
54
+
55
+
56
+ class InterfaceError(Error):
57
+ """Raised for interface misuse or invalid inputs."""
58
+
59
+
60
+ class DatabaseError(Error):
61
+ """Raised for general database failures."""
62
+
63
+
64
+ class DataError(DatabaseError):
65
+ """Raised for data processing failures."""
66
+
67
+
68
+ class OperationalError(DatabaseError):
69
+ """Raised for operational failures such as locks or path issues."""
70
+
71
+
72
+ class IntegrityError(DatabaseError):
73
+ """Raised for constraint violations."""
74
+
75
+
76
+ class InternalError(DatabaseError):
77
+ """Raised when SQLite reports an internal failure."""
78
+
79
+
80
+ class ProgrammingError(DatabaseError):
81
+ """Raised for invalid SQL or programming mistakes."""
82
+
83
+
84
+ class NotSupportedError(DatabaseError):
85
+ """Raised for unsupported SQLite features."""
86
+
87
+
88
+ class ConfigurationError(InterfaceError):
89
+ """Raised for invalid client configuration."""
90
+
91
+
92
+ class ValidationError(InterfaceError):
93
+ """Raised when helper-method inputs are malformed."""
94
+
95
+
96
+ class InvalidIdentifierError(ValidationError):
97
+ """Raised when a SQL identifier fails safety validation."""
98
+
99
+
100
+ class ConnectionClosedError(InterfaceError):
101
+ """Raised when an operation is attempted on a closed connection."""
sqlite7/helpers.py ADDED
@@ -0,0 +1,77 @@
1
+ """Internal helper utilities for sqlite7."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+ from collections.abc import Iterable, Mapping, Sequence
7
+ from typing import Any
8
+
9
+ from . import exc
10
+
11
+ _IDENTIFIER_RE = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")
12
+
13
+
14
+ def validate_identifier(value: str, *, kind: str = "identifier") -> str:
15
+ if not isinstance(value, str):
16
+ raise exc.InvalidIdentifierError(f"{kind} must be a string")
17
+ if not value:
18
+ raise exc.InvalidIdentifierError(f"{kind} must not be empty")
19
+ if not _IDENTIFIER_RE.fullmatch(value):
20
+ raise exc.InvalidIdentifierError(
21
+ f"Invalid {kind}: {value!r}. Only letters, numbers, and underscores are allowed, and it must not start with a number."
22
+ )
23
+ return value
24
+
25
+
26
+ def quote_identifier(value: str) -> str:
27
+ return f'"{validate_identifier(value)}"'
28
+
29
+
30
+ def normalize_params(params: Sequence[Any] | None) -> Sequence[Any]:
31
+ if params is None:
32
+ return ()
33
+ if isinstance(params, Mapping):
34
+ raise exc.ValidationError(
35
+ "Named SQL parameters are no longer supported. Use positional parameters with ? placeholders instead."
36
+ )
37
+ return params
38
+
39
+
40
+ def ensure_mapping_row(row: Any, *, index: int) -> Mapping[str, Any]:
41
+ if not isinstance(row, Mapping):
42
+ raise exc.ValidationError(
43
+ f"rows[{index}] must be a mapping of column names to values; got {type(row).__name__}"
44
+ )
45
+ if not row:
46
+ raise exc.ValidationError(f"rows[{index}] must not be empty")
47
+ for key in row.keys():
48
+ validate_identifier(str(key), kind="column name")
49
+ return row
50
+
51
+
52
+ def ensure_consistent_rows(rows: Iterable[Mapping[str, Any]]) -> list[Mapping[str, Any]]:
53
+ materialized = [ensure_mapping_row(row, index=index) for index, row in enumerate(rows)]
54
+ if not materialized:
55
+ raise exc.ValidationError("rows must contain at least one item")
56
+ first_keys = list(materialized[0].keys())
57
+ for index, row in enumerate(materialized[1:], start=1):
58
+ row_keys = list(row.keys())
59
+ if row_keys != first_keys:
60
+ raise exc.ValidationError(
61
+ f"rows[{index}] has different keys. Expected {first_keys!r}, got {row_keys!r}"
62
+ )
63
+ return materialized
64
+
65
+
66
+ def build_assignment_list(columns: Sequence[str]) -> str:
67
+ return ", ".join(f"{quote_identifier(column)} = ?" for column in columns)
68
+
69
+
70
+ def build_placeholders(count: int) -> str:
71
+ return ", ".join("?" for _ in range(count))
72
+
73
+
74
+ def map_sqlite_exception(error: BaseException) -> exc.Error:
75
+ if isinstance(error, exc.Error):
76
+ return error
77
+ return exc.Error(str(error), original=error)
sqlite7/result.py ADDED
@@ -0,0 +1,22 @@
1
+ """Result primitives for sqlite7."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+ from typing import Any
7
+
8
+
9
+ @dataclass(slots=True, frozen=True)
10
+ class StatementResult:
11
+ """Structured metadata about a write statement.
12
+
13
+ Attributes:
14
+ rowcount: Number of affected rows reported by SQLite.
15
+ lastrowid: Last inserted row id, when available.
16
+ """
17
+
18
+ rowcount: int
19
+ lastrowid: int | None = None
20
+
21
+
22
+ RowDict = dict[str, Any]
sqlite7/transaction.py ADDED
@@ -0,0 +1,23 @@
1
+ """Transaction context manager for the synchronous sqlite7 client."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+ from typing import TYPE_CHECKING
7
+
8
+ if TYPE_CHECKING:
9
+ from .database import Database
10
+
11
+
12
+ @dataclass(slots=True)
13
+ class Transaction:
14
+ """Synchronous transaction context manager with savepoint nesting support."""
15
+
16
+ database: "Database"
17
+
18
+ def __enter__(self) -> "Database":
19
+ self.database._enter_transaction()
20
+ return self.database
21
+
22
+ def __exit__(self, exc_type, exc, tb) -> None:
23
+ self.database._exit_transaction(exc is None)
@@ -0,0 +1,72 @@
1
+ Metadata-Version: 2.4
2
+ Name: sqlite7
3
+ Version: 1.0.0
4
+ Summary: A DB-API 2.0 style interface for SQLite databases.
5
+ Home-page: https://github.com/joumaico/sqlite7
6
+ Author: Joumaico Maulas
7
+ Classifier: Development Status :: 5 - Production/Stable
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Requires-Python: >=3.11
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Dynamic: author
18
+ Dynamic: classifier
19
+ Dynamic: description
20
+ Dynamic: description-content-type
21
+ Dynamic: home-page
22
+ Dynamic: license-file
23
+ Dynamic: requires-python
24
+ Dynamic: summary
25
+
26
+ # SQLite7
27
+
28
+ SQLite7 is a DB-API 2.0 style interface for SQLite databases backed directly by the SQLite C library, with both synchronous and asynchronous APIs.
29
+
30
+ ## Installation
31
+
32
+ ```bash
33
+ pip install sqlite7
34
+ ```
35
+
36
+ **Requires:** Python 3.11+
37
+
38
+ ## Quick Example
39
+
40
+ ```python
41
+ from sqlite7 import connect
42
+
43
+ with open_db(":memory:") as db:
44
+ db.script(
45
+ '''
46
+ CREATE TABLE users (
47
+ id INTEGER PRIMARY KEY,
48
+ email TEXT UNIQUE NOT NULL,
49
+ name TEXT NOT NULL,
50
+ age INTEGER NOT NULL
51
+ );
52
+ '''
53
+ )
54
+
55
+ users = db.table("users")
56
+ users.insert({"email": "ada@example.com", "name": "Ada", "age": 36})
57
+ users.insert({"email": "grace@example.com", "name": "Grace", "age": 37})
58
+
59
+ rows = users.select(
60
+ columns=["id", "name"],
61
+ where="age >= ?",
62
+ params=[36],
63
+ order_by="id ASC",
64
+ limit=10,
65
+ offset=0,
66
+ )
67
+ print(rows)
68
+ ```
69
+
70
+ ## License
71
+
72
+ MIT License
@@ -0,0 +1,14 @@
1
+ sqlite7/__init__.py,sha256=FZwxF7EIuhlExdLhyZ9S4SuF5qP7CIDFMH_wpfSkVJk,1815
2
+ sqlite7/_native.py,sha256=7gfzdWsnVQVC-3VVGwnpuk89BaT0YXCbpcRhFa89yks,17325
3
+ sqlite7/async_database.py,sha256=KobQhvzYY4WXDbDSX5dotTOvAcAV82HnJf400evPCds,11607
4
+ sqlite7/database.py,sha256=XhjrW3aBddKuqzTz0OYzEQsObkxaydwxo4pY1ygPcfo,20979
5
+ sqlite7/dialect.py,sha256=Ss_AbfU-N5BaWxl-UYpvibvEyspWIEQUeSMqgOtGeF4,1052
6
+ sqlite7/exc.py,sha256=kOLbdXa-hHMbIqGzTGJLmdytjWVCuMR5NE3yMDrxIHs,2576
7
+ sqlite7/helpers.py,sha256=dJ_WAzQCjvq2kZ_rz1-1h5i1labSWLYGqPrRdowunUA,2644
8
+ sqlite7/result.py,sha256=sjd2LTysnc99UPXw0UDmazpr985HFLjhc_RRpTVkZps,467
9
+ sqlite7/transaction.py,sha256=C8DCW7WSJSp8Qz6rhg5eMyDhNgkQIBJC9rhSi8eXc6w,597
10
+ sqlite7-1.0.0.dist-info/licenses/LICENSE,sha256=_bXwoDAsoV0I5L_IvcwSFyAIfLndidmTylC_wtGwtlw,1072
11
+ sqlite7-1.0.0.dist-info/METADATA,sha256=P0DBdCHeC0vN_PE-WSUGoQNhA8uohxvMdHYZqa5B7x8,1753
12
+ sqlite7-1.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
13
+ sqlite7-1.0.0.dist-info/top_level.txt,sha256=Rq4T-KEoWV8G0XTWI_jao3gzWCFX26FmS3ZUVxm39yU,8
14
+ sqlite7-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Joumaico Maulas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ sqlite7