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)
| 60 | |
| 61 | |
| 62 | def 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 | |
| 80 | class InvalidMapFile(ValueError): |
no outgoing calls
no test coverage detected