本文整理匯總了Python中playhouse.db_url.connect方法的典型用法代碼示例。如果您正苦於以下問題:Python db_url.connect方法的具體用法?Python db_url.connect怎麽用?Python db_url.connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類playhouse.db_url
的用法示例。
在下文中一共展示了db_url.connect方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from playhouse import db_url [as 別名]
# 或者: from playhouse.db_url import connect [as 別名]
def __init__(self, url):
self._url = url
parse_result = urlparse(url)
self._database_path = parse_result.path[1:]
# Connect to the database.
self._database = connect(url)
self._database.connect()
# Introspect the database and generate models.
self._introspector = Introspector.from_database(self._database)
self._models = self._introspector.generate_models(skip_invalid=True)
self._migrator = SchemaMigrator.from_database(self._database)
class BaseModel(Model):
class Meta:
database = self._database
self._base_model = BaseModel
self._export_formats = self.get_export_formats()
self._import_formats = self.get_import_formats()
示例2: _load_database
# 需要導入模塊: from playhouse import db_url [as 別名]
# 或者: from playhouse.db_url import connect [as 別名]
def _load_database(self, app, config_value):
if isinstance(config_value, Database):
database = config_value
elif isinstance(config_value, dict):
database = self._load_from_config_dict(dict(config_value))
else:
# Assume a database connection URL.
database = db_url_connect(config_value)
if isinstance(self.database, Proxy):
self.database.initialize(database)
else:
self.database = database
示例3: connect
# 需要導入模塊: from playhouse import db_url [as 別名]
# 或者: from playhouse.db_url import connect [as 別名]
def connect(self):
self._database.connect()
示例4: __enter__
# 需要導入模塊: from playhouse import db_url [as 別名]
# 或者: from playhouse.db_url import connect [as 別名]
def __enter__(self):
self.connect()
return self
示例5: asyncpg_init
# 需要導入模塊: from playhouse import db_url [as 別名]
# 或者: from playhouse.db_url import connect [as 別名]
def asyncpg_init(db_uri):
import asyncpg
async def create_conn():
global asyncpg_conn
asyncpg_conn = await asyncpg.connect(db_uri)
async_run(create_conn)
# asyncpg_init(config.DATABASE_URI)
示例6: init_db
# 需要導入模塊: from playhouse import db_url [as 別名]
# 或者: from playhouse.db_url import connect [as 別名]
def init_db(database_url):
"""
This function initializes the global database with the given url.
"""
# utility function to parse database urls
from playhouse.db_url import connect
# initialize the peewee database with the appropriate engine
db.initialize(connect(database_url))
示例7: setup_db
# 需要導入模塊: from playhouse import db_url [as 別名]
# 或者: from playhouse.db_url import connect [as 別名]
def setup_db():
global home, database
database_url = config.get("db", "sqlite:///diffengine.db")
logging.debug("connecting to db %s", database_url)
database_handler = connect(database_url)
database.initialize(database_handler)
database.connect()
database.create_tables([Feed, Entry, FeedEntry, EntryVersion, Diff], safe=True)
if isinstance(database_handler, SqliteDatabase):
try:
migrator = SqliteMigrator(database_handler)
migrate(migrator.add_index("entryversion", ("url",), False))
except OperationalError as e:
logging.debug(e)
示例8: create_tables
# 需要導入模塊: from playhouse import db_url [as 別名]
# 或者: from playhouse.db_url import connect [as 別名]
def create_tables():
db.connect()
db.create_tables([Pokemon, Pokestop, Gym], safe=True)
db.close()