Python peewee.Proxy() Examples
The following are 8
code examples of peewee.Proxy().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
peewee
, or try the search function
.
Example #1
Source File: __init__.py From peewee-async with MIT License | 6 votes |
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()
Example #2
Source File: fields.py From aiopeewee with MIT License | 6 votes |
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)
Example #3
Source File: database.py From PyPlanet with GNU General Public License v3.0 | 6 votes |
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)
Example #4
Source File: flask_utils.py From Quiver-alfred with MIT License | 5 votes |
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
Example #5
Source File: flask_utils.py From Quiver-alfred with MIT License | 5 votes |
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
Example #6
Source File: readreplica.py From quay with Apache License 2.0 | 5 votes |
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, [])
Example #7
Source File: test_model.py From tracboat with GNU General Public License v3.0 | 5 votes |
def test_get_model_supported(version): M = model.get_model(version) assert M assert M.database_proxy assert isinstance(M.database_proxy, peewee.Proxy)
Example #8
Source File: PWDatabase.py From neo-python with MIT License | 5 votes |
def DBProxy(): if not PWDatabase.__proxy: PWDatabase.__proxy = Proxy() return PWDatabase.__proxy