| 52 | |
| 53 | |
| 54 | class FunctionMetadata: |
| 55 | |
| 56 | def __init__( |
| 57 | self, schema_name, func_name, arg_names, arg_types, arg_modes, |
| 58 | return_type, is_aggregate, is_window, is_set_returning, arg_defaults |
| 59 | ): |
| 60 | """Class for describing a postgresql function""" |
| 61 | |
| 62 | self.schema_name = schema_name |
| 63 | self.func_name = func_name |
| 64 | |
| 65 | self.arg_modes = tuple(arg_modes) if arg_modes else None |
| 66 | self.arg_names = tuple(arg_names) if arg_names else None |
| 67 | |
| 68 | # Be flexible in not requiring arg_types -- use None as a placeholder |
| 69 | # for each arg. (Used for compatibility with old versions of postgresql |
| 70 | # where such info is hard to get. |
| 71 | if arg_types: |
| 72 | self.arg_types = tuple(arg_types) |
| 73 | elif arg_modes: |
| 74 | self.arg_types = tuple([None] * len(arg_modes)) |
| 75 | elif arg_names: |
| 76 | self.arg_types = tuple([None] * len(arg_names)) |
| 77 | else: |
| 78 | self.arg_types = None |
| 79 | |
| 80 | self.arg_defaults = tuple(parse_defaults(arg_defaults)) |
| 81 | |
| 82 | self.return_type = return_type.strip() |
| 83 | self.is_aggregate = is_aggregate |
| 84 | self.is_window = is_window |
| 85 | self.is_set_returning = is_set_returning |
| 86 | |
| 87 | def __eq__(self, other): |
| 88 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ |
| 89 | |
| 90 | def __ne__(self, other): |
| 91 | return not self.__eq__(other) |
| 92 | |
| 93 | def _signature(self): |
| 94 | return ( |
| 95 | self.schema_name, self.func_name, self.arg_names, self.arg_types, |
| 96 | self.arg_modes, self.return_type, self.is_aggregate, |
| 97 | self.is_window, self.is_set_returning, self.arg_defaults |
| 98 | ) |
| 99 | |
| 100 | def __hash__(self): |
| 101 | return hash(self._signature()) |
| 102 | |
| 103 | def __repr__(self): |
| 104 | return ( |
| 105 | ( |
| 106 | '%s(schema_name=%r, func_name=%r, arg_names=%r, ' |
| 107 | 'arg_types=%r, arg_modes=%r, return_type=%r, is_aggregate=%r, ' |
| 108 | 'is_window=%r, is_set_returning=%r, arg_defaults=%r)' |
| 109 | ) % (self.__class__.__name__, self.schema_name, self.func_name, self.arg_names, |
| 110 | self.arg_types, self.arg_modes, self.return_type, self.is_aggregate, |
| 111 | self.is_window, self.is_set_returning, self.arg_defaults) |
no outgoing calls