當前位置: 首頁>>代碼示例>>Python>>正文


Python peewee.Proxy方法代碼示例

本文整理匯總了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() 
開發者ID:05bit,項目名稱:peewee-async,代碼行數:24,代碼來源:__init__.py

示例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) 
開發者ID:kszucs,項目名稱:aiopeewee,代碼行數:27,代碼來源:fields.py

示例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) 
開發者ID:PyPlanet,項目名稱:PyPlanet,代碼行數:23,代碼來源:database.py

示例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 
開發者ID:danielecook,項目名稱:Quiver-alfred,代碼行數:15,代碼來源:flask_utils.py

示例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 
開發者ID:danielecook,項目名稱:Quiver-alfred,代碼行數:11,代碼來源:flask_utils.py

示例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, []) 
開發者ID:quay,項目名稱:quay,代碼行數:11,代碼來源:readreplica.py

示例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) 
開發者ID:tracboat,項目名稱:tracboat,代碼行數:7,代碼來源:test_model.py

示例8: DBProxy

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import Proxy [as 別名]
def DBProxy():
        if not PWDatabase.__proxy:
            PWDatabase.__proxy = Proxy()
        return PWDatabase.__proxy 
開發者ID:CityOfZion,項目名稱:neo-python,代碼行數:6,代碼來源:PWDatabase.py


注:本文中的peewee.Proxy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。