本文整理汇总了Python中peewee.Proxy方法的典型用法代码示例。如果您正苦于以下问题:Python peewee.Proxy方法的具体用法?Python peewee.Proxy怎么用?Python peewee.Proxy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类peewee
的用法示例。
在下文中一共展示了peewee.Proxy方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_proxy_database
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import Proxy [as 别名]
def test_proxy_database(self):
loop = asyncio.new_event_loop()
database = peewee.Proxy()
TestModel._meta.database = database
objects = peewee_async.Manager(database, loop=loop)
async def test(objects):
text = "Test %s" % uuid.uuid4()
await objects.create(TestModel, text=text)
await objects.get(TestModel, text=text)
for key in DB_CLASSES:
params = DB_DEFAULTS.get(key) or {}
params.update(DB_OVERRIDES.get(key) or {})
database.initialize(DB_CLASSES[key](**params))
TestModel.create_table(True)
loop.run_until_complete(test(objects))
loop.run_until_complete(objects.close())
TestModel.drop_table(True)
loop.close()
示例2: add_to_class
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import Proxy [as 别名]
def add_to_class(self, model_class, name):
if isinstance(self._through_model, Proxy):
def callback(through_model):
self._through_model = through_model
self.add_to_class(model_class, name)
self._through_model.attach_callback(callback)
return
elif isinstance(self._through_model, DeferredThroughModel):
self._through_model.set_field(model_class, self, name)
return
self.name = name
self.model_class = model_class
if not self.verbose_name:
self.verbose_name = re.sub('_+', ' ', name).title()
setattr(model_class, name, self._get_descriptor())
if not self._is_backref:
backref = AioManyToManyField(
self.model_class,
through_model=self._through_model,
_is_backref=True)
related_name = self._related_name or model_class._meta.name + 's'
backref.add_to_class(self.rel_model, related_name)
示例3: __init__
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import Proxy [as 别名]
def __init__(self, engine_cls, instance, *args, **kwargs):
"""
Initiate database.
:param engine_cls: Engine class
:param instance: Instance of the app.
:param args: *
:param kwargs: **
:type instance: pyplanet.core.instance.Instance
"""
self.engine = engine_cls(*args, **kwargs)
self.instance = instance
self.migrator = Migrator(self.instance, self)
self.registry = Registry(self.instance, self)
self.objects = peewee_async.Manager(self.engine, loop=self.instance.loop)
# Don't allow any sync code.
if hasattr(self.engine, 'allow_sync'):
self.engine.allow_sync = False
Proxy.initialize(self.engine)
示例4: _load_database
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import Proxy [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
示例5: Model
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import Proxy [as 别名]
def Model(self):
if self._app is None:
database = getattr(self, 'database', None)
if database is None:
self.database = Proxy()
if not hasattr(self, '_model_class'):
self._model_class = self.get_model_class()
return self._model_class
示例6: _read_only_config
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import Proxy [as 别名]
def _read_only_config(cls):
read_only_config = getattr(cls._meta, "read_only_config", None)
if read_only_config is None:
return ReadOnlyConfig(False, [])
if isinstance(read_only_config, Proxy) and read_only_config.obj is None:
return ReadOnlyConfig(False, [])
return read_only_config.obj or ReadOnlyConfig(False, [])
示例7: test_get_model_supported
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import Proxy [as 别名]
def test_get_model_supported(version):
M = model.get_model(version)
assert M
assert M.database_proxy
assert isinstance(M.database_proxy, peewee.Proxy)
示例8: DBProxy
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import Proxy [as 别名]
def DBProxy():
if not PWDatabase.__proxy:
PWDatabase.__proxy = Proxy()
return PWDatabase.__proxy