Untitled
unknown
plain_text
a year ago
1.2 kB
1
Indexable
Never
from flask_cqlalchemy import CQLAlchemy import uuid from datetime import datetime db=CQLAlchemy() def serializetojson(self): results = {} for key in self.keys(): if type(self[key]) in [str,int,bool,float,dict]: results[key] = self[key] elif type(self[key]) == type(None): results[key] = None elif type(self[key]) is list: lst = [] for x in self[key]: lst.append(x) results[key] = lst elif type(self[key]) in [ uuid.UUID ,datetime]: results[key] = str(self[key]) elif type(self[key]==bytes): results[key] = str(self[key].decode('utf-8')) else: results[key] = str(type(self[key])) return results class cache_store(db.Model): __keyspace__ = 'hobs_ods_staging' businessid = db.columns.Text(primary_key=True) valuetype = db.columns.Text(primary_key=True) key = db.columns.Text(primary_key=True) buid = db.columns.Text() createdtime = db.columns.DateTime() opid = db.columns.Text() updatedtime = db.columns.DateTime() username = db.columns.Text() value = db.columns.Blob() type = db.columns.Text() def __json__(self): results = serializetojson(self) return results db.sync_table(cache_store)