diff options
author | Zuul <zuul@review.opendev.org> | 2023-04-07 17:46:50 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2023-04-07 17:46:50 +0000 |
commit | cec8eb12c628a38b2431dac78ed37fc3f1506939 (patch) | |
tree | f613061baee36e32de818128e96f6d5742112585 /heat/db/types.py | |
parent | 1ca04117b9c3bff0b338df97df2c26d6a70929ea (diff) | |
parent | 43a5f3984e433ec28616cfe98cb060d9ff51af58 (diff) | |
download | heat-cec8eb12c628a38b2431dac78ed37fc3f1506939.tar.gz |
Merge "db: Remove layer of indirection"
Diffstat (limited to 'heat/db/types.py')
-rw-r--r-- | heat/db/types.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/heat/db/types.py b/heat/db/types.py new file mode 100644 index 000000000..d454024c6 --- /dev/null +++ b/heat/db/types.py @@ -0,0 +1,65 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from oslo_serialization import jsonutils +from sqlalchemy.dialects import mysql +from sqlalchemy import types + + +dumps = jsonutils.dumps +loads = jsonutils.loads + + +class LongText(types.TypeDecorator): + + impl = types.Text + cache_ok = True + + def load_dialect_impl(self, dialect): + if dialect.name == 'mysql': + return dialect.type_descriptor(mysql.LONGTEXT()) + else: + return self.impl + + +class Json(LongText): + + cache_ok = True + + def process_bind_param(self, value, dialect): + return dumps(value) + + def process_result_value(self, value, dialect): + if value is None: + return None + return loads(value) + + +class List(types.TypeDecorator): + + impl = types.Text + cache_ok = True + + def load_dialect_impl(self, dialect): + if dialect.name == 'mysql': + return dialect.type_descriptor(mysql.LONGTEXT()) + else: + return self.impl + + def process_bind_param(self, value, dialect): + return dumps(value) + + def process_result_value(self, value, dialect): + if value is None: + return None + return loads(value) |