MCPcopy Create free account
hub / github.com/daniel2005d/mapXplore / create_columns

Method create_columns

database/PostgreSQL.py:237–260  ·  view source on GitHub ↗
(self, tablename:str, columns)

Source from the content-addressed store, hash-verified

235 raise e
236
237 def create_columns(self, tablename:str, columns):
238 try:
239 if not self._hashcolumn in columns:
240 columns.append(self._hashcolumn)
241
242 sentence = f"ALTER TABLE {tablename}\n"
243
244 for index,column in enumerate(columns):
245 if not self._check_exists_column(tablename, column):
246 column_type = "TEXT"
247 if column.lower() == self._hashcolumn:
248 column_type = "varchar(50)"
249
250 sentence += f"ADD COLUMN \"{column.lower()}\" {column_type}"
251 sentence+=","
252
253 if sentence.endswith(","):
254 sentence=sentence[:-1]
255 if "COLUMN" in sentence:
256 self._execute(sentence)
257 if self._hashcolumn in sentence:
258 self._execute(f"CREATE UNIQUE INDEX IF NOT EXISTS {tablename}_{self._hashcolumn}_idx ON public.{tablename} USING btree ({self._hashcolumn})")
259 except Exception as e:
260 raise e
261
262 def _get_insert_sentence(self, tablename, data, columns=None):
263 if columns is None:

Callers 1

create_tableMethod · 0.95

Calls 3

_check_exists_columnMethod · 0.95
_executeMethod · 0.95
appendMethod · 0.45

Tested by

no test coverage detected