To avoid all the code generator having the same database connection logic, we may have a Python function like
def connect_with_data_source(data_source):
driver, source = data_source.split("://")
if driver != "mysql":
raise ValueError("connect_with_data_source doesn't support driver type {}".format(driver))
if driver == "mysql":
user, passwd, _, host, port = re.findall("^(\w*):(\w*)@(\w*)\((.*):(.*)\)/?.*$", source)[0]
from MySQLdb import connect
conn = connect(user=user,
passwd=passwd,
host=host,
port=int(port))
conn.driver = driver
return conn
@weiguoz @Yancey1989 What do you think?