本文整理汇总了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()