sqlalchemy-singlestoredb 1.0.0__tar.gz → 1.1.0__tar.gz

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.
Files changed (20) hide show
  1. {sqlalchemy_singlestoredb-1.0.0/sqlalchemy_singlestoredb.egg-info → sqlalchemy_singlestoredb-1.1.0}/PKG-INFO +1 -4
  2. {sqlalchemy_singlestoredb-1.0.0 → sqlalchemy_singlestoredb-1.1.0}/setup.cfg +2 -5
  3. {sqlalchemy_singlestoredb-1.0.0 → sqlalchemy_singlestoredb-1.1.0}/sqlalchemy_singlestoredb/__init__.py +7 -1
  4. {sqlalchemy_singlestoredb-1.0.0 → sqlalchemy_singlestoredb-1.1.0}/sqlalchemy_singlestoredb/base.py +71 -0
  5. sqlalchemy_singlestoredb-1.1.0/sqlalchemy_singlestoredb/column.py +29 -0
  6. sqlalchemy_singlestoredb-1.1.0/sqlalchemy_singlestoredb/ddlelement.py +29 -0
  7. {sqlalchemy_singlestoredb-1.0.0 → sqlalchemy_singlestoredb-1.1.0/sqlalchemy_singlestoredb.egg-info}/PKG-INFO +1 -4
  8. {sqlalchemy_singlestoredb-1.0.0 → sqlalchemy_singlestoredb-1.1.0}/sqlalchemy_singlestoredb.egg-info/SOURCES.txt +2 -0
  9. {sqlalchemy_singlestoredb-1.0.0 → sqlalchemy_singlestoredb-1.1.0}/LICENSE +0 -0
  10. {sqlalchemy_singlestoredb-1.0.0 → sqlalchemy_singlestoredb-1.1.0}/README.md +0 -0
  11. {sqlalchemy_singlestoredb-1.0.0 → sqlalchemy_singlestoredb-1.1.0}/setup.py +0 -0
  12. {sqlalchemy_singlestoredb-1.0.0 → sqlalchemy_singlestoredb-1.1.0}/sqlalchemy_singlestoredb/dtypes.py +0 -0
  13. {sqlalchemy_singlestoredb-1.0.0 → sqlalchemy_singlestoredb-1.1.0}/sqlalchemy_singlestoredb/reflection.py +0 -0
  14. {sqlalchemy_singlestoredb-1.0.0 → sqlalchemy_singlestoredb-1.1.0}/sqlalchemy_singlestoredb/tests/__init__.py +0 -0
  15. {sqlalchemy_singlestoredb-1.0.0 → sqlalchemy_singlestoredb-1.1.0}/sqlalchemy_singlestoredb/tests/test.sql +0 -0
  16. {sqlalchemy_singlestoredb-1.0.0 → sqlalchemy_singlestoredb-1.1.0}/sqlalchemy_singlestoredb/tests/test_basics.py +0 -0
  17. {sqlalchemy_singlestoredb-1.0.0 → sqlalchemy_singlestoredb-1.1.0}/sqlalchemy_singlestoredb.egg-info/dependency_links.txt +0 -0
  18. {sqlalchemy_singlestoredb-1.0.0 → sqlalchemy_singlestoredb-1.1.0}/sqlalchemy_singlestoredb.egg-info/entry_points.txt +0 -0
  19. {sqlalchemy_singlestoredb-1.0.0 → sqlalchemy_singlestoredb-1.1.0}/sqlalchemy_singlestoredb.egg-info/requires.txt +0 -0
  20. {sqlalchemy_singlestoredb-1.0.0 → sqlalchemy_singlestoredb-1.1.0}/sqlalchemy_singlestoredb.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sqlalchemy_singlestoredb
3
- Version: 1.0.0
3
+ Version: 1.1.0
4
4
  Summary: SQLAlchemy dialect for the SingleStoreDB database
5
5
  Home-page: https://github.com/singlestore-labs/sqlalchemy-singlestoredb
6
6
  Author: SingleStore
@@ -10,9 +10,6 @@ Classifier: Development Status :: 5 - Production/Stable
10
10
  Classifier: License :: OSI Approved :: Apache Software License
11
11
  Classifier: Programming Language :: Python :: 3
12
12
  Classifier: Programming Language :: Python :: 3 :: Only
13
- Classifier: Programming Language :: Python :: 3.8
14
- Classifier: Programming Language :: Python :: 3.9
15
- Classifier: Programming Language :: Python :: 3.10
16
13
  Requires-Python: >=3.8
17
14
  Description-Content-Type: text/markdown
18
15
  License-File: LICENSE
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = sqlalchemy_singlestoredb
3
- version = 1.0.0
3
+ version = 1.1.0
4
4
  description = SQLAlchemy dialect for the SingleStoreDB database
