ydb-sqlalchemy 0.1.16__py2.py3-none-any.whl → 0.1.17__py2.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.
@@ -1 +1 @@
1
- VERSION = "0.1.16"
1
+ VERSION = "0.1.17"
@@ -206,6 +206,7 @@ class YqlDialect(StrCompileDialect):
206
206
  json_serializer=None,
207
207
  json_deserializer=None,
208
208
  _add_declare_for_yql_stmt_vars=False,
209
+ _statement_prefixes_list=None,
209
210
  **kwargs,
210
211
  ):
211
212
  super().__init__(**kwargs)
@@ -215,6 +216,7 @@ class YqlDialect(StrCompileDialect):
215
216
  # NOTE: _add_declare_for_yql_stmt_vars is temporary and is soon to be removed.
216
217
  # no need in declare in yql statement here since ydb 24-1
217
218
  self._add_declare_for_yql_stmt_vars = _add_declare_for_yql_stmt_vars
219
+ self._statement_prefixes = tuple(_statement_prefixes_list) if _statement_prefixes_list else ()
218
220
 
219
221
  def _describe_table(self, connection, table_name, schema=None) -> ydb.TableDescription:
220
222
  if schema is not None:
@@ -405,6 +407,12 @@ class YqlDialect(StrCompileDialect):
405
407
  )
406
408
  return f"{declarations}\n{statement}"
407
409
 
410
+ def _apply_statement_prefixes_impl(self, statement: str) -> str:
411
+ if not self._statement_prefixes:
412
+ return statement
413
+ prefixes = "\n".join(self._statement_prefixes) + "\n"
414
+ return f"{prefixes}{statement}"
415
+
408
416
  def __merge_parameters_values_and_types(
409
417
  self, values: Mapping[str, Any], types: Mapping[str, Any], execute_many: bool
410
418
  ) -> Sequence[Mapping[str, ydb.TypedValue]]:
@@ -438,9 +446,12 @@ class YqlDialect(StrCompileDialect):
438
446
  statement, parameters = self._format_variables(statement, parameters, execute_many)
439
447
  if self._add_declare_for_yql_stmt_vars:
440
448
  statement = self._add_declare_for_yql_stmt_vars_impl(statement, parameters_types)
449
+ statement = self._apply_statement_prefixes_impl(statement)
441
450
  return statement, parameters
442
451
 
443
452
  statement, parameters = self._format_variables(statement, parameters, execute_many)
453
+ if not is_ddl:
454
+ statement = self._apply_statement_prefixes_impl(statement)
444
455
  return statement, parameters
445
456
 
446
457
  def do_ping(self, dbapi_connection: ydb_dbapi.Connection) -> bool:
@@ -114,6 +114,30 @@ def test_types_compilation():
114
114
  assert compile_type(struct) == "Struct<a:Int32,b:List<Int32>>"
115
115
 
116
116
 
117
+ def test_statement_prefixes_prepended_to_query():
118
+ dialect = YqlDialect(_statement_prefixes_list=["PRAGMA DistinctOverKeys;"])
119
+ result = dialect._apply_statement_prefixes_impl("SELECT 1")
120
+ assert result == "PRAGMA DistinctOverKeys;\nSELECT 1"
121
+
122
+
123
+ def test_statement_prefixes_empty_list_unchanged():
124
+ dialect = YqlDialect(_statement_prefixes_list=[])
125
+ result = dialect._apply_statement_prefixes_impl("SELECT 1")
126
+ assert result == "SELECT 1"
127
+
128
+
129
+ def test_statement_prefixes_none_unchanged():
130
+ dialect = YqlDialect()
131
+ result = dialect._apply_statement_prefixes_impl("SELECT 1")
132
+ assert result == "SELECT 1"
133
+
134
+
135
+ def test_statement_prefixes_multiple():
136
+ dialect = YqlDialect(_statement_prefixes_list=["PRAGMA Foo;", "PRAGMA Bar;"])
137
+ result = dialect._apply_statement_prefixes_impl("SELECT 1")
138
+ assert result == "PRAGMA Foo;\nPRAGMA Bar;\nSELECT 1"
139
+
140
+
117
141
  def test_optional_type_compilation():
118
142
  dialect = YqlDialect()
119
143
  type_compiler = dialect.type_compiler
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ydb-sqlalchemy
3
- Version: 0.1.16
3
+ Version: 0.1.17
4
4
  Summary: YDB Dialect for SQLAlchemy
5
5
  Home-page: http://github.com/ydb-platform/ydb-sqlalchemy
6
6
  Author: Yandex LLC
@@ -5,22 +5,22 @@ test/test_inspect.py,sha256=c4kc3jc48MCOfllO-ciiYf1vO-HOfuv0xVoXYT1Jxro,1106
5
5
  test/test_orm.py,sha256=jQVVld50zbUwxwgW9ySIWGaNDEOLzHKXjTkdpsG9TpA,1825
6
6
  test/test_suite.py,sha256=JYBGZjaRbg_ZiAqTHeCfL7DLnB6N6xkXN82gnooCyd8,31063
7
7
  ydb_sqlalchemy/__init__.py,sha256=hX7Gy-KOiHk7B5-0wj3ZmLjk4YDJnSMHIAqxVGn_PJY,181
