MCPcopy Index your code
hub / github.com/dbcli/pgcli / generate_alias

Function generate_alias

pgcli/pgcompleter.py:62–77  ·  view source on GitHub ↗

Generate a table alias. Given a table name will return an alias for that table using the first of the following options there's a match for. 1. The predefined alias for table defined in the alias_map. 2. All upper-case letters in the table name. 3. The first letter

(tbl, alias_map=None)

Source from the content-addressed store, hash-verified

60
61
62def generate_alias(tbl, alias_map=None):
63 """Generate a table alias.
64
65 Given a table name will return an alias for that table using the first of
66 the following options there's a match for.
67
68 1. The predefined alias for table defined in the alias_map.
69 2. All upper-case letters in the table name.
70 3. The first letter of the table name and all letters preceded by _
71
72 :param tbl: unescaped name of the table to alias
73 :param alias_map: optional mapping of predefined table aliases
74 """
75 if alias_map and tbl in alias_map:
76 return alias_map[tbl]
77 return "".join([l for l in tbl if l.isupper()] or [l for l, prev in zip(tbl, "_" + tbl) if prev == "_" and l != "_"])
78
79
80class InvalidMapFile(ValueError):

Callers 4

make_candMethod · 0.85
aliasMethod · 0.85
get_join_matchesMethod · 0.85
_make_candMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected