def to_sqlite_table(self, data: OrderedDict, keys: List[str]) -> None: if not data: return self.__logger.debug("to_sqlite_table: {}, keys={}".format( type(data), keys)) if isinstance(data, (list, tuple)): for s in data: self.to_sqlite_table(s, keys) return root_maps = {} for key, v in data.items(): if isinstance(v, (str, float) + (int, )) or v is None: root_maps[key] = v continue loader = ptr.JsonTableDictLoader(v) try: for table_data in loader.load(): if re.search("json[0-9]+", table_data.table_name): table_data.table_name = self.__make_table_name(keys + [key]) else: table_data.table_name = self.__make_table_name( keys + [key, table_data.table_name]) self.__convert(table_data) except ptr.DataError: self.to_sqlite_table(v, keys + [key]) except ptr.ValidationError as e: self.__logger.debug(msgfy.to_debug_message(e)) if not root_maps: return loader = ptr.JsonTableDictLoader(root_maps) for table_data in loader.load(): if keys: table_data.table_name = self.__make_table_name(keys) else: table_data.table_name = "root" self.__convert(table_data)
def to_sqlite_table(self, data, key_list): if not data: return root_maps = {} for key, v in data.items(): if isinstance(v, (six.text_type, float) + six.integer_types) or v is None: root_maps[key] = v continue loader = ptr.JsonTableDictLoader(v) try: for table_data in loader.load(): if re.search("json[0-9]+", table_data.table_name): table_data.table_name = self.__make_table_name(key_list + [key]) else: table_data.table_name = self.__make_table_name( key_list + [key, table_data.table_name] ) self.__convert(table_data) except ptr.DataError: self.to_sqlite_table(v, key_list + [key]) except ptr.ValidationError as e: self.__logger.debug(msgfy.to_debug_message(e)) if not root_maps: return loader = ptr.JsonTableDictLoader(root_maps) for table_data in loader.load(): if key_list: table_data.table_name = self.__make_table_name(key_list) else: table_data.table_name = "root" self.__convert(table_data)