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

Class MetaData

tests/metadata.py:58–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56
57
58class MetaData:
59 def __init__(self, metadata):
60 self.metadata = metadata
61
62 def builtin_functions(self, pos=0):
63 return [function(f, pos) for f in self.completer.functions]
64
65 def builtin_datatypes(self, pos=0):
66 return [datatype(dt, pos) for dt in self.completer.datatypes]
67
68 def keywords(self, pos=0):
69 return [keyword(kw, pos) for kw in self.completer.keywords_tree.keys()]
70
71 def specials(self, pos=0):
72 return [Completion(text=k, start_position=pos, display_meta=v.description) for k, v in self.completer.pgspecial.commands.items()]
73
74 def columns(self, tbl, parent="public", typ="tables", pos=0):
75 if typ == "functions":
76 fun = [x for x in self.metadata[typ][parent] if x[0] == tbl][0]
77 cols = fun[1]
78 else:
79 cols = self.metadata[typ][parent][tbl]
80 return [column(escape(col), pos) for col in cols]
81
82 def datatypes(self, parent="public", pos=0):
83 return [datatype(escape(x), pos) for x in self.metadata.get("datatypes", {}).get(parent, [])]
84
85 def tables(self, parent="public", pos=0):
86 return [table(escape(x), pos) for x in self.metadata.get("tables", {}).get(parent, [])]
87
88 def views(self, parent="public", pos=0):
89 return [view(escape(x), pos) for x in self.metadata.get("views", {}).get(parent, [])]
90
91 def functions(self, parent="public", pos=0):
92 return [
93 function(
94 escape(x[0])
95 + "("
96 + ", ".join(arg_name + " := " for (arg_name, arg_mode) in zip(x[1], x[3]) if arg_mode in ("b", "i"))
97 + ")",
98 pos,
99 escape(x[0]) + "(" + ", ".join(arg_name for (arg_name, arg_mode) in zip(x[1], x[3]) if arg_mode in ("b", "i")) + ")",
100 )
101 for x in self.metadata.get("functions", {}).get(parent, [])
102 ]
103
104 def schemas(self, pos=0):
105 schemas = {sch for schs in self.metadata.values() for sch in schs}
106 return [schema(escape(s), pos=pos) for s in schemas]
107
108 def functions_and_keywords(self, parent="public", pos=0):
109 return self.functions(parent, pos) + self.builtin_functions(pos) + self.keywords(pos)
110
111 # Note that the filtering parameters here only apply to the columns
112 def columns_functions_and_keywords(self, tbl, parent="public", typ="tables", pos=0):
113 return self.functions_and_keywords(pos=pos) + self.columns(tbl, parent, typ, pos)
114
115 def from_clause_items(self, parent="public", pos=0):

Calls

no outgoing calls

Tested by

no test coverage detected