sqlspec 0.10.1__py3-none-any.whl → 0.11.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/adapters/adbc/config.py +1 -1
- sqlspec/adapters/adbc/driver.py +336 -165
- sqlspec/adapters/aiosqlite/driver.py +211 -126
- sqlspec/adapters/asyncmy/driver.py +164 -68
- sqlspec/adapters/asyncpg/config.py +3 -1
- sqlspec/adapters/asyncpg/driver.py +190 -231
- sqlspec/adapters/bigquery/driver.py +178 -169
- sqlspec/adapters/duckdb/driver.py +175 -84
- sqlspec/adapters/oracledb/driver.py +224 -90
- sqlspec/adapters/psqlpy/driver.py +267 -187
- sqlspec/adapters/psycopg/driver.py +138 -184
- sqlspec/adapters/sqlite/driver.py +153 -121
- sqlspec/base.py +57 -45
- sqlspec/extensions/litestar/__init__.py +3 -12
- sqlspec/extensions/litestar/config.py +22 -7
- sqlspec/extensions/litestar/handlers.py +142 -85
- sqlspec/extensions/litestar/plugin.py +9 -8
- sqlspec/extensions/litestar/providers.py +521 -0
- sqlspec/filters.py +214 -11
- sqlspec/mixins.py +152 -2
- sqlspec/statement.py +276 -271
- sqlspec/typing.py +18 -1
- sqlspec/utils/__init__.py +2 -2
- sqlspec/utils/singleton.py +35 -0
- sqlspec/utils/sync_tools.py +90 -151
- sqlspec/utils/text.py +68 -5
- {sqlspec-0.10.1.dist-info → sqlspec-0.11.0.dist-info}/METADATA +5 -1
- {sqlspec-0.10.1.dist-info → sqlspec-0.11.0.dist-info}/RECORD +31 -29
- {sqlspec-0.10.1.dist-info → sqlspec-0.11.0.dist-info}/WHEEL +0 -0
- {sqlspec-0.10.1.dist-info → sqlspec-0.11.0.dist-info}/licenses/LICENSE +0 -0
- {sqlspec-0.10.1.dist-info → sqlspec-0.11.0.dist-info}/licenses/NOTICE +0 -0
sqlspec/base.py
CHANGED
|
@@ -21,11 +21,13 @@ from typing import (
|
|
|
21
21
|
from sqlspec.exceptions import NotFoundError
|
|
22
22
|
from sqlspec.statement import SQLStatement
|
|
23
23
|
from sqlspec.typing import ConnectionT, ModelDTOT, PoolT, StatementParameterType, T
|
|
24
|
-
from sqlspec.utils.sync_tools import
|
|
24
|
+
from sqlspec.utils.sync_tools import ensure_async_
|
|
25
25
|
|
|
26
26
|
if TYPE_CHECKING:
|
|
27
27
|
from contextlib import AbstractAsyncContextManager, AbstractContextManager
|
|
28
28
|
|
|
29
|
+
from sqlspec.filters import StatementFilter
|
|
30
|
+
|
|
29
31
|
|
|
30
32
|
__all__ = (
|
|
31
33
|
"AsyncDatabaseConfig",
|
|
@@ -206,7 +208,7 @@ class SQLSpec:
|
|
|
206
208
|
for config in self._configs.values():
|
|
207
209
|
if config.support_connection_pooling and config.pool_instance is not None:
|
|
208
210
|
with contextlib.suppress(Exception):
|
|
209
|
-
|
|
211
|
+
ensure_async_(config.close_pool)()
|
|
210
212
|
|
|
211
213
|
@overload
|
|
212
214
|
def add_config(self, config: "SyncConfigT") -> "type[SyncConfigT]": ...
|
|
@@ -533,22 +535,34 @@ class CommonDriverAttributes(Generic[ConnectionT]):
|
|
|
533
535
|
return item_or_none
|
|
534
536
|
|
|
535
537
|
def _process_sql_params(
|
|
536
|
-
self,
|
|
538
|
+
self,
|
|
539
|
+
sql: str,
|
|
540
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
541
|
+
/,
|
|
542
|
+
*filters: "StatementFilter",
|
|
543
|
+
**kwargs: Any,
|
|
537
544
|
) -> "tuple[str, Optional[Union[tuple[Any, ...], list[Any], dict[str, Any]]]]":
|
|
538
545
|
"""Process SQL query and parameters using SQLStatement for validation and formatting.
|
|
539
546
|
|
|
540
547
|
Args:
|
|
541
548
|
sql: The SQL query string.
|
|
542
549
|
parameters: Parameters for the query.
|
|
550
|
+
*filters: Statement filters to apply.
|
|
543
551
|
**kwargs: Additional keyword arguments to merge with parameters if parameters is a dict.
|
|
544
552
|
|
|
545
553
|
Returns:
|
|
546
554
|
A tuple containing the processed SQL query and parameters.
|
|
547
555
|
"""
|
|
548
556
|
# Instantiate SQLStatement with parameters and kwargs for internal merging
|
|
549
|
-
stmt = SQLStatement(sql=sql, parameters=parameters,
|
|
557
|
+
stmt = SQLStatement(sql=sql, parameters=parameters, kwargs=kwargs or None)
|
|
558
|
+
|
|
559
|
+
# Apply all statement filters
|
|
560
|
+
for filter_obj in filters:
|
|
561
|
+
stmt = stmt.apply_filter(filter_obj)
|
|
562
|
+
|
|
550
563
|
# Process uses the merged parameters internally
|
|
551
|
-
|
|
564
|
+
processed = stmt.process()
|
|
565
|
+
return processed[0], processed[1] # Return only the SQL and parameters, discard the third element
|
|
552
566
|
|
|
553
567
|
|
|
554
568
|
class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generic[ConnectionT]):
|
|
@@ -564,7 +578,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
564
578
|
sql: str,
|
|
565
579
|
parameters: "Optional[StatementParameterType]" = None,
|
|
566
580
|
/,
|
|
567
|
-
|
|
581
|
+
*filters: "StatementFilter",
|
|
568
582
|
connection: "Optional[ConnectionT]" = None,
|
|
569
583
|
schema_type: None = None,
|
|
570
584
|
**kwargs: Any,
|
|
@@ -577,7 +591,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
577
591
|
sql: str,
|
|
578
592
|
parameters: "Optional[StatementParameterType]" = None,
|
|
579
593
|
/,
|
|
580
|
-
|
|
594
|
+
*filters: "StatementFilter",
|
|
581
595
|
connection: "Optional[ConnectionT]" = None,
|
|
582
596
|
schema_type: "type[ModelDTOT]",
|
|
583
597
|
**kwargs: Any,
|
|
@@ -589,7 +603,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
589
603
|
sql: str,
|
|
590
604
|
parameters: "Optional[StatementParameterType]" = None,
|
|
591
605
|
/,
|
|
592
|
-
|
|
606
|
+
*filters: "StatementFilter",
|
|
593
607
|
connection: "Optional[ConnectionT]" = None,
|
|
594
608
|
schema_type: Optional[type[ModelDTOT]] = None,
|
|
595
609
|
**kwargs: Any,
|
|
@@ -602,7 +616,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
602
616
|
sql: str,
|
|
603
617
|
parameters: "Optional[StatementParameterType]" = None,
|
|
604
618
|
/,
|
|
605
|
-
|
|
619
|
+
*filters: "StatementFilter",
|
|
606
620
|
connection: "Optional[ConnectionT]" = None,
|
|
607
621
|
schema_type: None = None,
|
|
608
622
|
**kwargs: Any,
|
|
@@ -615,7 +629,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
615
629
|
sql: str,
|
|
616
630
|
parameters: "Optional[StatementParameterType]" = None,
|
|
617
631
|
/,
|
|
618
|
-
|
|
632
|
+
*filters: "StatementFilter",
|
|
619
633
|
connection: "Optional[ConnectionT]" = None,
|
|
620
634
|
schema_type: "type[ModelDTOT]",
|
|
621
635
|
**kwargs: Any,
|
|
@@ -627,7 +641,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
627
641
|
sql: str,
|
|
628
642
|
parameters: Optional[StatementParameterType] = None,
|
|
629
643
|
/,
|
|
630
|
-
|
|
644
|
+
*filters: "StatementFilter",
|
|
631
645
|
connection: Optional[ConnectionT] = None,
|
|
632
646
|
schema_type: Optional[type[ModelDTOT]] = None,
|
|
633
647
|
**kwargs: Any,
|
|
@@ -640,7 +654,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
640
654
|
sql: str,
|
|
641
655
|
parameters: "Optional[StatementParameterType]" = None,
|
|
642
656
|
/,
|
|
643
|
-
|
|
657
|
+
*filters: "StatementFilter",
|
|
644
658
|
connection: "Optional[ConnectionT]" = None,
|
|
645
659
|
schema_type: None = None,
|
|
646
660
|
**kwargs: Any,
|
|
@@ -653,7 +667,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
653
667
|
sql: str,
|
|
654
668
|
parameters: "Optional[StatementParameterType]" = None,
|
|
655
669
|
/,
|
|
656
|
-
|
|
670
|
+
*filters: "StatementFilter",
|
|
657
671
|
connection: "Optional[ConnectionT]" = None,
|
|
658
672
|
schema_type: "type[ModelDTOT]",
|
|
659
673
|
**kwargs: Any,
|
|
@@ -665,7 +679,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
665
679
|
sql: str,
|
|
666
680
|
parameters: Optional[StatementParameterType] = None,
|
|
667
681
|
/,
|
|
668
|
-
|
|
682
|
+
*filters: "StatementFilter",
|
|
669
683
|
connection: Optional[ConnectionT] = None,
|
|
670
684
|
schema_type: Optional[type[ModelDTOT]] = None,
|
|
671
685
|
**kwargs: Any,
|
|
@@ -678,7 +692,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
678
692
|
sql: str,
|
|
679
693
|
parameters: "Optional[StatementParameterType]" = None,
|
|
680
694
|
/,
|
|
681
|
-
|
|
695
|
+
*filters: "StatementFilter",
|
|
682
696
|
connection: "Optional[ConnectionT]" = None,
|
|
683
697
|
schema_type: None = None,
|
|
684
698
|
**kwargs: Any,
|
|
@@ -691,7 +705,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
691
705
|
sql: str,
|
|
692
706
|
parameters: "Optional[StatementParameterType]" = None,
|
|
693
707
|
/,
|
|
694
|
-
|
|
708
|
+
*filters: "StatementFilter",
|
|
695
709
|
connection: "Optional[ConnectionT]" = None,
|
|
696
710
|
schema_type: "type[T]",
|
|
697
711
|
**kwargs: Any,
|
|
@@ -703,7 +717,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
703
717
|
sql: str,
|
|
704
718
|
parameters: Optional[StatementParameterType] = None,
|
|
705
719
|
/,
|
|
706
|
-
|
|
720
|
+
*filters: "StatementFilter",
|
|
707
721
|
connection: Optional[ConnectionT] = None,
|
|
708
722
|
schema_type: Optional[type[T]] = None,
|
|
709
723
|
**kwargs: Any,
|
|
@@ -716,7 +730,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
716
730
|
sql: str,
|
|
717
731
|
parameters: "Optional[StatementParameterType]" = None,
|
|
718
732
|
/,
|
|
719
|
-
|
|
733
|
+
*filters: "StatementFilter",
|
|
720
734
|
connection: "Optional[ConnectionT]" = None,
|
|
721
735
|
schema_type: None = None,
|
|
722
736
|
**kwargs: Any,
|
|
@@ -729,7 +743,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
729
743
|
sql: str,
|
|
730
744
|
parameters: "Optional[StatementParameterType]" = None,
|
|
731
745
|
/,
|
|
732
|
-
|
|
746
|
+
*filters: "StatementFilter",
|
|
733
747
|
connection: "Optional[ConnectionT]" = None,
|
|
734
748
|
schema_type: "type[T]",
|
|
735
749
|
**kwargs: Any,
|
|
@@ -741,7 +755,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
741
755
|
sql: str,
|
|
742
756
|
parameters: Optional[StatementParameterType] = None,
|
|
743
757
|
/,
|
|
744
|
-
|
|
758
|
+
*filters: "StatementFilter",
|
|
745
759
|
connection: Optional[ConnectionT] = None,
|
|
746
760
|
schema_type: Optional[type[T]] = None,
|
|
747
761
|
**kwargs: Any,
|
|
@@ -753,7 +767,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
753
767
|
sql: str,
|
|
754
768
|
parameters: Optional[StatementParameterType] = None,
|
|
755
769
|
/,
|
|
756
|
-
|
|
770
|
+
*filters: "StatementFilter",
|
|
757
771
|
connection: Optional[ConnectionT] = None,
|
|
758
772
|
**kwargs: Any,
|
|
759
773
|
) -> int: ...
|
|
@@ -765,7 +779,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
765
779
|
sql: str,
|
|
766
780
|
parameters: "Optional[StatementParameterType]" = None,
|
|
767
781
|
/,
|
|
768
|
-
|
|
782
|
+
*filters: "StatementFilter",
|
|
769
783
|
connection: "Optional[ConnectionT]" = None,
|
|
770
784
|
schema_type: None = None,
|
|
771
785
|
**kwargs: Any,
|
|
@@ -778,7 +792,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
778
792
|
sql: str,
|
|
779
793
|
parameters: "Optional[StatementParameterType]" = None,
|
|
780
794
|
/,
|
|
781
|
-
|
|
795
|
+
*filters: "StatementFilter",
|
|
782
796
|
connection: "Optional[ConnectionT]" = None,
|
|
783
797
|
schema_type: "type[ModelDTOT]",
|
|
784
798
|
**kwargs: Any,
|
|
@@ -790,7 +804,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
790
804
|
sql: str,
|
|
791
805
|
parameters: Optional[StatementParameterType] = None,
|
|
792
806
|
/,
|
|
793
|
-
|
|
807
|
+
*filters: "StatementFilter",
|
|
794
808
|
connection: Optional[ConnectionT] = None,
|
|
795
809
|
schema_type: Optional[type[ModelDTOT]] = None,
|
|
796
810
|
**kwargs: Any,
|
|
@@ -802,7 +816,6 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
802
816
|
sql: str,
|
|
803
817
|
parameters: Optional[StatementParameterType] = None,
|
|
804
818
|
/,
|
|
805
|
-
*,
|
|
806
819
|
connection: Optional[ConnectionT] = None,
|
|
807
820
|
**kwargs: Any,
|
|
808
821
|
) -> str: ...
|
|
@@ -821,7 +834,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
821
834
|
sql: str,
|
|
822
835
|
parameters: "Optional[StatementParameterType]" = None,
|
|
823
836
|
/,
|
|
824
|
-
|
|
837
|
+
*filters: "StatementFilter",
|
|
825
838
|
connection: "Optional[ConnectionT]" = None,
|
|
826
839
|
schema_type: None = None,
|
|
827
840
|
**kwargs: Any,
|
|
@@ -834,7 +847,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
834
847
|
sql: str,
|
|
835
848
|
parameters: "Optional[StatementParameterType]" = None,
|
|
836
849
|
/,
|
|
837
|
-
|
|
850
|
+
*filters: "StatementFilter",
|
|
838
851
|
connection: "Optional[ConnectionT]" = None,
|
|
839
852
|
schema_type: "type[ModelDTOT]",
|
|
840
853
|
**kwargs: Any,
|
|
@@ -846,7 +859,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
846
859
|
sql: str,
|
|
847
860
|
parameters: "Optional[StatementParameterType]" = None,
|
|
848
861
|
/,
|
|
849
|
-
|
|
862
|
+
*filters: "StatementFilter",
|
|
850
863
|
connection: "Optional[ConnectionT]" = None,
|
|
851
864
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
852
865
|
**kwargs: Any,
|
|
@@ -859,7 +872,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
859
872
|
sql: str,
|
|
860
873
|
parameters: "Optional[StatementParameterType]" = None,
|
|
861
874
|
/,
|
|
862
|
-
|
|
875
|
+
*filters: "StatementFilter",
|
|
863
876
|
connection: "Optional[ConnectionT]" = None,
|
|
864
877
|
schema_type: None = None,
|
|
865
878
|
**kwargs: Any,
|
|
@@ -872,7 +885,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
872
885
|
sql: str,
|
|
873
886
|
parameters: "Optional[StatementParameterType]" = None,
|
|
874
887
|
/,
|
|
875
|
-
|
|
888
|
+
*filters: "StatementFilter",
|
|
876
889
|
connection: "Optional[ConnectionT]" = None,
|
|
877
890
|
schema_type: "type[ModelDTOT]",
|
|
878
891
|
**kwargs: Any,
|
|
@@ -884,7 +897,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
884
897
|
sql: str,
|
|
885
898
|
parameters: "Optional[StatementParameterType]" = None,
|
|
886
899
|
/,
|
|
887
|
-
|
|
900
|
+
*filters: "StatementFilter",
|
|
888
901
|
connection: "Optional[ConnectionT]" = None,
|
|
889
902
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
890
903
|
**kwargs: Any,
|
|
@@ -897,7 +910,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
897
910
|
sql: str,
|
|
898
911
|
parameters: "Optional[StatementParameterType]" = None,
|
|
899
912
|
/,
|
|
900
|
-
|
|
913
|
+
*filters: "StatementFilter",
|
|
901
914
|
connection: "Optional[ConnectionT]" = None,
|
|
902
915
|
schema_type: None = None,
|
|
903
916
|
**kwargs: Any,
|
|
@@ -910,7 +923,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
910
923
|
sql: str,
|
|
911
924
|
parameters: "Optional[StatementParameterType]" = None,
|
|
912
925
|
/,
|
|
913
|
-
|
|
926
|
+
*filters: "StatementFilter",
|
|
914
927
|
connection: "Optional[ConnectionT]" = None,
|
|
915
928
|
schema_type: "type[ModelDTOT]",
|
|
916
929
|
**kwargs: Any,
|
|
@@ -922,7 +935,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
922
935
|
sql: str,
|
|
923
936
|
parameters: "Optional[StatementParameterType]" = None,
|
|
924
937
|
/,
|
|
925
|
-
|
|
938
|
+
*filters: "StatementFilter",
|
|
926
939
|
connection: "Optional[ConnectionT]" = None,
|
|
927
940
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
928
941
|
**kwargs: Any,
|
|
@@ -935,7 +948,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
935
948
|
sql: str,
|
|
936
949
|
parameters: "Optional[StatementParameterType]" = None,
|
|
937
950
|
/,
|
|
938
|
-
|
|
951
|
+
*filters: "StatementFilter",
|
|
939
952
|
connection: "Optional[ConnectionT]" = None,
|
|
940
953
|
schema_type: None = None,
|
|
941
954
|
**kwargs: Any,
|
|
@@ -948,7 +961,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
948
961
|
sql: str,
|
|
949
962
|
parameters: "Optional[StatementParameterType]" = None,
|
|
950
963
|
/,
|
|
951
|
-
|
|
964
|
+
*filters: "StatementFilter",
|
|
952
965
|
connection: "Optional[ConnectionT]" = None,
|
|
953
966
|
schema_type: "type[T]",
|
|
954
967
|
**kwargs: Any,
|
|
@@ -960,7 +973,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
960
973
|
sql: str,
|
|
961
974
|
parameters: "Optional[StatementParameterType]" = None,
|
|
962
975
|
/,
|
|
963
|
-
|
|
976
|
+
*filters: "StatementFilter",
|
|
964
977
|
connection: "Optional[ConnectionT]" = None,
|
|
965
978
|
schema_type: "Optional[type[T]]" = None,
|
|
966
979
|
**kwargs: Any,
|
|
@@ -973,7 +986,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
973
986
|
sql: str,
|
|
974
987
|
parameters: "Optional[StatementParameterType]" = None,
|
|
975
988
|
/,
|
|
976
|
-
|
|
989
|
+
*filters: "StatementFilter",
|
|
977
990
|
connection: "Optional[ConnectionT]" = None,
|
|
978
991
|
schema_type: None = None,
|
|
979
992
|
**kwargs: Any,
|
|
@@ -986,7 +999,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
986
999
|
sql: str,
|
|
987
1000
|
parameters: "Optional[StatementParameterType]" = None,
|
|
988
1001
|
/,
|
|
989
|
-
|
|
1002
|
+
*filters: "StatementFilter",
|
|
990
1003
|
connection: "Optional[ConnectionT]" = None,
|
|
991
1004
|
schema_type: "type[T]",
|
|
992
1005
|
**kwargs: Any,
|
|
@@ -998,7 +1011,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
998
1011
|
sql: str,
|
|
999
1012
|
parameters: "Optional[StatementParameterType]" = None,
|
|
1000
1013
|
/,
|
|
1001
|
-
|
|
1014
|
+
*filters: "StatementFilter",
|
|
1002
1015
|
connection: "Optional[ConnectionT]" = None,
|
|
1003
1016
|
schema_type: "Optional[type[T]]" = None,
|
|
1004
1017
|
**kwargs: Any,
|
|
@@ -1010,7 +1023,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
1010
1023
|
sql: str,
|
|
1011
1024
|
parameters: "Optional[StatementParameterType]" = None,
|
|
1012
1025
|
/,
|
|
1013
|
-
|
|
1026
|
+
*filters: "StatementFilter",
|
|
1014
1027
|
connection: "Optional[ConnectionT]" = None,
|
|
1015
1028
|
**kwargs: Any,
|
|
1016
1029
|
) -> int: ...
|
|
@@ -1022,7 +1035,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
1022
1035
|
sql: str,
|
|
1023
1036
|
parameters: "Optional[StatementParameterType]" = None,
|
|
1024
1037
|
/,
|
|
1025
|
-
|
|
1038
|
+
*filters: "StatementFilter",
|
|
1026
1039
|
connection: "Optional[ConnectionT]" = None,
|
|
1027
1040
|
schema_type: None = None,
|
|
1028
1041
|
**kwargs: Any,
|
|
@@ -1035,7 +1048,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
1035
1048
|
sql: str,
|
|
1036
1049
|
parameters: "Optional[StatementParameterType]" = None,
|
|
1037
1050
|
/,
|
|
1038
|
-
|
|
1051
|
+
*filters: "StatementFilter",
|
|
1039
1052
|
connection: "Optional[ConnectionT]" = None,
|
|
1040
1053
|
schema_type: "type[ModelDTOT]",
|
|
1041
1054
|
**kwargs: Any,
|
|
@@ -1047,7 +1060,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
1047
1060
|
sql: str,
|
|
1048
1061
|
parameters: "Optional[StatementParameterType]" = None,
|
|
1049
1062
|
/,
|
|
1050
|
-
|
|
1063
|
+
*filters: "StatementFilter",
|
|
1051
1064
|
connection: "Optional[ConnectionT]" = None,
|
|
1052
1065
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
1053
1066
|
**kwargs: Any,
|
|
@@ -1059,7 +1072,6 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
1059
1072
|
sql: str,
|
|
1060
1073
|
parameters: "Optional[StatementParameterType]" = None,
|
|
1061
1074
|
/,
|
|
1062
|
-
*,
|
|
1063
1075
|
connection: "Optional[ConnectionT]" = None,
|
|
1064
1076
|
**kwargs: Any,
|
|
1065
1077
|
) -> str: ...
|
|
@@ -1,19 +1,10 @@
|
|
|
1
|
+
from sqlspec.extensions.litestar import handlers, providers
|
|
1
2
|
from sqlspec.extensions.litestar.config import DatabaseConfig
|
|
2
|
-
from sqlspec.extensions.litestar.handlers import (
|
|
3
|
-
autocommit_handler_maker,
|
|
4
|
-
connection_provider_maker,
|
|
5
|
-
lifespan_handler_maker,
|
|
6
|
-
manual_handler_maker,
|
|
7
|
-
pool_provider_maker,
|
|
8
|
-
)
|
|
9
3
|
from sqlspec.extensions.litestar.plugin import SQLSpec
|
|
10
4
|
|
|
11
5
|
__all__ = (
|
|
12
6
|
"DatabaseConfig",
|
|
13
7
|
"SQLSpec",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"lifespan_handler_maker",
|
|
17
|
-
"manual_handler_maker",
|
|
18
|
-
"pool_provider_maker",
|
|
8
|
+
"handlers",
|
|
9
|
+
"providers",
|
|
19
10
|
)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from dataclasses import dataclass, field
|
|
2
|
-
from typing import TYPE_CHECKING, Callable, Literal, Optional, Union
|
|
2
|
+
from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, Union
|
|
3
3
|
|
|
4
4
|
from sqlspec.exceptions import ImproperConfigurationError
|
|
5
5
|
from sqlspec.extensions.litestar.handlers import (
|
|
@@ -12,7 +12,7 @@ from sqlspec.extensions.litestar.handlers import (
|
|
|
12
12
|
)
|
|
13
13
|
|
|
14
14
|
if TYPE_CHECKING:
|
|
15
|
-
from collections.abc import Awaitable
|
|
15
|
+
from collections.abc import AsyncGenerator, Awaitable
|
|
16
16
|
from contextlib import AbstractAsyncContextManager
|
|
17
17
|
|
|
18
18
|
from litestar import Litestar
|
|
@@ -29,6 +29,15 @@ DEFAULT_CONNECTION_KEY = "db_connection"
|
|
|
29
29
|
DEFAULT_POOL_KEY = "db_pool"
|
|
30
30
|
DEFAULT_SESSION_KEY = "db_session"
|
|
31
31
|
|
|
32
|
+
__all__ = (
|
|
33
|
+
"DEFAULT_COMMIT_MODE",
|
|
34
|
+
"DEFAULT_CONNECTION_KEY",
|
|
35
|
+
"DEFAULT_POOL_KEY",
|
|
36
|
+
"DEFAULT_SESSION_KEY",
|
|
37
|
+
"CommitMode",
|
|
38
|
+
"DatabaseConfig",
|
|
39
|
+
)
|
|
40
|
+
|
|
32
41
|
|
|
33
42
|
@dataclass
|
|
34
43
|
class DatabaseConfig:
|
|
@@ -39,9 +48,11 @@ class DatabaseConfig:
|
|
|
39
48
|
commit_mode: "CommitMode" = field(default=DEFAULT_COMMIT_MODE)
|
|
40
49
|
extra_commit_statuses: "Optional[set[int]]" = field(default=None)
|
|
41
50
|
extra_rollback_statuses: "Optional[set[int]]" = field(default=None)
|
|
42
|
-
connection_provider: "Callable[[State,Scope],
|
|
51
|
+
connection_provider: "Callable[[State, Scope], AsyncGenerator[ConnectionT, None]]" = field( # pyright: ignore[reportGeneralTypeIssues]
|
|
52
|
+
init=False, repr=False, hash=False
|
|
53
|
+
)
|
|
43
54
|
pool_provider: "Callable[[State,Scope], Awaitable[PoolT]]" = field(init=False, repr=False, hash=False) # pyright: ignore[reportGeneralTypeIssues]
|
|
44
|
-
session_provider: "Callable[[
|
|
55
|
+
session_provider: "Callable[[Any], AsyncGenerator[DriverT, None]]" = field(init=False, repr=False, hash=False) # pyright: ignore[reportGeneralTypeIssues]
|
|
45
56
|
before_send_handler: "BeforeMessageSendHookHandler" = field(init=False, repr=False, hash=False)
|
|
46
57
|
lifespan_handler: "Callable[[Litestar], AbstractAsyncContextManager[None]]" = field(
|
|
47
58
|
init=False,
|
|
@@ -74,6 +85,10 @@ class DatabaseConfig:
|
|
|
74
85
|
msg = f"Invalid commit mode: {self.commit_mode}" # type: ignore[unreachable]
|
|
75
86
|
raise ImproperConfigurationError(detail=msg)
|
|
76
87
|
self.lifespan_handler = lifespan_handler_maker(config=self.config, pool_key=self.pool_key)
|
|
77
|
-
self.connection_provider = connection_provider_maker(
|
|
78
|
-
|
|
79
|
-
|
|
88
|
+
self.connection_provider = connection_provider_maker(
|
|
89
|
+
connection_key=self.connection_key, pool_key=self.pool_key, config=self.config
|
|
90
|
+
)
|
|
91
|
+
self.pool_provider = pool_provider_maker(config=self.config, pool_key=self.pool_key)
|
|
92
|
+
self.session_provider = session_provider_maker(
|
|
93
|
+
config=self.config, connection_dependency_key=self.connection_key
|
|
94
|
+
)
|