Python playhouse.postgres_ext.PostgresqlExtDatabase() Examples

The following are 4 code examples of playhouse.postgres_ext.PostgresqlExtDatabase(). 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 playhouse.postgres_ext , or try the search function .
Example #1
Source File: config.py    From tildemush with GNU General Public License v3.0 6 votes vote down vote up
def get_db():
    db = None

    if env == 'test':
        db = PostgresqlExtDatabase(
            TEST_DB_NAME,
            user=DB_UN,
            password=DB_PW,
            host=DB_HOST,
            port=DB_PORT)
    else:
        db = PostgresqlExtDatabase(
            DB_NAME,
            user=DB_UN,
            password=DB_PW,
            host=DB_HOST,
            port=DB_PORT)

    return db 
Example #2
Source File: config.py    From open-syllabus-project with Apache License 2.0 5 votes vote down vote up
def get_db(self, name='default'):

        """
        Get a Postgres database object.

        Args:
            name (str): The database key.

        Returns:
            The database object.
        """

        defaults = self['postgres']['default']['args']

        db = (
            self['postgres']
            .get(name, {})
            .get('args', {})
        )

        args = dict(
            list(defaults.items()) +
            list(db.items())
        )

        return PostgresqlExtDatabase(
            autorollback=True,
            register_hstore=False,
            **args
        ) 
Example #3
Source File: test.py    From peewee-db-evolve with GNU Lesser General Public License v3.0 5 votes vote down vote up
def setUp(self):
    os.system("createdb peeweedbevolve_test && psql peeweedbevolve_test -c 'create extension IF NOT EXISTS hstore;' > /dev/null 2> /dev/null")
    self.db = pwe.PostgresqlExtDatabase('peeweedbevolve_test')
    self.db.connect()
    peeweedbevolve.clear() 
Example #4
Source File: tools.py    From TorCMS with MIT License 4 votes vote down vote up
def get_cfg():
    '''
    Get the configure value.
    '''

    cfg_var = dir(cfg)

    if 'DB_CFG' in cfg_var:
        db_cfg = cfg.DB_CFG
    else:
        db_cfg = ConfigDefault.DB_CFG

    if 'SMTP_CFG' in cfg_var:
        smtp_cfg = cfg.SMTP_CFG
    else:
        smtp_cfg = ConfigDefault.SMTP_CFG

    if 'SITE_CFG' in cfg_var:
        site_cfg = cfg.SITE_CFG
    else:
        site_cfg = ConfigDefault.SITE_CFG

    if 'ROLE_CFG' in cfg_var:
        role_cfg = cfg.ROLE_CFG
    else:
        role_cfg = ConfigDefault.ROLE_CFG

    role_cfg['view'] = role_cfg.get('view', '')
    role_cfg['add'] = role_cfg.get('add', '1000')
    role_cfg['edit'] = role_cfg.get('edit', '2000')
    role_cfg['delete'] = role_cfg.get('delete', '3000')
    role_cfg['admin'] = role_cfg.get('admin', '0300')

    ###################################################################

    site_url = site_cfg['site_url'].strip('/')
    site_cfg['site_url'] = site_url
    infor = site_url.split(':')
    if len(infor) == 1:
        site_cfg['PORT'] = 8888
    else:
        site_cfg['PORT'] = infor[-1]

    if 'DEBUG' in site_cfg:
        pass
    else:
        site_cfg['DEBUG'] = False

    db_con = PostgresqlExtDatabase(
        db_cfg['db'],
        user=db_cfg.get('user', db_cfg['db']),
        password=db_cfg['pass'],
        host=db_cfg.get('host', '127.0.0.1'),
        port=db_cfg.get('port', '5432'),
        autocommit=True,
        autorollback=True)

    return (db_con, smtp_cfg, site_cfg, role_cfg)