async def set_schema(self, schema): try: get_schema(schema['type']).validate_schema(schema['schema']) except KeyError: pass # TODO Exception blob = await Blob.create(schema) return await Journal.create( blob=blob._id, collection=self._id, namespace=self.namespace, action=Action.UPDATE_SCHEMA, record_id=self.SCHEMA_RESERVED, )
async def set_schema(self, schema): try: get_schema(schema["type"]).validate_schema(schema["schema"]) except KeyError: pass # TODO Exception blob = await Blob.create(schema) return await Journal.create( blob=blob._id, collection=self._id, namespace=self.namespace, action=Action.UPDATE_SCHEMA, record_id=self.SCHEMA_RESERVED, )
async def get_schema(self): try: entry = next(await Journal.find( (Journal.collection == self._id) & (Journal.namespace == self.namespace) & (Journal.record_id == self.SCHEMA_RESERVED) & ((Journal.action == Action.UPDATE_SCHEMA.value) | (Journal.action == Action.DELETE_SCHEMA.value)), limit=1, sort=sort.Descending(Journal.modified_by))) except StopIteration: return None if entry.action == Action.DELETE_SCHEMA: return None blob = await entry.blob return get_schema(blob['type'])(blob['schema'])
async def get_schema(self): try: entry = next( await Journal.find( (Journal.collection == self._id) & (Journal.namespace == self.namespace) & (Journal.record_id == self.SCHEMA_RESERVED) & ((Journal.action == Action.UPDATE_SCHEMA.value) | (Journal.action == Action.DELETE_SCHEMA.value)), limit=1, sort=sort.Descending(Journal.modified_by), ) ) except StopIteration: return None if entry.action == Action.DELETE_SCHEMA: return None blob = await entry.blob return get_schema(blob["type"])(blob["schema"])