本文整理匯總了Python中db.DB.init_pool方法的典型用法代碼示例。如果您正苦於以下問題:Python DB.init_pool方法的具體用法?Python DB.init_pool怎麽用?Python DB.init_pool使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類db.DB
的用法示例。
在下文中一共展示了DB.init_pool方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setUpClass
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import init_pool [as 別名]
def setUpClass(cls):
app.config['DATABASE'] = config.connstr
app.config['TESTING'] = True
DB.init_pool(app.config['DATABASE'])
with DB(False) as (conn, cursor):
# this pretty much cascades to everything, except animals
cursor.execute("TRUNCATE users CASCADE")
# create a single user/distribution/version
cursor.execute("INSERT INTO users (user_name, full_name) VALUES ('test_user', 'test user full name')")
cursor.execute("INSERT INTO distributions (user_id, dist_name) VALUES (currval('users_id_seq'), 'testdistr')")
cursor.execute("INSERT INTO distribution_versions (dist_id, dist_version, dist_date, dist_status) VALUES (currval('distributions_id_seq'), '1.2.3', '2014-01-02 03:04:05', 'stable')")
cursor.execute("INSERT INTO users (user_name, full_name) VALUES ('test_user2', 'test user full name')")
cursor.execute("INSERT INTO distributions (user_id, dist_name) VALUES (currval('users_id_seq'), 'testdistr2')")
cursor.execute("INSERT INTO distribution_versions (dist_id, dist_version, dist_date, dist_status) VALUES (currval('distributions_id_seq'), '1.2.4', '2014-01-02 03:04:05', 'stable')")
cursor.execute("INSERT INTO users (user_name, full_name) VALUES ('test_user3', 'test user full name')")
cursor.execute("INSERT INTO distributions (user_id, dist_name) VALUES (currval('users_id_seq'), 'testdistr3')")
cursor.execute("INSERT INTO distribution_versions (dist_id, dist_version, dist_date, dist_status) VALUES (currval('distributions_id_seq'), '1.2.5', '2014-01-02 03:04:05', 'stable')")
conn.commit()
示例2: setUpClass
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import init_pool [as 別名]
def setUpClass(cls):
app.config['DATABASE'] = config.connstr
app.config['TESTING'] = True
DB.init_pool(app.config['DATABASE'])
with DB(False) as (conn, cursor):
# this pretty much cascades to everything, except animals
cursor.execute("TRUNCATE animals CASCADE")
conn.commit()
示例3: Flask
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import init_pool [as 別名]
from flask.ext.restful import Api
# this is where the implementation is placed
sys.path.append('src')
from db import DB
import cors, jsonp
# create flask application
app = Flask(__name__)
# load config from the config.api dictionary
app.config.from_object('config.api')
# initialize the database pool
DB.init_pool(app.config['DATABASE'])
# create the REST api
api = Api(app)
# CORS / allow calls from all origins (well, especially pgxn-tester.org, but not only)
api.decorators=[cors.crossdomain(origin='*'), jsonp.support_jsonp]
import index
import distributions
import users
import machines
import results
import stats
api.add_resource(index.Index, '/')