5
5
  long_description = file: README.md
6
6
  long_description_content_type = text/markdown
@@ -8,15 +8,12 @@ url = https://github.com/singlestore-labs/sqlalchemy-singlestoredb
8
8
  author = SingleStore
9
9
  author_email = support@singlestore.com
10
10
  license = Apache-2.0
11
- license_file = LICENSE
11
+ license_files = LICENSE
12
12
  classifiers =
13
13
  Development Status :: 5 - Production/Stable
14
14
  License :: OSI Approved :: Apache Software License
15
15
  Programming Language :: Python :: 3
16
16
  Programming Language :: Python :: 3 :: Only
17
- Programming Language :: Python :: 3.8
18
- Programming Language :: Python :: 3.9
19
- Programming Language :: Python :: 3.10
20
17
 
21
18
  [options]
22
19
  packages = find:
@@ -40,6 +40,9 @@ from sqlalchemy.dialects.mysql.dml import Insert
40
40
  from sqlalchemy.dialects.mysql.dml import insert
41
41
 
42
42
  from . import base
43
+ from .column import PersistedColumn
44
+ from .ddlelement import ShardKey
45
+ from .ddlelement import SortKey
43
46
  from .dtypes import JSON
44
47
  from .dtypes import VECTOR
45
48
 
@@ -48,7 +51,7 @@ array = base.array
48
51
  # default dialect
49
52
  dialect = base.dialect
50
53
 
51
- __version__ = '1.0.0'
54
+ __version__ = '1.1.0'
52
55
 
