lbxtoolkit 2.3.0__tar.gz → 2.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: lbxtoolkit
3
- Version: 2.3.0
3
+ Version: 2.3.1
4
4
  Summary:
5
5
  Author: Cristiano P. Ferrari
6
6
  Author-email: cristiano.ferrari@lbx.com.br
@@ -170,7 +170,7 @@ conexao.close()
170
170
  raise
171
171
  #
172
172
  #
173
- def db_insert_df(self, DataFrame, Tabela, Schema=None, Colunas=None, OnConflict=None, TypeCast=None, Returning=None): # Insere os dados de um dataframe em uma tabela equivalente no banco (exige mesma estrutura de colunas)
173
+ def db_insert_df(self, DataFrame, Tabela, Schema=None, Colunas=None, OnConflict=None, TypeCast=None, Returning=None, Truncar=False): # Insere os dados de um dataframe em uma tabela equivalente no banco (exige mesma estrutura de colunas)
174
174
  """
175
175
  Insere um DataFrame no PostgreSQL usando psycopg2 e execute_values().
176
176
 
@@ -223,6 +223,15 @@ conexao.close()
223
223
  try:
224
224
  self.Cursor = self.Conexao.cursor()
225
225
 
226
+ if Truncar:
227
+ try:
228
+ self.Cursor.execute(f"truncate table {Schema}.{Tabela} restart identity cascade;")
229
+ self.Conexao.commit()
230
+ except Exception as Err:
231
+ self.logger.erro(f'{__name__}:Erro [{Err}] ao TRUNCAR a tabela {Schema}.{Tabela}.')
232
+ self.Conexao.rollback()
233
+ raise
234
+
226
235
  if Returning:
227
236
  Retorno = []
228
237
  for valor in Valores:
@@ -233,7 +242,7 @@ conexao.close()
233
242
 
234
243
  self.Conexao.commit()
235
244
  except Exception as Err:
236
- self.logger.erro(f'{__name__}: Erro [{Err}] ao inserir dados na tabela {Schema}.{Tabela}!')
245
+ self.logger.erro(f'{__name__}: Erro [{Err}] ao INSERIR dados na tabela {Schema}.{Tabela}!')
237
246
  self.Conexao.rollback()
238
247
  finally:
239
248
  self.Cursor.close()
@@ -263,7 +272,7 @@ conexao.close()
263
272
  #
264
273
  def db_update(self, Query): # Retorna um cursor à partir de um select
265
274
  UpdRows = 0
266
- BlackList = ['INSERT ', 'SELECT ', 'CREATE ', 'DROP ', 'MERGE ', 'REPLACE ', 'CALL ', 'EXECUTE ']
275
+ BlackList = ['INSERT ', 'SELECT ', 'CREATE ', 'DROP ', 'MERGE ', 'REPLACE ' ] ## 'CALL ', 'EXECUTE ' ]
267
276
  if any(element in Query.upper() for element in BlackList):
268
277
  BlackListed = [element for element in BlackList if element in Query.upper()]
269
278
  self.logger.erro(f'{__name__}: Este método permite apenas updates e deletes. A query informada possui as seguintes palavras reservadas não aceitas: {BlackListed} e não foi executada!')
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "lbxtoolkit"
3
- version = "2.3.0"
3
+ version = "2.3.1"
4
4
  description = ""
5
5
  authors = ["Cristiano P. Ferrari <cristiano.ferrari@lbx.com.br>"]
6
6
  readme = "README.md"
File without changes