-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQLAlchemy: Use JSON type adapter for implementing CrateDB's OBJECT
#561
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
# However, if you have executed another commercial license agreement | ||
# with Crate these terms will supersede the license and you may use the | ||
# software solely pursuant to the terms of the relevant commercial agreement. | ||
import warnings | ||
|
||
import sqlalchemy.types as sqltypes | ||
from sqlalchemy.sql import operators, expression | ||
|
@@ -131,24 +132,31 @@ def __eq__(self, other): | |
return dict.__eq__(self, other) | ||
|
||
|
||
class _Craty(sqltypes.UserDefinedType): | ||
class ObjectTypeImpl(sqltypes.UserDefinedType, sqltypes.JSON): | ||
|
||
__visit_name__ = "OBJECT" | ||
|
||
cache_ok = False | ||
none_as_null = False | ||
|
||
class Comparator(sqltypes.TypeEngine.Comparator): | ||
|
||
def __getitem__(self, key): | ||
return default_comparator._binary_operate(self.expr, | ||
operators.getitem, | ||
key) | ||
# Designated name to refer to. `Object` is too ambiguous. | ||
ObjectType = MutableDict.as_mutable(ObjectTypeImpl) | ||
Comment on lines
+143
to
+144
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SQLAlchemy also offers a However, it did not work out of the box. SQLAlchemy's This topic will need to be re-visited. /cc GH-425 |
||
|
||
def get_col_spec(self): | ||
return 'OBJECT' | ||
# Backward-compatibility aliases. | ||
_deprecated_Craty = ObjectType | ||
Check notice Code scanning / CodeQL Unused global variable
The global variable '_deprecated_Craty' is not used.
|
||
_deprecated_Object = ObjectType | ||
Check notice Code scanning / CodeQL Unused global variable
The global variable '_deprecated_Object' is not used.
|
||
|
||
type = MutableDict | ||
comparator_factory = Comparator | ||
# https://www.lesinskis.com/deprecating-module-scope-variables.html | ||
deprecated_names = ["Craty", "Object"] | ||
|
||
|
||
Object = Craty = MutableDict.as_mutable(_Craty) | ||
def __getattr__(name): | ||
if name in deprecated_names: | ||
warnings.warn(f"{name} is deprecated and will be removed in future releases. " | ||
f"Please use ObjectType instead.", DeprecationWarning) | ||
return globals()[f"_deprecated_{name}"] | ||
raise AttributeError(f"module {__name__} has no attribute {name}") | ||
|
||
|
||
class Any(expression.ColumnElement): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need to use
cache_ok = False
, otherwise things go south on indexed dictionary access. So, it does not improve the situation wrt. GH-559. I will ask for advise on the upstream issue tracker about this detail.