-
Notifications
You must be signed in to change notification settings - Fork 4
/
utilities.py
49 lines (36 loc) · 1.11 KB
/
utilities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import random
import string
import uuid
import main
def get_new_table_id() -> str:
"""
Method to return a new table id
"""
letters = string.ascii_lowercase
return ''.join(random.choice(letters) for i in range(50))
def get_new_process_id() -> str:
"""
Method to return a new process id
"""
return str(uuid.uuid4())
async def get_table_columns(table: str, database: str, new_table_name: str=None) -> list:
"""
Method to return a list of columns for a table.
"""
pool = main.app.state.databases[f'{database}_pool']
async with pool.acquire() as con:
sql_field_query = f"""
SELECT column_name
FROM information_schema.columns
WHERE table_name = '{table}'
AND column_name != 'geom';
"""
db_fields = await con.fetch(sql_field_query)
fields = []
for field in db_fields:
if new_table_name:
column_name = field['column_name']
fields.append(f"{new_table_name}.{column_name}")
else:
fields.append(field['column_name'])
return fields