Reformatted
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from aore.dbutils.dbimpl import DBImpl
|
||||
from aore.config import db as dbparams
|
||||
from aore.dbutils.dbschemas import db_shemas, allowed_tables
|
||||
from traceback import format_exc
|
||||
import psycopg2
|
||||
import logging
|
||||
from traceback import format_exc
|
||||
|
||||
import psycopg2
|
||||
|
||||
from aore.config import db as dbparams
|
||||
from aore.dbutils.dbimpl import DBImpl
|
||||
from aore.dbutils.dbschemas import db_shemas
|
||||
|
||||
|
||||
class DbHandler:
|
||||
@@ -13,12 +15,12 @@ class DbHandler:
|
||||
logging.basicConfig(format='%(asctime)s %(message)s')
|
||||
self.db = DBImpl(psycopg2, dbparams)
|
||||
|
||||
def bulk_csv(self, chunck_size, table_name, csv_file_name):
|
||||
def bulk_csv(self, chunk_size, table_name, csv_file_name):
|
||||
sql_query = "COPY \"{}\" ({}) FROM '{}' DELIMITER '\t' NULL 'NULL'". \
|
||||
format(table_name,
|
||||
", ".join(
|
||||
db_shemas[table_name].fields),
|
||||
csv_file_name)
|
||||
db_shemas[table_name].fields),
|
||||
csv_file_name)
|
||||
try:
|
||||
cur = self.db.get_cursor()
|
||||
cur.execute(sql_query)
|
||||
@@ -27,7 +29,7 @@ class DbHandler:
|
||||
self.db.transaction_rollback()
|
||||
logging.error("Error updating sql. Reason : {}".format(format_exc()))
|
||||
|
||||
logging.warning("Inserted {} queries FROM {}".format(chunck_size, csv_file_name))
|
||||
logging.warning("Inserted {} queries FROM {}".format(chunk_size, csv_file_name))
|
||||
|
||||
def pre_create(self):
|
||||
f = open("aore/templates/postgre/pre_create.sql")
|
||||
@@ -44,4 +46,4 @@ class DbHandler:
|
||||
|
||||
def pre_update(self):
|
||||
# TODO: update actions
|
||||
pass
|
||||
pass
|
||||
|
||||
@@ -30,4 +30,4 @@ class DBImpl:
|
||||
if cur:
|
||||
cur.close()
|
||||
|
||||
return rows
|
||||
return rows
|
||||
|
||||
Reference in New Issue
Block a user