Fixes in documentation for db model
This commit is contained in:
parent
ae3bf3f6c3
commit
3433b3150a
6 changed files with 159 additions and 2 deletions
|
|
@ -12,6 +12,14 @@ import traceback
|
|||
engine=None
|
||||
|
||||
class SqlClass:
|
||||
"""Class used how interface to sqlalchemy for connect to mysql engine
|
||||
|
||||
Attributes:
|
||||
cursors_connect (pymysql.cursors.DictCursor): Cursor dict connection to database
|
||||
disable_pool (boolean): If True then not exists mysql pool, if False, use sql pool for better connections.
|
||||
pymsql_install (boolean): If True, pymysql is used how mysqldb classic python module.
|
||||
pool_size (int): The size of the mysql pool.
|
||||
"""
|
||||
|
||||
cursors_connect=None
|
||||
disable_pool=False
|
||||
|
|
@ -19,8 +27,18 @@ class SqlClass:
|
|||
pool_size=15
|
||||
|
||||
def __init__(self, connection):
|
||||
"""
|
||||
Args:
|
||||
connection (dict): A dict with the configurations of SqlClass connection
|
||||
Attributes:
|
||||
error_connection (str): A string where errors are saved
|
||||
connection (dict): A dict with the configurations of SqlClass connection
|
||||
conn (MySQL Connection): A PyMySQL or Mysqldb connection
|
||||
connected (bool): Simple bool for check if was connected to mysql
|
||||
pool_recycle (int): Time limite for recycle the pool by inactivity
|
||||
"""
|
||||
|
||||
self.max_overflow=-1
|
||||
#self.max_overflow=-1
|
||||
self.error_connection=""
|
||||
# Data of connection
|
||||
self.connection=connection
|
||||
|
|
@ -32,6 +50,8 @@ class SqlClass:
|
|||
|
||||
|
||||
def connect(self):
|
||||
"""Method for connect to mysql db using pymysql or mysqldb
|
||||
"""
|
||||
|
||||
global engine
|
||||
|
||||
|
|
@ -132,7 +152,13 @@ class SqlClass:
|
|||
#Make def query more simple if not debugging.
|
||||
|
||||
def query(self, sql_query, arguments=[], name_connection="default"):
|
||||
"""Method for send a sql query to mysql server
|
||||
|
||||
Args:
|
||||
sql_query (str): The sql sentence to execute. For data you should use %s character.
|
||||
arguments (list): The data used in sql sentence. This data substitute the %s characters.
|
||||
name_connection (str): The name of dict element with the configuration of connection, without used in this moment.
|
||||
"""
|
||||
|
||||
cursor=self.conn.cursor(SqlClass.cursors_connect)
|
||||
|
||||
|
|
@ -194,12 +220,16 @@ class SqlClass:
|
|||
#return cursor.fetchone()
|
||||
|
||||
def __del__(self):
|
||||
"""Typical method used when class is deleted from memory. Close the connextion if exists.
|
||||
"""
|
||||
|
||||
if self.conn:
|
||||
|
||||
self.conn.close()
|
||||
|
||||
def close(self, name_connection="default"):
|
||||
"""Method used for close the connection if you want close connection and open other.
|
||||
"""
|
||||
|
||||
if self.conn:
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue