Beispiel #1
0
 def show_tables(self, cnx: PooledMySQLConnection = None) -> list:
     """
     数据库小助手-获取库中的表\n
     :param cnx: 数据库连接,装饰器自动赋值
     :return: 将数据库中表名列表予以返回
     """
     cursor = cnx.cursor()
     cursor.execute("SHOW TABLES")
     tables = [row[0] for row in cursor.fetchall()]
     return tables
Beispiel #2
0
 def get_table_fields(self,
                      cnx: PooledMySQLConnection = None,
                      table: str = None):
     """
     数据库小助手-获取表结构\n
     :param cnx: 数据库连接,装饰器自动赋值
     :param table: 表名
     :return: 将表结构的字典列表予以返回(key:字段名,type:字段类型,null:是否为空)
     """
     cursor = cnx.cursor()
     cursor.execute(f"DESC {table}")
     feilds = [{
         'key': f[0],
         'type': f[1],
         'null': 'NULL' if f[2] == 'YES' else 'NOT NULL'
     } for f in cursor.fetchall()]
     return feilds
Beispiel #3
0
 def build_cursor(self, connection: PooledMySQLConnection) -> MySQLCursor:
     return connection.cursor()
Beispiel #4
0
 def _get_cursor(self, connetion: PooledMySQLConnection) -> MySQLCursor:
     return connetion.cursor()