def process_item(item, include, includes): matcher = re.compile(replace_wildcards(prefix(include))) col = find_column(item.table, matcher) fk = find_foreign_key(item.table, matcher) if not col and not fk: raise UnknownColumnException(item.table, include) if '.' not in include: # Only include column, don't include referencing rows # # Examples: # 1) user_id - include column user_id, but no referenced rows # 2) user_id. - include column user_id with referencing user # row # 3) user_id.article - include column user_id with referenced # articles return if fk: if fk.a.table.name == item.table.name: add_forward_reference(includes, fk, item) else: add_backward_reference(includes, fk, item) if col and col.name in item.table.foreign_keys(): add_column(includes, col, item)
def check_excludes(items, exclude): if exclude: for item in items: for x in exclude: matcher = re.compile(replace_wildcards(prefix(x))) fks = fk_by_a_table_name(item.table.foreign_keys()) col, fk = None, None for k in fks.keys(): if matcher.match(k): fk = fks[k] break for c in item.table.columns(): if matcher.match(c.name): col = c break if not col and not fk: raise UnknownColumnException( item.table, x, fks.keys() + map(lambda c: c.name, item.table.columns())) # only check first item, as we expect all items are from the same # table break
def check_excludes(items, exclude): if exclude: for item in items: for x in exclude: matcher = re.compile(replace_wildcards(prefix(x))) fks = fk_by_a_table_name(item.table.foreign_keys()) col, fk = None, None for k in fks.keys(): if matcher.match(k): fk = fks[k] break for c in item.table.columns(): if matcher.match(c.name): col = c break if not col and not fk: raise UnknownColumnException( item.table, x, fks.keys() + map( lambda c: c.name, item.table.columns())) # only check first item, as we expect all items are from the same # table break