clean file and cascade adapt of __get_pkey__,__get_dtype__
This commit is contained in:
parent
1a5c1ed5f9
commit
237c7877cb
@ -12,22 +12,11 @@ Module contains tools for processing files into DataFrames or other objects
|
||||
import geopandas as gpd
|
||||
import pandas as pd
|
||||
from .params import DIC_REF_HAB, DIC_UNIQUE_KEY
|
||||
from .tools import _get_table
|
||||
from .tools import _get_table,__get_pkey__,__get_dtype__
|
||||
|
||||
#####################################
|
||||
### Update ###
|
||||
#####################################
|
||||
def __get_pkey__(engine,table_name,schema):
|
||||
pk = engine.dialect.get_pk_constraint(engine,table_name=table_name,schema=schema)
|
||||
return pk
|
||||
|
||||
def __get_dtype__(engine,table_name,schema):
|
||||
cols = engine.dialect.get_columns(engine,table_name=table_name,schema=schema)
|
||||
# name_cols = [i['name'] for i in cols]
|
||||
# type_cols = [i['type'] for i in cols]
|
||||
type_cols = {i['name']:i['type'] for i in cols}
|
||||
return type_cols
|
||||
|
||||
def _get_dic(self):
|
||||
if self._table:
|
||||
select_cols = DIC_REF_HAB[self._table]
|
||||
@ -218,7 +207,7 @@ class update_ref_table:
|
||||
Q = input('UPDATE {0}/{1} ... Yes(y)/No(n)/View(v) ?'.format(len_updt,len(df)))
|
||||
if Q.lower() in ['yes','y']:
|
||||
print('UPDATE {0}/{1} ...'.format(len_updt,len(df)))
|
||||
update.update_to_sql(
|
||||
update_to_sql(
|
||||
df=df_updt,
|
||||
con=self.con,
|
||||
table_name=self._table,
|
||||
@ -234,7 +223,7 @@ def update_ref(file, table, schema=None, update=False):
|
||||
update_ref_table(file, table, schema, update)
|
||||
|
||||
|
||||
def update_to_sql(df, con, table_name, schema_name, key_name):
|
||||
def update_to_sql(df, con, table_name, schema_name, key_name, checkid=True):
|
||||
from sys import exit
|
||||
|
||||
a = []
|
||||
@ -246,19 +235,20 @@ def update_to_sql(df, con, table_name, schema_name, key_name):
|
||||
con,table_name=table,schema=schema)
|
||||
type_cols = __get_dtype__(
|
||||
con,table_name=table,schema=schema)
|
||||
|
||||
if not all(item in pkey['constrained_columns'] for item in df.columns):
|
||||
print('Le(s) champs clé primaire "%s" ne figure pas dans le DataFrame'%pkey['constrained_columns'])
|
||||
Q = input('Voulez-vous continuer la mise à jour ? (y/n) ')
|
||||
if Q.lower() == 'y':
|
||||
pass
|
||||
else :
|
||||
return print('Données non mise à jour')
|
||||
# if pkey not in df.columns:
|
||||
# exit('Le champs clé primaire "%s" ne figure pas dans le DataFrame'%pkey)
|
||||
|
||||
if isinstance(primary_key, str):
|
||||
primary_key = [primary_key]
|
||||
|
||||
if checkid :
|
||||
if not all(item in pkey['constrained_columns'] for item in primary_key):
|
||||
print('Le(s) champs clé primaire "%s" ne figure pas dans le DataFrame'%pkey['constrained_columns'])
|
||||
Q = input('Voulez-vous continuer la mise à jour ? (y/n) ')
|
||||
if Q.lower() == 'y':
|
||||
pass
|
||||
else :
|
||||
return print('Données non mise à jour')
|
||||
|
||||
for col in df.columns:
|
||||
if col in primary_key:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user