8
- ydb_sqlalchemy/_version.py,sha256=EP5EHnJPa1QWoZlQBIhmsmHs-zCq83eQ9QAPmqT8HTo,19
9
- ydb_sqlalchemy/sqlalchemy/__init__.py,sha256=qLPF8gobyuwiXznh1-MPSQb5iTJc1p_Ypm7yz9owbGQ,17951
8
+ ydb_sqlalchemy/_version.py,sha256=CQKgFdKOd8j2eckBUFbwPNJt1oASUfatjq5eO0eF8cA,19
9
+ ydb_sqlalchemy/sqlalchemy/__init__.py,sha256=8_wPXgqlhyIW0CGmG1vIsjuepGyCOl8rAm7E0Hv90DY,18500
10
10
  ydb_sqlalchemy/sqlalchemy/datetime_types.py,sha256=wrI9kpsI_f7Jhbm7Fu0o_S1QoGCLIe6A9jfUwb41aMM,1929
11
11
  ydb_sqlalchemy/sqlalchemy/dbapi_adapter.py,sha256=7FDjganh9QStIkoXYPFfcRRhd07YCX63_8OmMnge1FI,3542
12
12
  ydb_sqlalchemy/sqlalchemy/dml.py,sha256=k_m6PLOAY7dVzG1gsyo2bB3Lp-o3rhzN0oSX_nfkbFU,310
13
13
  ydb_sqlalchemy/sqlalchemy/json.py,sha256=b4ydjlQjBhlhqGP_Sy2uZVKmt__D-9M7-YLGQMdYGME,1043
14
14
  ydb_sqlalchemy/sqlalchemy/requirements.py,sha256=zm6fcLormtk3KHnbtrBvxfkbG9ZyzNan38HrRB6vC3c,2505
15
- ydb_sqlalchemy/sqlalchemy/test_sqlalchemy.py,sha256=4wyRHmE8YQaMElQPHX6ToEj7A9F8Mvv909aaz_0wRnA,4535
15
+ ydb_sqlalchemy/sqlalchemy/test_sqlalchemy.py,sha256=kSQ2sg90X5QoEAKfJSj3CIqI6j95tLUoUW8Fa197Um0,5410
16
16
  ydb_sqlalchemy/sqlalchemy/types.py,sha256=lFopPGW8WLPIrhgXEcnSAqzJMyrV74ryLSaeTnaKBzA,6125
17
17
  ydb_sqlalchemy/sqlalchemy/compiler/__init__.py,sha256=QqA6r-_bw1R97nQZy5ZSJN724znXg88l4mi5PpqAOxI,492
18
18
  ydb_sqlalchemy/sqlalchemy/compiler/base.py,sha256=JyDIEk3CvJggidFLSNoeI4Khjk3a-b0SjS80GrjgSIk,20248
19
19
  ydb_sqlalchemy/sqlalchemy/compiler/sa14.py,sha256=LanxAnwOiMnsnrY05B0jpmvGn5NXuOKMcxi_6N3obVM,1186
20
20
  ydb_sqlalchemy/sqlalchemy/compiler/sa20.py,sha256=rvVhe-pq5bOyuW4KMMMAD7JIWMzy355eijymBvuPwKw,3421
21
- ydb_sqlalchemy-0.1.16.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
22
- ydb_sqlalchemy-0.1.16.dist-info/METADATA,sha256=F3A9xNjcBN9pL4wLc4V8-NKyz3TKN1Kcm25_xJ47vDg,5395
23
- ydb_sqlalchemy-0.1.16.dist-info/WHEEL,sha256=I3glN-nznogni2CWkAvi6vPRkBhTbVeYvJZnIsln6uc,109
24
- ydb_sqlalchemy-0.1.16.dist-info/entry_points.txt,sha256=iJxbKYuliWNBmL0iIiw8MxvOXrSEz5xe5fuEBqMRwCE,267
25
- ydb_sqlalchemy-0.1.16.dist-info/top_level.txt,sha256=iS69Y1GTAcTok0u0oQdxP-Q5iVgUGI71XBsaEUrWhMg,20
26
- ydb_sqlalchemy-0.1.16.dist-info/RECORD,,
21
+ ydb_sqlalchemy-0.1.17.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
22
+ ydb_sqlalchemy-0.1.17.dist-info/METADATA,sha256=fhxTYNZXhbJs_hoyerJNTPmdqjVXSDbUa84YmsacZts,5395
23
+ ydb_sqlalchemy-0.1.17.dist-info/WHEEL,sha256=I3glN-nznogni2CWkAvi6vPRkBhTbVeYvJZnIsln6uc,109
24
+ ydb_sqlalchemy-0.1.17.dist-info/entry_points.txt,sha256=iJxbKYuliWNBmL0iIiw8MxvOXrSEz5xe5fuEBqMRwCE,267
25
+ ydb_sqlalchemy-0.1.17.dist-info/top_level.txt,sha256=iS69Y1GTAcTok0u0oQdxP-Q5iVgUGI71XBsaEUrWhMg,20
26
+ ydb_sqlalchemy-0.1.17.dist-info/RECORD,,