MCPcopy Create free account
hub / github.com/dbcli/mssql-cli / MetaData

Class MetaData

tests/metadata.py:67–246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65
66
67class MetaData:
68 def __init__(self, metadata):
69 self.metadata = metadata
70
71 def builtin_functions(self, pos=0):
72 return [function(f, pos) for f in self.completer.functions]
73
74 def builtin_datatypes(self, pos=0):
75 return [datatype(dt, pos) for dt in self.completer.datatypes]
76
77 def keywords(self, pos=0):
78 return [keyword(kw, pos) for kw in self.completer.keywords_tree.keys()]
79
80 def columns(self, tbl, parent='public', typ='tables', pos=0):
81 if typ == 'functions':
82 fun = [x for x in self.metadata[typ][parent] if x[0] == tbl][0]
83 cols = fun[1]
84 else:
85 cols = self.metadata[typ][parent][tbl]
86 return [column(escape(col), pos) for col in cols]
87
88 def datatypes(self, parent='public', pos=0):
89 return [
90 datatype(escape(x), pos)
91 for x in self.metadata.get('datatypes', {}).get(parent, [])]
92
93 def tables(self, parent='public', pos=0):
94 return [
95 table(escape(x), pos)
96 for x in self.metadata.get('tables', {}).get(parent, [])]
97
98 def views(self, parent='public', pos=0):
99 return [
100 view(escape(x), pos)
101 for x in self.metadata.get('views', {}).get(parent, [])]
102
103 def functions(self, parent='public', pos=0):
104 return [
105 function(
106 escape(x[0]) + '(' + ', '.join(
107 arg_name + ' := '
108 for (arg_name, arg_mode) in zip(x[1], x[3])
109 if arg_mode in ('b', 'i')
110 ) + ')',
111 pos,
112 escape(x[0]) + '(' + ', '.join(
113 arg_name
114 for (arg_name, arg_mode) in zip(x[1], x[3])
115 if arg_mode in ('b', 'i')
116 ) + ')'
117 )
118 for x in self.metadata.get('functions', {}).get(parent, [])
119 ]
120
121 def schemas(self, pos=0):
122 schemas = set(sch for schs in self.metadata.values() for sch in schs)
123 return [schema(escape(s), pos=pos) for s in schemas]
124

Calls

no outgoing calls

Tested by

no test coverage detected