53
56
  __all__ = (
54
57
  'BIGINT',
@@ -74,8 +77,11 @@ __all__ = (
74
77
  'NCHAR',
75
78
  'NVARCHAR',
76
79
  'NUMERIC',
80
+ 'PersistedColumn',
77
81
  'SET',
78
82
  'SMALLINT',
83
+ 'ShardKey',
84
+ 'SortKey',
79
85
  'REAL',
80
86
  'TEXT',
81
87
  'TIME',
@@ -26,8 +26,13 @@ from sqlalchemy.engine.url import URL
26
26
  from sqlalchemy.sql import sqltypes
27
27
  from sqlalchemy.sql.compiler import BIND_PARAMS
28
28
  from sqlalchemy.sql.compiler import BIND_PARAMS_ESC
29
+ try:
30
+ from sqlalchemy.sql.schema import SchemaConst
31
+ except ImportError:
32
+ from sqlalchemy.sql import schema as SchemaConst
29
33
 
30
34
  from . import reflection
35
+ from .column import PersistedColumn
31
36
  from .dtypes import _json_deserializer
32
37
  from .dtypes import JSON
33
38
  from .dtypes import VECTOR
@@ -198,6 +203,72 @@ class SingleStoreDBCompiler(MySQLCompiler):
198
203
  class SingleStoreDBDDLCompiler(MySQLDDLCompiler):
199
204
  """SingleStoreDB SQLAlchemy DDL compiler."""
200
205
 
206
+ def visit_create_table(self, create: Any, **kw: Any) -> str:
207
+ create_table_sql = super().visit_create_table(create, **kw)
208
+ shard_key = create.element.info.get('singlestoredb_shard_key')
209
+ if shard_key is not None:
210
+ shard_columns = ', '.join(shard_key.columns)
211
+ shard_key_sql = f'SHARD KEY ({shard_columns})'
212
+ # Append the SHARD KEY definition to the original SQL
213
+ create_table_sql = f'{create_table_sql.rstrip()[:-2]},\n\t{shard_key_sql}\n)'
214
+
215
+ sort_key = create.element.info.get('singlestoredb_sort_key')
216
+ if sort_key is not None:
217
+ sort_columns = ', '.join(sort_key.columns)
218
+ sort_key_sql = f'SORT KEY ({sort_columns})'
219
+ # Append the SHARD KEY definition to the original SQL
220
+ create_table_sql = f'{create_table_sql.rstrip()[:-2]},\n\t{sort_key_sql}\n)'
221
+
222
+ return create_table_sql
223
+
224
+ def get_column_specification(self, column: Any, **kw: Any) -> str:
225
+ """Builds column DDL."""
226
+ if not isinstance(column, PersistedColumn):
227
+ return super().get_column_specification(column, **kw)
228
+
229
+ if (
230
+ self.dialect.is_mariadb is True
231
+ and column.computed is not None
232
+ and column._user_defined_nullable is SchemaConst.NULL_UNSPECIFIED
233
+ ):
234
+ column.nullable = True
235
+ colspec = [
236
+ self.preparer.format_column(column),
237
+ 'AS',
238
+ column.persisted_expression,
239
+ 'PERSISTED',
240
+ self.dialect.type_compiler_instance.process(
241
+ column.type, type_expression=column,
242
+ ),
243
+ ]
244
+
245
+ if column.computed is not None:
246
+ colspec.append(self.process(column.computed))
247
+
248
+ is_timestamp = isinstance(
249
+ column.type._unwrapped_dialect_impl(self.dialect),
250
+ sqltypes.TIMESTAMP,
251
+ )
252
+
253
+ if not column.nullable:
254
+ colspec.append('NOT NULL')
255
+
256
+ # see: https://docs.sqlalchemy.org/en/latest/dialects/mysql.html#mysql_timestamp_null # noqa
257
+ elif column.nullable and is_timestamp:
258
+ colspec.append('NULL')
259
+
260
+ comment = column.comment
261
+ if comment is not None:
262
+ literal = self.sql_compiler.render_literal_value(
263
+ comment, sqltypes.String(),
264
+ )
265
+ colspec.append('COMMENT ' + literal)
266
+
267
+ default = self.get_column_default_string(column)
268
+ if default is not None:
269
+ colspec.append('DEFAULT ' + default)
270
+ return ' '.join(colspec)
271
+
201
272
 
202
273
  class SingleStoreDBTypeCompiler(MySQLTypeCompiler):
203
274
  """SingleStoreDB SQLAlchemy type compiler."""
@@ -0,0 +1,29 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+ from sqlalchemy import Column
6
+ from sqlalchemy.ext.declarative import declarative_base
7
+ from sqlalchemy.sql.expression import TextClause
8
+
9
+ Base = declarative_base()
10
+
11
+
12
+ class PersistedColumn(Column):
13
+ def __init__(
14
+ self,
15
+ *args: Any,
16
+ persisted_expression: Any = None,
17
+ **kwargs: Any,
18
+ ) -> None:
19
+ if persisted_expression is not None:
20
+ # Ensure persisted_expression is either a TextClause or a string
21
+ if not isinstance(persisted_expression, (TextClause, str)):
22
+ raise ValueError(
23
+ 'Persisted expression must be a SQL expression '
24
+ 'as a string or TextClause',
25
+ )
26
+ self.is_persisted = True
27
+ self.persisted_expression = persisted_expression
28
+ kwargs['info'] = {'persisted_expression': persisted_expression}
29
+ super().__init__(*args, **kwargs)
@@ -0,0 +1,29 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+ from sqlalchemy.ext.compiler import compiles
6
+ from sqlalchemy.ext.declarative import declarative_base
7
+ from sqlalchemy.schema import DDLElement
8
+
9
+ Base = declarative_base()
10
+
11
+
12
+ class ShardKey(DDLElement):
13
+ def __init__(self, *columns: Any) -> None:
14
+ self.columns = columns
15
+
16
+
17
+ @compiles(ShardKey, 'singlestoredb.mysql')
18
+ def compile_shard_key(element: Any, compiler: Any, **kw: Any) -> str:
19
+ return 'SHARD KEY (%s)' % ', '.join(element.columns)
20
+
21
+
22
+ class SortKey(DDLElement):
23
+ def __init__(self, *columns: Any) -> None:
24
+ self.columns = columns
25
+
26
+
27
+ @compiles(SortKey, 'singlestoredb.mysql')
28
+ def compile_sort_key(element: Any, compiler: Any, **kw: Any) -> str:
29
+ return 'SORT KEY (%s)' % ', '.join(element.columns)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sqlalchemy_singlestoredb
3
- Version: 1.0.0
3
+ Version: 1.1.0
4
4
  Summary: SQLAlchemy dialect for the SingleStoreDB database
5
5
  Home-page: https://github.com/singlestore-labs/sqlalchemy-singlestoredb
6
6
  Author: SingleStore
@@ -10,9 +10,6 @@ Classifier: Development Status :: 5 - Production/Stable
10
10
  Classifier: License :: OSI Approved :: Apache Software License
11
11
  Classifier: Programming Language :: Python :: 3
12
12
  Classifier: Programming Language :: Python :: 3 :: Only
13
- Classifier: Programming Language :: Python :: 3.8
14
- Classifier: Programming Language :: Python :: 3.9
15
- Classifier: Programming Language :: Python :: 3.10
16
13
  Requires-Python: >=3.8
17
14
  Description-Content-Type: text/markdown
18
15
  License-File: LICENSE
@@ -4,6 +4,8 @@ setup.cfg
4
4
  setup.py
5
5
  sqlalchemy_singlestoredb/__init__.py
6
6
  sqlalchemy_singlestoredb/base.py
7
+ sqlalchemy_singlestoredb/column.py
8
+ sqlalchemy_singlestoredb/ddlelement.py
7
9
  sqlalchemy_singlestoredb/dtypes.py
8
10
  sqlalchemy_singlestoredb/reflection.py
9
11
  sqlalchemy_singlestoredb.egg-info/PKG-INFO