sqlspec 0.3.0__py3-none-any.whl → 0.5.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.
Potentially problematic release.
This version of sqlspec might be problematic. Click here for more details.
- sqlspec/_serialization.py +1 -1
- sqlspec/_typing.py +58 -2
- sqlspec/adapters/adbc/config.py +8 -10
- sqlspec/adapters/aiosqlite/config.py +4 -21
- sqlspec/adapters/asyncmy/config.py +12 -25
- sqlspec/adapters/asyncpg/config.py +15 -21
- sqlspec/adapters/duckdb/__init__.py +3 -0
- sqlspec/adapters/duckdb/config.py +130 -29
- sqlspec/adapters/oracledb/__init__.py +1 -1
- sqlspec/adapters/oracledb/config/_asyncio.py +14 -14
- sqlspec/adapters/oracledb/config/_common.py +9 -9
- sqlspec/adapters/oracledb/config/_sync.py +9 -13
- sqlspec/adapters/psycopg/config/__init__.py +2 -2
- sqlspec/adapters/psycopg/config/_async.py +8 -14
- sqlspec/adapters/psycopg/config/_common.py +6 -5
- sqlspec/adapters/psycopg/config/_sync.py +8 -14
- sqlspec/adapters/sqlite/config.py +6 -23
- sqlspec/base.py +87 -0
- sqlspec/filters.py +8 -5
- sqlspec/typing.py +248 -32
- sqlspec/utils/deprecation.py +111 -0
- sqlspec/utils/fixtures.py +66 -0
- sqlspec/utils/module_loader.py +94 -0
- sqlspec/utils/text.py +46 -0
- sqlspec-0.5.0.dist-info/METADATA +126 -0
- sqlspec-0.5.0.dist-info/RECORD +44 -0
- sqlspec/config.py +0 -16
- sqlspec/utils/dataclass.py +0 -138
- sqlspec/utils/empty.py +0 -18
- sqlspec-0.3.0.dist-info/METADATA +0 -84
- sqlspec-0.3.0.dist-info/RECORD +0 -42
- {sqlspec-0.3.0.dist-info → sqlspec-0.5.0.dist-info}/WHEEL +0 -0
- {sqlspec-0.3.0.dist-info → sqlspec-0.5.0.dist-info}/licenses/NOTICE +0 -0
sqlspec/utils/text.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""General utility functions."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
import unicodedata
|
|
7
|
+
|
|
8
|
+
__all__ = (
|
|
9
|
+
"check_email",
|
|
10
|
+
"slugify",
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def check_email(email: str) -> str:
|
|
15
|
+
"""Validate an email."""
|
|
16
|
+
if "@" not in email:
|
|
17
|
+
msg = "Invalid email!"
|
|
18
|
+
raise ValueError(msg)
|
|
19
|
+
return email.lower()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def slugify(value: str, allow_unicode: bool = False, separator: str | None = None) -> str:
|
|
23
|
+
"""Slugify.
|
|
24
|
+
|
|
25
|
+
Convert to ASCII if ``allow_unicode`` is ``False``. Convert spaces or repeated
|
|
26
|
+
dashes to single dashes. Remove characters that aren't alphanumerics,
|
|
27
|
+
underscores, or hyphens. Convert to lowercase. Also strip leading and
|
|
28
|
+
trailing whitespace, dashes, and underscores.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
value (str): the string to slugify
|
|
32
|
+
allow_unicode (bool, optional): allow unicode characters in slug. Defaults to False.
|
|
33
|
+
separator (str, optional): by default a `-` is used to delimit word boundaries.
|
|
34
|
+
Set this to configure something different.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
str: a slugified string of the value parameter
|
|
38
|
+
"""
|
|
39
|
+
if allow_unicode:
|
|
40
|
+
value = unicodedata.normalize("NFKC", value)
|
|
41
|
+
else:
|
|
42
|
+
value = unicodedata.normalize("NFKD", value).encode("ascii", "ignore").decode("ascii")
|
|
43
|
+
value = re.sub(r"[^\w\s-]", "", value.lower())
|
|
44
|
+
if separator is not None:
|
|
45
|
+
return re.sub(r"[-\s]+", "-", value).strip("-_").replace("-", separator)
|
|
46
|
+
return re.sub(r"[-\s]+", "-", value).strip("-_")
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sqlspec
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: SQL Experiments in Python
|
|
5
|
+
Author-email: Cody Fincher <cody@litestar.dev>
|
|
6
|
+
Maintainer-email: Litestar Developers <hello@litestar.dev>
|
|
7
|
+
License-File: NOTICE
|
|
8
|
+
Requires-Python: <4.0,>=3.9
|
|
9
|
+
Requires-Dist: eval-type-backport; python_version < '3.10'
|
|
10
|
+
Requires-Dist: sqlglot
|
|
11
|
+
Requires-Dist: typing-extensions
|
|
12
|
+
Provides-Extra: adbc
|
|
13
|
+
Requires-Dist: adbc-driver-manager; extra == 'adbc'
|
|
14
|
+
Requires-Dist: pyarrow; extra == 'adbc'
|
|
15
|
+
Provides-Extra: aioodbc
|
|
16
|
+
Requires-Dist: aioodbc; extra == 'aioodbc'
|
|
17
|
+
Provides-Extra: aiosqlite
|
|
18
|
+
Requires-Dist: aiosqlite; extra == 'aiosqlite'
|
|
19
|
+
Provides-Extra: asyncmy
|
|
20
|
+
Requires-Dist: asyncmy; extra == 'asyncmy'
|
|
21
|
+
Provides-Extra: asyncpg
|
|
22
|
+
Requires-Dist: asyncpg; extra == 'asyncpg'
|
|
23
|
+
Provides-Extra: bigquery
|
|
24
|
+
Requires-Dist: google-cloud-bigquery; extra == 'bigquery'
|
|
25
|
+
Provides-Extra: duckdb
|
|
26
|
+
Requires-Dist: duckdb; extra == 'duckdb'
|
|
27
|
+
Provides-Extra: fastapi
|
|
28
|
+
Requires-Dist: fastapi; extra == 'fastapi'
|
|
29
|
+
Provides-Extra: flask
|
|
30
|
+
Requires-Dist: flask; extra == 'flask'
|
|
31
|
+
Provides-Extra: litestar
|
|
32
|
+
Requires-Dist: litestar; extra == 'litestar'
|
|
33
|
+
Provides-Extra: msgspec
|
|
34
|
+
Requires-Dist: msgspec; extra == 'msgspec'
|
|
35
|
+
Provides-Extra: oracledb
|
|
36
|
+
Requires-Dist: oracledb; extra == 'oracledb'
|
|
37
|
+
Provides-Extra: performance
|
|
38
|
+
Requires-Dist: google-re2; (sys_platform == 'linux') and extra == 'performance'
|
|
39
|
+
Requires-Dist: sqlglot[rs]; extra == 'performance'
|
|
40
|
+
Provides-Extra: psycopg
|
|
41
|
+
Requires-Dist: psycopg[binary,pool]; extra == 'psycopg'
|
|
42
|
+
Provides-Extra: pydantic
|
|
43
|
+
Requires-Dist: pydantic; extra == 'pydantic'
|
|
44
|
+
Provides-Extra: pymssql
|
|
45
|
+
Requires-Dist: pymssql; extra == 'pymssql'
|
|
46
|
+
Provides-Extra: pymysql
|
|
47
|
+
Requires-Dist: pymysql; extra == 'pymysql'
|
|
48
|
+
Provides-Extra: spanner
|
|
49
|
+
Requires-Dist: google-cloud-spanner; extra == 'spanner'
|
|
50
|
+
Description-Content-Type: text/markdown
|
|
51
|
+
|
|
52
|
+
# SQLSpec
|
|
53
|
+
|
|
54
|
+
## A Query Mapper for Python
|
|
55
|
+
|
|
56
|
+
SQLSpec is an experimental Python library designed to streamline and modernize your SQL interactions across a variety of database systems. While still in its early stages, SQLSpec aims to provide a flexible, typed, and extensible interface for working with SQL in Python.
|
|
57
|
+
|
|
58
|
+
**Note**: SQLSpec is currently under active development and the API is subject to change. It is not yet ready for production use. Contributions are welcome!
|
|
59
|
+
|
|
60
|
+
### Core Features (Planned but subject to change, removal or redesign)
|
|
61
|
+
|
|
62
|
+
- **Consistent Database Session Interface**: Provides a consistent connectivity interface for interacting with one or more database systems, including SQLite, Postgres, DuckDB, MySQL, Oracle, SQL Server, Spanner, BigQuery, and more.
|
|
63
|
+
- **Emphasis on RAW SQL and Minimal Abstractions and Performance**: SQLSpec is a library for working with SQL in Python. It's goals are to offer minimal abstractions between the user and the database. It does not aim to be an ORM library.
|
|
64
|
+
- **Type-Safe Queries**: Quickly map SQL queries to typed objects using libraries such as Pydantic, Msqgspec, Attrs, etc.
|
|
65
|
+
- **Extensible Design**: Easily add support for new database dialects or extend existing functionality to meet your specific needs. Easily add support for async and sync database drivers.
|
|
66
|
+
- **Minimal Dependencies**: SQLSpec is designed to be lightweight and can run on it's own or with other libraries such as `litestar`, `fastapi`, `flask` and more. (Contributions welcome!)
|
|
67
|
+
- **Dynamic Query Manipulation**: Easily apply filters to pre-defined queries with a fluent, Pythonic API. Safely manipulate queries without the risk of SQL injection.
|
|
68
|
+
- **Dialect Validation and Conversion**: Use `sqlglot` to validate your SQL against specific dialects and seamlessly convert between them.
|
|
69
|
+
- **Support for Async and Sync Database Drivers**: SQLSpec supports both async and sync database drivers, allowing you to choose the style that best fits your application.
|
|
70
|
+
|
|
71
|
+
### What SQLSpec Is Not (Yet)
|
|
72
|
+
|
|
73
|
+
SQLSpec is a work in progress. While it offers a solid foundation for modern SQL interactions, it does not yet include every feature you might find in a mature ORM or database toolkit. The focus is on building a robust, flexible core that can be extended over time.
|
|
74
|
+
|
|
75
|
+
### Inspiration and Future Direction
|
|
76
|
+
|
|
77
|
+
SQLSpec originally drew inspiration from features found in the `aiosql` library. This is a great library for working with and executed SQL stored in files. It's unclear how much of an overlap there will be between the two libraries, but it's possible that some features will be contributed back to `aiosql` where appropriate.
|
|
78
|
+
|
|
79
|
+
### Current Focus: Universal Connectivity
|
|
80
|
+
|
|
81
|
+
The primary goal at this stage is to establish a **native connectivity interface** that works seamlessly across all supported database environments. This means you can connect to any of the supported databases using a consistent API, regardless of the underlying driver or dialect.
|
|
82
|
+
|
|
83
|
+
### Adapters: Completed, In Progress, and Planned
|
|
84
|
+
|
|
85
|
+
This list is not final. If you have a driver you'd like to see added, please open an issue or submit a PR!
|
|
86
|
+
|
|
87
|
+
| Driver | Database | Mode | Status |
|
|
88
|
+
| :----------------------------------------------------------------------------------------------------------- | :--------- | :------ | :--------- |
|
|
89
|
+
| [`adbc`](https://arrow.apache.org/adbc/) | Postgres | Sync | ✅ |
|
|
90
|
+
| [`adbc`](https://arrow.apache.org/adbc/) | SQLite | Sync | ✅ |
|
|
91
|
+
| [`adbc`](https://arrow.apache.org/adbc/) | Snowflake | Sync | ✅ |
|
|
92
|
+
| [`adbc`](https://arrow.apache.org/adbc/) | DuckDB | Sync | ✅ |
|
|
93
|
+
| [`asyncpg`](https://magicstack.github.io/asyncpg/current/) | PostgreSQL | Async | ✅ |
|
|
94
|
+
| [`psycopg`](https://www.psycopg.org/) | PostgreSQL | Sync | ✅ |
|
|
95
|
+
| [`psycopg`](https://www.psycopg.org/) | PostgreSQL | Async | ✅ |
|
|
96
|
+
| [`aiosqlite`](https://github.com/omnilib/aiosqlite) | SQLite | Async | ✅ |
|
|
97
|
+
| `sqlite3` | SQLite | Sync | ✅ |
|
|
98
|
+
| [`oracledb`](https://oracle.github.io/python-oracledb/) | Oracle | Async | ✅ |
|
|
99
|
+
| [`oracledb`](https://oracle.github.io/python-oracledb/) | Oracle | Sync | ✅ |
|
|
100
|
+
| [`duckdb`](https://duckdb.org/) | DuckDB | Sync | ✅ |
|
|
101
|
+
| [`bigquery`](https://googleapis.dev/python/bigquery/latest/index.html) | BigQuery | Sync | 🗓️ Planned |
|
|
102
|
+
| [`spanner`](https://googleapis.dev/python/spanner/latest/index.html) | Spanner | Sync | 🗓️ Planned |
|
|
103
|
+
| [`sqlserver`](https://docs.microsoft.com/en-us/sql/connect/python/pyodbc/python-sql-driver-for-pyodbc?view=sql-server-ver16) | SQL Server | Sync | 🗓️ Planned |
|
|
104
|
+
| [`mysql`](https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysql-connector-python.html) | MySQL | Sync | 🗓️ Planned |
|
|
105
|
+
| [`snowflake`](https://docs.snowflake.com)
|
|
106
|
+
|
|
107
|
+
### Proposed Project Structure
|
|
108
|
+
|
|
109
|
+
- `sqlspec/`:
|
|
110
|
+
- `adapters/`: Contains all database drivers and associated configuration.
|
|
111
|
+
- `extensions/`:
|
|
112
|
+
- `litestar/`: Future home of `litestar` integration.
|
|
113
|
+
- `fastapi/`: Future home of `fastapi` integration.
|
|
114
|
+
- `flask/`: Future home of `flask` integration.
|
|
115
|
+
- `*/`: Future home of your favorite framework integration 🔌 ✨
|
|
116
|
+
- `base.py`: Contains base protocols for database configurations.
|
|
117
|
+
- `filters.py`: Contains the `Filter` class which is used to apply filters to pre-defined SQL queries.
|
|
118
|
+
- `utils/`: Contains utility functions used throughout the project.
|
|
119
|
+
- `exceptions.py`: Contains custom exceptions for SQLSpec.
|
|
120
|
+
- `typing.py`: Contains type hints, type guards and several facades for optional libraries that are not required for the core functionality of SQLSpec.
|
|
121
|
+
|
|
122
|
+
### Get Involved
|
|
123
|
+
|
|
124
|
+
SQLSpec is an open-source project, and contributions are welcome! Whether you're interested in adding support for new databases, improving the query interface, or simply providing feedback, your input is valuable.
|
|
125
|
+
|
|
126
|
+
**Disclaimer**: SQLSpec is under active development. Expect changes and improvements as the project evolves.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
sqlspec/__init__.py,sha256=U4S_2y3zgLZVfMenHRaJFBW8yqh2mUBuI291LGQVOJ8,35
|
|
2
|
+
sqlspec/__metadata__.py,sha256=Vw99abV_UQNVH2jB0IBa9-8emyZQcXm1J9eMtLxFX2Y,496
|
|
3
|
+
sqlspec/_serialization.py,sha256=NnJajyQU2I1QCwE0eOBcUbG1E25aiNLOPqMk6S-52Sg,850
|
|
4
|
+
sqlspec/_typing.py,sha256=pJkUkgy3zra1SFV96F4PTWStWyRNV44rrZEyrtQfgbw,4235
|
|
5
|
+
sqlspec/base.py,sha256=rvdylQ2YyTx8iyqgpk04FmkFwNpd_qZytUs4mvJ6MBw,2793
|
|
6
|
+
sqlspec/exceptions.py,sha256=fhCOILBj0J7HJP67BNSC0d9YUbW8QpZPXM55xJJzE8A,3039
|
|
7
|
+
sqlspec/filters.py,sha256=K6AVBo1OTLVXZZiLuM7n_44MQKUT0DzZe9roiAsTX-4,3614
|
|
8
|
+
sqlspec/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
sqlspec/typing.py,sha256=6g8lkdYRAFWW_4Vct9D2QNOaw0AYyHHMXT7jbdT6aeI,13665
|
|
10
|
+
sqlspec/adapters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
sqlspec/adapters/adbc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
|
+
sqlspec/adapters/adbc/config.py,sha256=DRlcJGo2haN_UKTnp4zplC_UV6yf5XwyHu0Z2L5lrSM,1690
|
|
13
|
+
sqlspec/adapters/aiosqlite/__init__.py,sha256=PLqWg24l3TooJvqA0Xf1WErrxtqwo8DEoL_Zp2iSCzs,68
|
|
14
|
+
sqlspec/adapters/aiosqlite/config.py,sha256=ou3aAB2JzTkkFplTCwdXKTVHMPfoGsTR1CGdI9BeSM4,3861
|
|
15
|
+
sqlspec/adapters/asyncmy/__init__.py,sha256=o0R_Azae3FHiSZ1TQ5ZjyCneDOuvnEeMjmSkhuiKoWo,103
|
|
16
|
+
sqlspec/adapters/asyncmy/config.py,sha256=YWsw8PBDMae-oVle-szKBzZYFq9ayIhDL7UdLLM7ybk,5696
|
|
17
|
+
sqlspec/adapters/asyncpg/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
+
sqlspec/adapters/asyncpg/config.py,sha256=3kDG4nAtdRU8gC-AJvifwwIokDtrI63G6aYcMKwNHZQ,6226
|
|
19
|
+
sqlspec/adapters/duckdb/__init__.py,sha256=-IC44IEsRPbz16HpQFAGkV7Bfbow8CGMruBsdMEIEf4,85
|
|
20
|
+
sqlspec/adapters/duckdb/config.py,sha256=sqKD_FUdPMQKZad15qX9VIMQ2CdTd5x6Jors43YxQbE,8206
|
|
21
|
+
sqlspec/adapters/oracledb/__init__.py,sha256=f7P24wnDhDoEwgO0pJbutqqN2L0WUZWqVJIAcvphb4M,300
|
|
22
|
+
sqlspec/adapters/oracledb/config/__init__.py,sha256=XoHgInT4IbXjDg5ax3ncuUoVvnYB5qQjI-Ib7gwSycU,338
|
|
23
|
+
sqlspec/adapters/oracledb/config/_asyncio.py,sha256=Hr28ogOUED1kRIPYQE73hA6fpthDTJ3rxFg4-PO2ZtU,3327
|
|
24
|
+
sqlspec/adapters/oracledb/config/_common.py,sha256=5y8G_aYjJAGAVSQufMQlGHnlSW5cqeiBmz4W5lCceOQ,6244
|
|
25
|
+
sqlspec/adapters/oracledb/config/_sync.py,sha256=QsPNqiO4GKD1oouAL6ulApKJx6_r5_Sjcy2udrOK1JU,3232
|
|
26
|
+
sqlspec/adapters/psycopg/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
27
|
+
sqlspec/adapters/psycopg/config/__init__.py,sha256=y4s9ezhFu764yQIqm_qlE_HYJiumTRN_dDfewwRGSkI,342
|
|
28
|
+
sqlspec/adapters/psycopg/config/_async.py,sha256=d3nZCn6pjxUCWqEdHKrdWsu7wkR5b4dkEygm3zR_gTk,2828
|
|
29
|
+
sqlspec/adapters/psycopg/config/_common.py,sha256=p4oh2nqwvN1IAM8M9OqPWjBdPRw2-Qow3RIx-houjYc,2794
|
|
30
|
+
sqlspec/adapters/psycopg/config/_sync.py,sha256=8HhvhDufeFtuKROkKAW96Pl2lVB_5WPBBrXK9AJz3uE,2707
|
|
31
|
+
sqlspec/adapters/sqlite/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
32
|
+
sqlspec/adapters/sqlite/config.py,sha256=tNF3a3wQDzZaa1UEVKrhtVmIjF-8mqTGhQKUhJi5tMM,3750
|
|
33
|
+
sqlspec/extensions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
34
|
+
sqlspec/extensions/litestar/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
35
|
+
sqlspec/extensions/litestar/plugin.py,sha256=oiBFfRffNvy_vnGptREd6JYZGB6Yd98KbtVct_VcW0A,837
|
|
36
|
+
sqlspec/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
37
|
+
sqlspec/utils/deprecation.py,sha256=MbmIs1Qz1ZIITW7TrCE-wa1nmO0x4nGqtM1AShmKYT8,3900
|
|
38
|
+
sqlspec/utils/fixtures.py,sha256=FbySeVuU0E_B885ulQh_J5CO_5eL51beH9X0y9zjsYU,2196
|
|
39
|
+
sqlspec/utils/module_loader.py,sha256=Qe52uUgAwHSMJC2aKQwMs0F1XSbwJARF-8QdASItH_M,2720
|
|
40
|
+
sqlspec/utils/text.py,sha256=FnlNj7drS6JwcFc3dd7BPUBP6JDSmxTZmxnZPAB-Yq0,1479
|
|
41
|
+
sqlspec-0.5.0.dist-info/METADATA,sha256=0ROm7C3bz5eykaLTrEG4Yed9AR82cN0VVL5D-GJ26zQ,8932
|
|
42
|
+
sqlspec-0.5.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
43
|
+
sqlspec-0.5.0.dist-info/licenses/NOTICE,sha256=Lyir8ozXWov7CyYS4huVaOCNrtgL17P-bNV-5daLntQ,1634
|
|
44
|
+
sqlspec-0.5.0.dist-info/RECORD,,
|
sqlspec/config.py
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
from dataclasses import dataclass
|
|
2
|
-
|
|
3
|
-
__all__ = (
|
|
4
|
-
"GenericDatabaseConfig",
|
|
5
|
-
"GenericPoolConfig",
|
|
6
|
-
)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
@dataclass
|
|
10
|
-
class GenericDatabaseConfig:
|
|
11
|
-
"""Generic Database Configuration."""
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
@dataclass
|
|
15
|
-
class GenericPoolConfig:
|
|
16
|
-
"""Generic Database Pool Configuration."""
|
sqlspec/utils/dataclass.py
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from dataclasses import Field, fields
|
|
4
|
-
from typing import TYPE_CHECKING, ClassVar, Protocol, runtime_checkable
|
|
5
|
-
|
|
6
|
-
from typing_extensions import TypeGuard
|
|
7
|
-
|
|
8
|
-
from sqlspec.utils.empty import Empty
|
|
9
|
-
|
|
10
|
-
if TYPE_CHECKING:
|
|
11
|
-
from collections.abc import Iterable
|
|
12
|
-
from collections.abc import Set as AbstractSet
|
|
13
|
-
from typing import Any
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
__all__ = (
|
|
17
|
-
"extract_dataclass_fields",
|
|
18
|
-
"extract_dataclass_items",
|
|
19
|
-
"is_dataclass_instance",
|
|
20
|
-
"simple_asdict",
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
@runtime_checkable
|
|
25
|
-
class DataclassProtocol(Protocol):
|
|
26
|
-
"""Protocol for instance checking dataclasses"""
|
|
27
|
-
|
|
28
|
-
__dataclass_fields__: ClassVar[dict[str, Any]]
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def is_dataclass_instance(obj: Any) -> TypeGuard[DataclassProtocol]:
|
|
32
|
-
"""Check if an object is a dataclass instance.
|
|
33
|
-
|
|
34
|
-
Args:
|
|
35
|
-
obj: An object to check.
|
|
36
|
-
|
|
37
|
-
Returns:
|
|
38
|
-
True if the object is a dataclass instance.
|
|
39
|
-
"""
|
|
40
|
-
return hasattr(type(obj), "__dataclass_fields__")
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
def extract_dataclass_fields(
|
|
44
|
-
dt: DataclassProtocol,
|
|
45
|
-
exclude_none: bool = False,
|
|
46
|
-
exclude_empty: bool = False,
|
|
47
|
-
include: AbstractSet[str] | None = None,
|
|
48
|
-
exclude: AbstractSet[str] | None = None,
|
|
49
|
-
) -> tuple[Field[Any], ...]:
|
|
50
|
-
"""Extract dataclass fields.
|
|
51
|
-
|
|
52
|
-
Args:
|
|
53
|
-
dt: A dataclass instance.
|
|
54
|
-
exclude_none: Whether to exclude None values.
|
|
55
|
-
exclude_empty: Whether to exclude Empty values.
|
|
56
|
-
include: An iterable of fields to include.
|
|
57
|
-
exclude: An iterable of fields to exclude.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
Returns:
|
|
61
|
-
A tuple of dataclass fields.
|
|
62
|
-
"""
|
|
63
|
-
include = include or set()
|
|
64
|
-
exclude = exclude or set()
|
|
65
|
-
|
|
66
|
-
if common := (include & exclude):
|
|
67
|
-
msg = f"Fields {common} are both included and excluded."
|
|
68
|
-
raise ValueError(msg)
|
|
69
|
-
|
|
70
|
-
dataclass_fields: Iterable[Field[Any]] = fields(dt)
|
|
71
|
-
if exclude_none:
|
|
72
|
-
dataclass_fields = (field for field in dataclass_fields if getattr(dt, field.name) is not None)
|
|
73
|
-
if exclude_empty:
|
|
74
|
-
dataclass_fields = (field for field in dataclass_fields if getattr(dt, field.name) is not Empty)
|
|
75
|
-
if include:
|
|
76
|
-
dataclass_fields = (field for field in dataclass_fields if field.name in include)
|
|
77
|
-
if exclude:
|
|
78
|
-
dataclass_fields = (field for field in dataclass_fields if field.name not in exclude)
|
|
79
|
-
|
|
80
|
-
return tuple(dataclass_fields)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
def extract_dataclass_items(
|
|
84
|
-
dt: DataclassProtocol,
|
|
85
|
-
exclude_none: bool = False,
|
|
86
|
-
exclude_empty: bool = False,
|
|
87
|
-
include: AbstractSet[str] | None = None,
|
|
88
|
-
exclude: AbstractSet[str] | None = None,
|
|
89
|
-
) -> tuple[tuple[str, Any], ...]:
|
|
90
|
-
"""Extract dataclass name, value pairs.
|
|
91
|
-
|
|
92
|
-
Unlike the 'asdict' method exports by the stdlib, this function does not pickle values.
|
|
93
|
-
|
|
94
|
-
Args:
|
|
95
|
-
dt: A dataclass instance.
|
|
96
|
-
exclude_none: Whether to exclude None values.
|
|
97
|
-
exclude_empty: Whether to exclude Empty values.
|
|
98
|
-
include: An iterable of fields to include.
|
|
99
|
-
exclude: An iterable of fields to exclude.
|
|
100
|
-
|
|
101
|
-
Returns:
|
|
102
|
-
A tuple of key/value pairs.
|
|
103
|
-
"""
|
|
104
|
-
dataclass_fields = extract_dataclass_fields(dt, exclude_none, exclude_empty, include, exclude)
|
|
105
|
-
return tuple((field.name, getattr(dt, field.name)) for field in dataclass_fields)
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
def simple_asdict(
|
|
109
|
-
obj: DataclassProtocol,
|
|
110
|
-
exclude_none: bool = False,
|
|
111
|
-
exclude_empty: bool = False,
|
|
112
|
-
convert_nested: bool = True,
|
|
113
|
-
exclude: set[str] | None = None,
|
|
114
|
-
) -> dict[str, Any]:
|
|
115
|
-
"""Convert a dataclass to a dictionary.
|
|
116
|
-
|
|
117
|
-
This method has important differences to the standard library version:
|
|
118
|
-
- it does not deepcopy values
|
|
119
|
-
- it does not recurse into collections
|
|
120
|
-
|
|
121
|
-
Args:
|
|
122
|
-
obj: A dataclass instance.
|
|
123
|
-
exclude_none: Whether to exclude None values.
|
|
124
|
-
exclude_empty: Whether to exclude Empty values.
|
|
125
|
-
convert_nested: Whether to recursively convert nested dataclasses.
|
|
126
|
-
exclude: An iterable of fields to exclude.
|
|
127
|
-
|
|
128
|
-
Returns:
|
|
129
|
-
A dictionary of key/value pairs.
|
|
130
|
-
"""
|
|
131
|
-
ret = {}
|
|
132
|
-
for field in extract_dataclass_fields(obj, exclude_none, exclude_empty, exclude=exclude):
|
|
133
|
-
value = getattr(obj, field.name)
|
|
134
|
-
if is_dataclass_instance(value) and convert_nested:
|
|
135
|
-
ret[field.name] = simple_asdict(value, exclude_none, exclude_empty)
|
|
136
|
-
else:
|
|
137
|
-
ret[field.name] = getattr(obj, field.name)
|
|
138
|
-
return ret
|
sqlspec/utils/empty.py
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from enum import Enum
|
|
4
|
-
from typing import Final, Literal, Union
|
|
5
|
-
|
|
6
|
-
from sqlspec.typing import UnsetType
|
|
7
|
-
|
|
8
|
-
__all__ = ("Empty", "EmptyType")
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class _EmptyEnum(Enum):
|
|
12
|
-
"""A sentinel enum used as placeholder."""
|
|
13
|
-
|
|
14
|
-
EMPTY = 0
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
EmptyType = Union[Literal[_EmptyEnum.EMPTY], UnsetType]
|
|
18
|
-
Empty: Final = _EmptyEnum.EMPTY
|
sqlspec-0.3.0.dist-info/METADATA
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: sqlspec
|
|
3
|
-
Version: 0.3.0
|
|
4
|
-
Summary: SQL Experiments in Python
|
|
5
|
-
Author-email: Cody Fincher <cody@litestar.dev>
|
|
6
|
-
Maintainer-email: Litestar Developers <hello@litestar.dev>
|
|
7
|
-
License-File: NOTICE
|
|
8
|
-
Requires-Python: <4.0,>=3.9
|
|
9
|
-
Requires-Dist: eval-type-backport; python_version <= '3.9'
|
|
10
|
-
Requires-Dist: sqlglot
|
|
11
|
-
Requires-Dist: typing-extensions>=4.0.0
|
|
12
|
-
Provides-Extra: adbc
|
|
13
|
-
Requires-Dist: adbc-driver-manager; extra == 'adbc'
|
|
14
|
-
Requires-Dist: pyarrow; extra == 'adbc'
|
|
15
|
-
Provides-Extra: aioodbc
|
|
16
|
-
Requires-Dist: aioodbc; extra == 'aioodbc'
|
|
17
|
-
Provides-Extra: aiosqlite
|
|
18
|
-
Requires-Dist: aiosqlite; extra == 'aiosqlite'
|
|
19
|
-
Provides-Extra: asyncmy
|
|
20
|
-
Requires-Dist: asyncmy; extra == 'asyncmy'
|
|
21
|
-
Provides-Extra: asyncpg
|
|
22
|
-
Requires-Dist: asyncpg; extra == 'asyncpg'
|
|
23
|
-
Provides-Extra: bigquery
|
|
24
|
-
Requires-Dist: google-cloud-bigquery; extra == 'bigquery'
|
|
25
|
-
Provides-Extra: duckdb
|
|
26
|
-
Requires-Dist: duckdb; extra == 'duckdb'
|
|
27
|
-
Provides-Extra: fastapi
|
|
28
|
-
Requires-Dist: fastapi; extra == 'fastapi'
|
|
29
|
-
Provides-Extra: flask
|
|
30
|
-
Requires-Dist: flask; extra == 'flask'
|
|
31
|
-
Provides-Extra: litestar
|
|
32
|
-
Requires-Dist: litestar; extra == 'litestar'
|
|
33
|
-
Provides-Extra: msgspec
|
|
34
|
-
Requires-Dist: msgspec; extra == 'msgspec'
|
|
35
|
-
Provides-Extra: oracledb
|
|
36
|
-
Requires-Dist: oracledb; extra == 'oracledb'
|
|
37
|
-
Provides-Extra: performance
|
|
38
|
-
Requires-Dist: google-re2; (sys_platform == 'linux') and extra == 'performance'
|
|
39
|
-
Requires-Dist: sqlglot[rs]; extra == 'performance'
|
|
40
|
-
Provides-Extra: psycopg
|
|
41
|
-
Requires-Dist: psycopg[binary,pool]; extra == 'psycopg'
|
|
42
|
-
Provides-Extra: pydantic
|
|
43
|
-
Requires-Dist: pydantic; extra == 'pydantic'
|
|
44
|
-
Provides-Extra: pymssql
|
|
45
|
-
Requires-Dist: pymssql; extra == 'pymssql'
|
|
46
|
-
Provides-Extra: pymysql
|
|
47
|
-
Requires-Dist: pymysql; extra == 'pymysql'
|
|
48
|
-
Provides-Extra: spanner
|
|
49
|
-
Requires-Dist: google-cloud-spanner; extra == 'spanner'
|
|
50
|
-
Description-Content-Type: text/markdown
|
|
51
|
-
|
|
52
|
-
<!-- markdownlint-disable -->
|
|
53
|
-
<p align="center">
|
|
54
|
-
<!-- github-banner-start -->
|
|
55
|
-
<img src="https://raw.githubusercontent.com/litestar-org/branding/main/assets/Branding%20-%20SVG%20-%20Transparent/Logo%20-%20Banner%20-%20Inline%20-%20Light.svg#gh-light-mode-only" alt="Litestar Logo - Light" width="100%" height="auto" />
|
|
56
|
-
<img src="https://raw.githubusercontent.com/litestar-org/branding/main/assets/Branding%20-%20SVG%20-%20Transparent/Logo%20-%20Banner%20-%20Inline%20-%20Dark.svg#gh-dark-mode-only" alt="Litestar Logo - Dark" width="100%" height="auto" />
|
|
57
|
-
<!-- github-banner-end -->
|
|
58
|
-
|
|
59
|
-
</p>
|
|
60
|
-
<div align="center">
|
|
61
|
-
<!-- markdownlint-restore -->
|
|
62
|
-
|
|
63
|
-
# SQLSpec
|
|
64
|
-
|
|
65
|
-
SQL Experiments in Python
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
## Minimal SQL Abstractions for Python.
|
|
69
|
-
|
|
70
|
-
- Modern: Typed and Extensible
|
|
71
|
-
- Multi-database: SQLite, Postgres, DuckDB, MySQL, Oracle, SQL Server, Spanner, Big Query, and more...
|
|
72
|
-
- Easy ability to manipulate and add filters to queries
|
|
73
|
-
- Validate and Convert between dialects with `sqlglot`
|
|
74
|
-
- and more...
|
|
75
|
-
|
|
76
|
-
## Can it do `X`?
|
|
77
|
-
|
|
78
|
-
- Probably not currently; but, if it makes sense we can add enhancements.
|
|
79
|
-
|
|
80
|
-
## Inspiration
|
|
81
|
-
|
|
82
|
-
`aiosql` is the primary influence for this library. However, I wanted to be able to use the query interface from `aiosql` a bit more flexibly.
|
|
83
|
-
|
|
84
|
-
Why not add it to `aiosql`? Where it makes sense, many of these changes will likely get submitted to aiosql as a PR (`spanner` and `bigquery` drivers are likely the starting point.)
|
sqlspec-0.3.0.dist-info/RECORD
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
sqlspec/__init__.py,sha256=U4S_2y3zgLZVfMenHRaJFBW8yqh2mUBuI291LGQVOJ8,35
|
|
2
|
-
sqlspec/__metadata__.py,sha256=Vw99abV_UQNVH2jB0IBa9-8emyZQcXm1J9eMtLxFX2Y,496
|
|
3
|
-
sqlspec/_serialization.py,sha256=OL4x0Rz5UjF7RgAKqhYChi5qSS_ImtaVrIlA4DhIKUE,824
|
|
4
|
-
sqlspec/_typing.py,sha256=8tk4KqqO8OLDe-PIow2oaAnzgHOiFb74Mx7yuoAZUgI,2814
|
|
5
|
-
sqlspec/config.py,sha256=BOX_V_q2MOP33tK0ISpYaiQJt3zrvK4D_JIBD9FOixY,272
|
|
6
|
-
sqlspec/exceptions.py,sha256=fhCOILBj0J7HJP67BNSC0d9YUbW8QpZPXM55xJJzE8A,3039
|
|
7
|
-
sqlspec/filters.py,sha256=UtDJVpABSxHLkadiswMcneBsvawmWsz3Bq7wLxLJn74,3454
|
|
8
|
-
sqlspec/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
-
sqlspec/typing.py,sha256=9gXd4qAxZxejXo1NpGDKflsmWu5kQomB3fps3l4EbZs,7289
|
|
10
|
-
sqlspec/adapters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
-
sqlspec/adapters/adbc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
|
-
sqlspec/adapters/adbc/config.py,sha256=lCOoewYM0u9GHHGkux0FbSRAri4oIi91_Zrs_x3FkdQ,1745
|
|
13
|
-
sqlspec/adapters/aiosqlite/__init__.py,sha256=PLqWg24l3TooJvqA0Xf1WErrxtqwo8DEoL_Zp2iSCzs,68
|
|
14
|
-
sqlspec/adapters/aiosqlite/config.py,sha256=SM1nkRnrIzeUUMtL1cmMEh75epkCKtII1D-Wjgnc7ZY,4308
|
|
15
|
-
sqlspec/adapters/asyncmy/__init__.py,sha256=o0R_Azae3FHiSZ1TQ5ZjyCneDOuvnEeMjmSkhuiKoWo,103
|
|
16
|
-
sqlspec/adapters/asyncmy/config.py,sha256=0_0tdx7JvTIR1DZuaHeLg8IaK5Rv3li6dVKVOf8k_AI,5956
|
|
17
|
-
sqlspec/adapters/asyncpg/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
-
sqlspec/adapters/asyncpg/config.py,sha256=Q1TgWtI2lrn0SDtP8KTVfJ2f1I6XhOUPSujKngWIf5A,6306
|
|
19
|
-
sqlspec/adapters/duckdb/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
|
-
sqlspec/adapters/duckdb/config.py,sha256=2LfJnZYMcbXAR9BQ66Y9rhh7R_u6PI2GHApGo1Oy04k,3461
|
|
21
|
-
sqlspec/adapters/oracledb/__init__.py,sha256=fFQ2xOxFcgpr-ug4AVv430irnJgBRUINvt4sL3qzyBw,275
|
|
22
|
-
sqlspec/adapters/oracledb/config/__init__.py,sha256=XoHgInT4IbXjDg5ax3ncuUoVvnYB5qQjI-Ib7gwSycU,338
|
|
23
|
-
sqlspec/adapters/oracledb/config/_asyncio.py,sha256=qB-1jPwjNdHYrDYjjQqR-q1KqMKFXESk-T9aZtdrwDI,3280
|
|
24
|
-
sqlspec/adapters/oracledb/config/_common.py,sha256=VwMbZAX-jJ2kyAbtgRUOWDvO12nXsb68wO-3d3L9Wz4,6183
|
|
25
|
-
sqlspec/adapters/oracledb/config/_sync.py,sha256=m_OkErwBKvQrFU6Q9PuduSJu_vHbmZl1gWYbpw6b22I,3268
|
|
26
|
-
sqlspec/adapters/psycopg/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
27
|
-
sqlspec/adapters/psycopg/config/__init__.py,sha256=pXI9Pa2VYESTchPgM3tt5kFF8tsmgq-ksZRGR6pgiUQ,280
|
|
28
|
-
sqlspec/adapters/psycopg/config/_async.py,sha256=mdqFanrnodTq8u3THim3KkiNmEoIQpsKmBpJSaRiGTc,3004
|
|
29
|
-
sqlspec/adapters/psycopg/config/_common.py,sha256=F4rwAlAcVM2HgDVnD87Pda0DjVV-oqzDUd0TofqnUL0,2766
|
|
30
|
-
sqlspec/adapters/psycopg/config/_sync.py,sha256=YILMCmOpGX4E62hepuM0WgT7aPQpwbZpUwjAonmjUYc,2860
|
|
31
|
-
sqlspec/adapters/sqlite/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
32
|
-
sqlspec/adapters/sqlite/config.py,sha256=0c_eN01mEcM-OIiaDgs-4fM20z03QivANGxAuxJOisA,4117
|
|
33
|
-
sqlspec/extensions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
34
|
-
sqlspec/extensions/litestar/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
35
|
-
sqlspec/extensions/litestar/plugin.py,sha256=oiBFfRffNvy_vnGptREd6JYZGB6Yd98KbtVct_VcW0A,837
|
|
36
|
-
sqlspec/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
37
|
-
sqlspec/utils/dataclass.py,sha256=g88yP0Pi3EiF8N-Npuo-D6QpPExCLuUvJCO0U_3lHkQ,4301
|
|
38
|
-
sqlspec/utils/empty.py,sha256=u5KC3HUF7MolHYs9kSt7Uq-jTIl0x9gJqf-jX0y5_BY,349
|
|
39
|
-
sqlspec-0.3.0.dist-info/METADATA,sha256=DCx_OsG0w07rjQx01g2av9VxMgQZsmDWcZl0nsqJU8A,3222
|
|
40
|
-
sqlspec-0.3.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
41
|
-
sqlspec-0.3.0.dist-info/licenses/NOTICE,sha256=Lyir8ozXWov7CyYS4huVaOCNrtgL17P-bNV-5daLntQ,1634
|
|
42
|
-
sqlspec-0.3.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|