예제 #1
0
def async_connect():  # 异步连接
    conf = DATABASE.get('default', {})
    conf.update({
        'autocommit': True,
        'cursorclass': tornado_mysql.cursors.DictCursor
    })
    return tornado_mysql.connect(**conf)
예제 #2
0
if __name__ == '__main__':
    args = sys.argv[1:]
    if args[0] == 'run':
        app = Application()
        print('Starting server on port 9000...')
        # sockets = netutil.bind_sockets(9000, '127.0.0.1', socket.AF_UNSPEC)
        # process.fork_processes(5)
        server = httpserver.HTTPServer(app)
        server.listen(9000)
        # server.start(num_processes=4)
        server.start()
        # server.add_sockets(sockets)
        ioloop.IOLoop.instance().start()

    elif args[0] == 'dbshell':
        config = DATABASE.get('default', {})
        os.system('mysql -u{user} -p{password} -D{database} -A'.format(
            user=config.get('user', 'root'),
            password=config.get('password', ''),
            database=config.get('database', 'tequila')))

    elif args[0] == 'migrate':
        config = DATABASE.get('default', {})
        init_sql = 'mysql -u{user} -p{password} -D{database} -A < database/migration.sql'.format(
            user=config.get('user', 'root'),
            password=config.get('password', ''),
            database=config.get('database', 'tequila'))
        print('Initializing tables to database {}...'.format(
            config.get('database')))
        data = os.system(init_sql)
        if data == 256:
예제 #3
0
def async_pool():  # 连接池
    conf = DATABASE.get('default', {})
    conf.update({'cursorclass': tornado_mysql.cursors.DictCursor})
    POOL = pools.Pool(conf, max_idle_connections=1, max_recycle_sec=3)
    return POOL
예제 #4
0
def connect():  # 连接默认数据库
    config = DATABASE.get('default', {})
    conn = pymysql.connections.Connection(**config)
    return conn.cursor(cursor=pymysql.cursors.DictCursor)
예제 #5
0
 def __init__(self):
     self.config = DATABASE.get('default', {})
     self.connection = pymysql.connections.Connection(**self.config)
     self.cursor = self.connection.cursor()
     self.dict_cusor = self.connection.cursor(
         cursor=pymysql.cursors.DictCursor)