sqlspec 0.10.1__py3-none-any.whl → 0.11.1__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 +340 -192
- sqlspec/adapters/aiosqlite/driver.py +183 -129
- sqlspec/adapters/asyncmy/driver.py +168 -88
- sqlspec/adapters/asyncpg/config.py +3 -1
- sqlspec/adapters/asyncpg/driver.py +208 -259
- sqlspec/adapters/bigquery/driver.py +184 -264
- sqlspec/adapters/duckdb/driver.py +172 -110
- sqlspec/adapters/oracledb/driver.py +274 -160
- sqlspec/adapters/psqlpy/driver.py +274 -211
- sqlspec/adapters/psycopg/driver.py +196 -283
- sqlspec/adapters/sqlite/driver.py +154 -142
- sqlspec/base.py +56 -85
- 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 +215 -11
- sqlspec/mixins.py +161 -12
- 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.1.dist-info}/METADATA +8 -1
- {sqlspec-0.10.1.dist-info → sqlspec-0.11.1.dist-info}/RECORD +31 -29
- {sqlspec-0.10.1.dist-info → sqlspec-0.11.1.dist-info}/WHEEL +0 -0
- {sqlspec-0.10.1.dist-info → sqlspec-0.11.1.dist-info}/licenses/LICENSE +0 -0
- {sqlspec-0.10.1.dist-info → sqlspec-0.11.1.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,33 @@ 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
|
+
*filters: "StatementFilter",
|
|
542
|
+
**kwargs: Any,
|
|
537
543
|
) -> "tuple[str, Optional[Union[tuple[Any, ...], list[Any], dict[str, Any]]]]":
|
|
538
544
|
"""Process SQL query and parameters using SQLStatement for validation and formatting.
|
|
539
545
|
|
|
540
546
|
Args:
|
|
541
547
|
sql: The SQL query string.
|
|
542
548
|
parameters: Parameters for the query.
|
|
549
|
+
*filters: Statement filters to apply.
|
|
543
550
|
**kwargs: Additional keyword arguments to merge with parameters if parameters is a dict.
|
|
544
551
|
|
|
545
552
|
Returns:
|
|
546
553
|
A tuple containing the processed SQL query and parameters.
|
|
547
554
|
"""
|
|
548
555
|
# Instantiate SQLStatement with parameters and kwargs for internal merging
|
|
549
|
-
stmt = SQLStatement(sql=sql, parameters=parameters,
|
|
556
|
+
stmt = SQLStatement(sql=sql, parameters=parameters, kwargs=kwargs or None)
|
|
557
|
+
|
|
558
|
+
# Apply all statement filters
|
|
559
|
+
for filter_obj in filters:
|
|
560
|
+
stmt = stmt.apply_filter(filter_obj)
|
|
561
|
+
|
|
550
562
|
# Process uses the merged parameters internally
|
|
551
|
-
|
|
563
|
+
processed = stmt.process()
|
|
564
|
+
return processed[0], processed[1] # Return only the SQL and parameters, discard the third element
|
|
552
565
|
|
|
553
566
|
|
|
554
567
|
class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generic[ConnectionT]):
|
|
@@ -563,8 +576,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
563
576
|
self,
|
|
564
577
|
sql: str,
|
|
565
578
|
parameters: "Optional[StatementParameterType]" = None,
|
|
566
|
-
|
|
567
|
-
*,
|
|
579
|
+
*filters: "StatementFilter",
|
|
568
580
|
connection: "Optional[ConnectionT]" = None,
|
|
569
581
|
schema_type: None = None,
|
|
570
582
|
**kwargs: Any,
|
|
@@ -576,8 +588,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
576
588
|
self,
|
|
577
589
|
sql: str,
|
|
578
590
|
parameters: "Optional[StatementParameterType]" = None,
|
|
579
|
-
|
|
580
|
-
*,
|
|
591
|
+
*filters: "StatementFilter",
|
|
581
592
|
connection: "Optional[ConnectionT]" = None,
|
|
582
593
|
schema_type: "type[ModelDTOT]",
|
|
583
594
|
**kwargs: Any,
|
|
@@ -588,8 +599,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
588
599
|
self,
|
|
589
600
|
sql: str,
|
|
590
601
|
parameters: "Optional[StatementParameterType]" = None,
|
|
591
|
-
|
|
592
|
-
*,
|
|
602
|
+
*filters: "StatementFilter",
|
|
593
603
|
connection: "Optional[ConnectionT]" = None,
|
|
594
604
|
schema_type: Optional[type[ModelDTOT]] = None,
|
|
595
605
|
**kwargs: Any,
|
|
@@ -601,8 +611,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
601
611
|
self,
|
|
602
612
|
sql: str,
|
|
603
613
|
parameters: "Optional[StatementParameterType]" = None,
|
|
604
|
-
|
|
605
|
-
*,
|
|
614
|
+
*filters: "StatementFilter",
|
|
606
615
|
connection: "Optional[ConnectionT]" = None,
|
|
607
616
|
schema_type: None = None,
|
|
608
617
|
**kwargs: Any,
|
|
@@ -614,8 +623,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
614
623
|
self,
|
|
615
624
|
sql: str,
|
|
616
625
|
parameters: "Optional[StatementParameterType]" = None,
|
|
617
|
-
|
|
618
|
-
*,
|
|
626
|
+
*filters: "StatementFilter",
|
|
619
627
|
connection: "Optional[ConnectionT]" = None,
|
|
620
628
|
schema_type: "type[ModelDTOT]",
|
|
621
629
|
**kwargs: Any,
|
|
@@ -626,8 +634,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
626
634
|
self,
|
|
627
635
|
sql: str,
|
|
628
636
|
parameters: Optional[StatementParameterType] = None,
|
|
629
|
-
|
|
630
|
-
*,
|
|
637
|
+
*filters: "StatementFilter",
|
|
631
638
|
connection: Optional[ConnectionT] = None,
|
|
632
639
|
schema_type: Optional[type[ModelDTOT]] = None,
|
|
633
640
|
**kwargs: Any,
|
|
@@ -639,8 +646,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
639
646
|
self,
|
|
640
647
|
sql: str,
|
|
641
648
|
parameters: "Optional[StatementParameterType]" = None,
|
|
642
|
-
|
|
643
|
-
*,
|
|
649
|
+
*filters: "StatementFilter",
|
|
644
650
|
connection: "Optional[ConnectionT]" = None,
|
|
645
651
|
schema_type: None = None,
|
|
646
652
|
**kwargs: Any,
|
|
@@ -652,8 +658,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
652
658
|
self,
|
|
653
659
|
sql: str,
|
|
654
660
|
parameters: "Optional[StatementParameterType]" = None,
|
|
655
|
-
|
|
656
|
-
*,
|
|
661
|
+
*filters: "StatementFilter",
|
|
657
662
|
connection: "Optional[ConnectionT]" = None,
|
|
658
663
|
schema_type: "type[ModelDTOT]",
|
|
659
664
|
**kwargs: Any,
|
|
@@ -664,8 +669,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
664
669
|
self,
|
|
665
670
|
sql: str,
|
|
666
671
|
parameters: Optional[StatementParameterType] = None,
|
|
667
|
-
|
|
668
|
-
*,
|
|
672
|
+
*filters: "StatementFilter",
|
|
669
673
|
connection: Optional[ConnectionT] = None,
|
|
670
674
|
schema_type: Optional[type[ModelDTOT]] = None,
|
|
671
675
|
**kwargs: Any,
|
|
@@ -677,8 +681,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
677
681
|
self,
|
|
678
682
|
sql: str,
|
|
679
683
|
parameters: "Optional[StatementParameterType]" = None,
|
|
680
|
-
|
|
681
|
-
*,
|
|
684
|
+
*filters: "StatementFilter",
|
|
682
685
|
connection: "Optional[ConnectionT]" = None,
|
|
683
686
|
schema_type: None = None,
|
|
684
687
|
**kwargs: Any,
|
|
@@ -690,8 +693,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
690
693
|
self,
|
|
691
694
|
sql: str,
|
|
692
695
|
parameters: "Optional[StatementParameterType]" = None,
|
|
693
|
-
|
|
694
|
-
*,
|
|
696
|
+
*filters: "StatementFilter",
|
|
695
697
|
connection: "Optional[ConnectionT]" = None,
|
|
696
698
|
schema_type: "type[T]",
|
|
697
699
|
**kwargs: Any,
|
|
@@ -702,8 +704,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
702
704
|
self,
|
|
703
705
|
sql: str,
|
|
704
706
|
parameters: Optional[StatementParameterType] = None,
|
|
705
|
-
|
|
706
|
-
*,
|
|
707
|
+
*filters: "StatementFilter",
|
|
707
708
|
connection: Optional[ConnectionT] = None,
|
|
708
709
|
schema_type: Optional[type[T]] = None,
|
|
709
710
|
**kwargs: Any,
|
|
@@ -715,8 +716,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
715
716
|
self,
|
|
716
717
|
sql: str,
|
|
717
718
|
parameters: "Optional[StatementParameterType]" = None,
|
|
718
|
-
|
|
719
|
-
*,
|
|
719
|
+
*filters: "StatementFilter",
|
|
720
720
|
connection: "Optional[ConnectionT]" = None,
|
|
721
721
|
schema_type: None = None,
|
|
722
722
|
**kwargs: Any,
|
|
@@ -728,8 +728,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
728
728
|
self,
|
|
729
729
|
sql: str,
|
|
730
730
|
parameters: "Optional[StatementParameterType]" = None,
|
|
731
|
-
|
|
732
|
-
*,
|
|
731
|
+
*filters: "StatementFilter",
|
|
733
732
|
connection: "Optional[ConnectionT]" = None,
|
|
734
733
|
schema_type: "type[T]",
|
|
735
734
|
**kwargs: Any,
|
|
@@ -740,8 +739,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
740
739
|
self,
|
|
741
740
|
sql: str,
|
|
742
741
|
parameters: Optional[StatementParameterType] = None,
|
|
743
|
-
|
|
744
|
-
*,
|
|
742
|
+
*filters: "StatementFilter",
|
|
745
743
|
connection: Optional[ConnectionT] = None,
|
|
746
744
|
schema_type: Optional[type[T]] = None,
|
|
747
745
|
**kwargs: Any,
|
|
@@ -752,8 +750,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
752
750
|
self,
|
|
753
751
|
sql: str,
|
|
754
752
|
parameters: Optional[StatementParameterType] = None,
|
|
755
|
-
|
|
756
|
-
*,
|
|
753
|
+
*filters: "StatementFilter",
|
|
757
754
|
connection: Optional[ConnectionT] = None,
|
|
758
755
|
**kwargs: Any,
|
|
759
756
|
) -> int: ...
|
|
@@ -764,8 +761,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
764
761
|
self,
|
|
765
762
|
sql: str,
|
|
766
763
|
parameters: "Optional[StatementParameterType]" = None,
|
|
767
|
-
|
|
768
|
-
*,
|
|
764
|
+
*filters: "StatementFilter",
|
|
769
765
|
connection: "Optional[ConnectionT]" = None,
|
|
770
766
|
schema_type: None = None,
|
|
771
767
|
**kwargs: Any,
|
|
@@ -777,8 +773,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
777
773
|
self,
|
|
778
774
|
sql: str,
|
|
779
775
|
parameters: "Optional[StatementParameterType]" = None,
|
|
780
|
-
|
|
781
|
-
*,
|
|
776
|
+
*filters: "StatementFilter",
|
|
782
777
|
connection: "Optional[ConnectionT]" = None,
|
|
783
778
|
schema_type: "type[ModelDTOT]",
|
|
784
779
|
**kwargs: Any,
|
|
@@ -789,8 +784,7 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
789
784
|
self,
|
|
790
785
|
sql: str,
|
|
791
786
|
parameters: Optional[StatementParameterType] = None,
|
|
792
|
-
|
|
793
|
-
*,
|
|
787
|
+
*filters: "StatementFilter",
|
|
794
788
|
connection: Optional[ConnectionT] = None,
|
|
795
789
|
schema_type: Optional[type[ModelDTOT]] = None,
|
|
796
790
|
**kwargs: Any,
|
|
@@ -801,8 +795,6 @@ class SyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Generi
|
|
|
801
795
|
self,
|
|
802
796
|
sql: str,
|
|
803
797
|
parameters: Optional[StatementParameterType] = None,
|
|
804
|
-
/,
|
|
805
|
-
*,
|
|
806
798
|
connection: Optional[ConnectionT] = None,
|
|
807
799
|
**kwargs: Any,
|
|
808
800
|
) -> str: ...
|
|
@@ -820,8 +812,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
820
812
|
self,
|
|
821
813
|
sql: str,
|
|
822
814
|
parameters: "Optional[StatementParameterType]" = None,
|
|
823
|
-
|
|
824
|
-
*,
|
|
815
|
+
*filters: "StatementFilter",
|
|
825
816
|
connection: "Optional[ConnectionT]" = None,
|
|
826
817
|
schema_type: None = None,
|
|
827
818
|
**kwargs: Any,
|
|
@@ -833,8 +824,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
833
824
|
self,
|
|
834
825
|
sql: str,
|
|
835
826
|
parameters: "Optional[StatementParameterType]" = None,
|
|
836
|
-
|
|
837
|
-
*,
|
|
827
|
+
*filters: "StatementFilter",
|
|
838
828
|
connection: "Optional[ConnectionT]" = None,
|
|
839
829
|
schema_type: "type[ModelDTOT]",
|
|
840
830
|
**kwargs: Any,
|
|
@@ -845,8 +835,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
845
835
|
self,
|
|
846
836
|
sql: str,
|
|
847
837
|
parameters: "Optional[StatementParameterType]" = None,
|
|
848
|
-
|
|
849
|
-
*,
|
|
838
|
+
*filters: "StatementFilter",
|
|
850
839
|
connection: "Optional[ConnectionT]" = None,
|
|
851
840
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
852
841
|
**kwargs: Any,
|
|
@@ -858,8 +847,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
858
847
|
self,
|
|
859
848
|
sql: str,
|
|
860
849
|
parameters: "Optional[StatementParameterType]" = None,
|
|
861
|
-
|
|
862
|
-
*,
|
|
850
|
+
*filters: "StatementFilter",
|
|
863
851
|
connection: "Optional[ConnectionT]" = None,
|
|
864
852
|
schema_type: None = None,
|
|
865
853
|
**kwargs: Any,
|
|
@@ -871,8 +859,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
871
859
|
self,
|
|
872
860
|
sql: str,
|
|
873
861
|
parameters: "Optional[StatementParameterType]" = None,
|
|
874
|
-
|
|
875
|
-
*,
|
|
862
|
+
*filters: "StatementFilter",
|
|
876
863
|
connection: "Optional[ConnectionT]" = None,
|
|
877
864
|
schema_type: "type[ModelDTOT]",
|
|
878
865
|
**kwargs: Any,
|
|
@@ -883,8 +870,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
883
870
|
self,
|
|
884
871
|
sql: str,
|
|
885
872
|
parameters: "Optional[StatementParameterType]" = None,
|
|
886
|
-
|
|
887
|
-
*,
|
|
873
|
+
*filters: "StatementFilter",
|
|
888
874
|
connection: "Optional[ConnectionT]" = None,
|
|
889
875
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
890
876
|
**kwargs: Any,
|
|
@@ -896,8 +882,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
896
882
|
self,
|
|
897
883
|
sql: str,
|
|
898
884
|
parameters: "Optional[StatementParameterType]" = None,
|
|
899
|
-
|
|
900
|
-
*,
|
|
885
|
+
*filters: "StatementFilter",
|
|
901
886
|
connection: "Optional[ConnectionT]" = None,
|
|
902
887
|
schema_type: None = None,
|
|
903
888
|
**kwargs: Any,
|
|
@@ -909,8 +894,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
909
894
|
self,
|
|
910
895
|
sql: str,
|
|
911
896
|
parameters: "Optional[StatementParameterType]" = None,
|
|
912
|
-
|
|
913
|
-
*,
|
|
897
|
+
*filters: "StatementFilter",
|
|
914
898
|
connection: "Optional[ConnectionT]" = None,
|
|
915
899
|
schema_type: "type[ModelDTOT]",
|
|
916
900
|
**kwargs: Any,
|
|
@@ -921,8 +905,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
921
905
|
self,
|
|
922
906
|
sql: str,
|
|
923
907
|
parameters: "Optional[StatementParameterType]" = None,
|
|
924
|
-
|
|
925
|
-
*,
|
|
908
|
+
*filters: "StatementFilter",
|
|
926
909
|
connection: "Optional[ConnectionT]" = None,
|
|
927
910
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
928
911
|
**kwargs: Any,
|
|
@@ -934,8 +917,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
934
917
|
self,
|
|
935
918
|
sql: str,
|
|
936
919
|
parameters: "Optional[StatementParameterType]" = None,
|
|
937
|
-
|
|
938
|
-
*,
|
|
920
|
+
*filters: "StatementFilter",
|
|
939
921
|
connection: "Optional[ConnectionT]" = None,
|
|
940
922
|
schema_type: None = None,
|
|
941
923
|
**kwargs: Any,
|
|
@@ -947,8 +929,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
947
929
|
self,
|
|
948
930
|
sql: str,
|
|
949
931
|
parameters: "Optional[StatementParameterType]" = None,
|
|
950
|
-
|
|
951
|
-
*,
|
|
932
|
+
*filters: "StatementFilter",
|
|
952
933
|
connection: "Optional[ConnectionT]" = None,
|
|
953
934
|
schema_type: "type[T]",
|
|
954
935
|
**kwargs: Any,
|
|
@@ -959,8 +940,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
959
940
|
self,
|
|
960
941
|
sql: str,
|
|
961
942
|
parameters: "Optional[StatementParameterType]" = None,
|
|
962
|
-
|
|
963
|
-
*,
|
|
943
|
+
*filters: "StatementFilter",
|
|
964
944
|
connection: "Optional[ConnectionT]" = None,
|
|
965
945
|
schema_type: "Optional[type[T]]" = None,
|
|
966
946
|
**kwargs: Any,
|
|
@@ -972,8 +952,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
972
952
|
self,
|
|
973
953
|
sql: str,
|
|
974
954
|
parameters: "Optional[StatementParameterType]" = None,
|
|
975
|
-
|
|
976
|
-
*,
|
|
955
|
+
*filters: "StatementFilter",
|
|
977
956
|
connection: "Optional[ConnectionT]" = None,
|
|
978
957
|
schema_type: None = None,
|
|
979
958
|
**kwargs: Any,
|
|
@@ -985,8 +964,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
985
964
|
self,
|
|
986
965
|
sql: str,
|
|
987
966
|
parameters: "Optional[StatementParameterType]" = None,
|
|
988
|
-
|
|
989
|
-
*,
|
|
967
|
+
*filters: "StatementFilter",
|
|
990
968
|
connection: "Optional[ConnectionT]" = None,
|
|
991
969
|
schema_type: "type[T]",
|
|
992
970
|
**kwargs: Any,
|
|
@@ -997,8 +975,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
997
975
|
self,
|
|
998
976
|
sql: str,
|
|
999
977
|
parameters: "Optional[StatementParameterType]" = None,
|
|
1000
|
-
|
|
1001
|
-
*,
|
|
978
|
+
*filters: "StatementFilter",
|
|
1002
979
|
connection: "Optional[ConnectionT]" = None,
|
|
1003
980
|
schema_type: "Optional[type[T]]" = None,
|
|
1004
981
|
**kwargs: Any,
|
|
@@ -1009,8 +986,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
1009
986
|
self,
|
|
1010
987
|
sql: str,
|
|
1011
988
|
parameters: "Optional[StatementParameterType]" = None,
|
|
1012
|
-
|
|
1013
|
-
*,
|
|
989
|
+
*filters: "StatementFilter",
|
|
1014
990
|
connection: "Optional[ConnectionT]" = None,
|
|
1015
991
|
**kwargs: Any,
|
|
1016
992
|
) -> int: ...
|
|
@@ -1021,8 +997,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
1021
997
|
self,
|
|
1022
998
|
sql: str,
|
|
1023
999
|
parameters: "Optional[StatementParameterType]" = None,
|
|
1024
|
-
|
|
1025
|
-
*,
|
|
1000
|
+
*filters: "StatementFilter",
|
|
1026
1001
|
connection: "Optional[ConnectionT]" = None,
|
|
1027
1002
|
schema_type: None = None,
|
|
1028
1003
|
**kwargs: Any,
|
|
@@ -1034,8 +1009,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
1034
1009
|
self,
|
|
1035
1010
|
sql: str,
|
|
1036
1011
|
parameters: "Optional[StatementParameterType]" = None,
|
|
1037
|
-
|
|
1038
|
-
*,
|
|
1012
|
+
*filters: "StatementFilter",
|
|
1039
1013
|
connection: "Optional[ConnectionT]" = None,
|
|
1040
1014
|
schema_type: "type[ModelDTOT]",
|
|
1041
1015
|
**kwargs: Any,
|
|
@@ -1046,8 +1020,7 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
1046
1020
|
self,
|
|
1047
1021
|
sql: str,
|
|
1048
1022
|
parameters: "Optional[StatementParameterType]" = None,
|
|
1049
|
-
|
|
1050
|
-
*,
|
|
1023
|
+
*filters: "StatementFilter",
|
|
1051
1024
|
connection: "Optional[ConnectionT]" = None,
|
|
1052
1025
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
1053
1026
|
**kwargs: Any,
|
|
@@ -1058,8 +1031,6 @@ class AsyncDriverAdapterProtocol(CommonDriverAttributes[ConnectionT], ABC, Gener
|
|
|
1058
1031
|
self,
|
|
1059
1032
|
sql: str,
|
|
1060
1033
|
parameters: "Optional[StatementParameterType]" = None,
|
|
1061
|
-
/,
|
|
1062
|
-
*,
|
|
1063
1034
|
connection: "Optional[ConnectionT]" = None,
|
|
1064
1035
|
**kwargs: Any,
|
|
1065
1036
|
) -> 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
|
+
)
|