|
@@ -2,15 +2,13 @@
|
|
@desc 数据库操作方法封装
|
|
@desc 数据库操作方法封装
|
|
@auth chenkai
|
|
@auth chenkai
|
|
@date 2020/11/19
|
|
@date 2020/11/19
|
|
-@py_version py3.7
|
|
|
|
|
|
+@py_version py3.6
|
|
"""
|
|
"""
|
|
import pymysql
|
|
import pymysql
|
|
-# from clickhouse_sqlalchemy import make_session
|
|
|
|
-# from sqlalchemy import create_engine
|
|
|
|
import logging as log
|
|
import logging as log
|
|
import pandas as pd
|
|
import pandas as pd
|
|
import time
|
|
import time
|
|
-from model.common.log import logger
|
|
|
|
|
|
+from model.log import logger
|
|
log = logger()
|
|
log = logger()
|
|
pd.set_option('display.max_columns', None)
|
|
pd.set_option('display.max_columns', None)
|
|
pd.set_option('display.width', 1000)
|
|
pd.set_option('display.width', 1000)
|
|
@@ -579,34 +577,27 @@ class MysqlOperation:
|
|
log.debug('update %s rows, cost: %s' % (len(key_values), time.time() - t0))
|
|
log.debug('update %s rows, cost: %s' % (len(key_values), time.time() - t0))
|
|
|
|
|
|
|
|
|
|
-# class CkOperation:
|
|
|
|
-# cursor = None
|
|
|
|
-# session = None
|
|
|
|
-#
|
|
|
|
-# def __init__(self, conf):
|
|
|
|
-# try:
|
|
|
|
-# connection = 'clickhouse://{user}:{passwd}@{host}:{port}/{db}'.format(**conf)
|
|
|
|
-# engine = create_engine(connection, pool_size=100, pool_recycle=3600, pool_timeout=20)
|
|
|
|
-# self.session = make_session(engine)
|
|
|
|
-#
|
|
|
|
-# except Exception as e:
|
|
|
|
-# log.info(e)
|
|
|
|
-#
|
|
|
|
-# def execute(self, sql):
|
|
|
|
-# self.cursor = self.session.execute(sql)
|
|
|
|
-# try:
|
|
|
|
-# fields = self.cursor._metadata.keys
|
|
|
|
-# return [dict(zip(fields, item)) for item in self.cursor.fetchall()]
|
|
|
|
-# except Exception as e:
|
|
|
|
-# log.info(e)
|
|
|
|
-#
|
|
|
|
-# def getData_pd(self, sql):
|
|
|
|
-# li = self.execute(sql)
|
|
|
|
-# return pd.DataFrame(li)
|
|
|
|
-#
|
|
|
|
-# def getOne(self, sql):
|
|
|
|
-# li = self.execute(sql)
|
|
|
|
-# return [i for i in li[0].values()][0]
|
|
|
|
|
|
+ def getColumn(self,table,flag=0):
|
|
|
|
+ "获取表的所有列"
|
|
|
|
+ sql="SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` " \
|
|
|
|
+ "WHERE `TABLE_NAME`='{}' ORDER BY ordinal_position".format(table)
|
|
|
|
+ self.cursor.execute(sql)
|
|
|
|
+ a= self.cursor.fetchall()
|
|
|
|
+ str=''
|
|
|
|
+ li=[]
|
|
|
|
+ for i in a:
|
|
|
|
+ str+=i[0]+','
|
|
|
|
+ li.append(i[0])
|
|
|
|
+
|
|
|
|
+ if flag:
|
|
|
|
+ return li
|
|
|
|
+ else:
|
|
|
|
+ return str[:-1]
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|