How to use the asyncpg.create_pool function in asyncpg

To help you get started, we’ve selected a few asyncpg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pawbot-discord / Pawbot / index.py View on Github external
async def run():
    # Create a Dictionary under the name help attrs
    help_attrs = dict(hidden=True)
    # Log into the database
    credentials = {
        "user": config.dbname,
        "password": config.dbpass,
        "database": config.database,
        "host": "127.0.0.1",
    }
    db = await asyncpg.create_pool(**credentials)

    # Add tables if they don't exist
    await db.execute(
        "CREATE TABLE IF NOT EXISTS warnings(serverid bigint, userid bigint, warnings int);"
    )
    await db.execute(
        "CREATE TABLE IF NOT EXISTS modlogs(serverid bigint, caseid bigint, casenumber int, casetype varchar, target bigint, moderator bigint, reason varchar);"
    )
    await db.execute(
        "CREATE TABLE IF NOT EXISTS adminpanel(serverid bigint, joins int, leaves int, embeds int, nsfw int, automod int, modlog int);"
    )
    await db.execute(
        "CREATE TABLE IF NOT EXISTS automod(serverid bigint, autorole int, adblock int, lockdown int, antispam int, owo int, uwu int, ignorerole int, actionlog int);"
    )
    await db.execute(
        "CREATE TABLE IF NOT EXISTS idstore(serverid bigint, joinmsg varchar, leavemsg varchar, joinchan bigint, leavechan bigint, modlogchan bigint, ignorerolerole bigint, autorolerole bigint, actionlogchan bigint);"
github plone / guillotina / guillotina / db / storages / pg.py View on Github external
async def initialize(self, loop=None, **kw):
        self._connection_options = kw
        if loop is None:
            loop = asyncio.get_event_loop()
        self._pool = await asyncpg.create_pool(
            dsn=self._dsn,
            max_size=self._pool_size,
            min_size=2,
            connection_class=app_settings['pg_connection_class'],
            loop=loop,
            **kw)

        # shared read connection on all transactions
        self._read_conn = await self.open()
        try:
            await self.initialize_tid_statements()
            await self._read_conn.execute(CREATE_TRASH)
        except asyncpg.exceptions.UndefinedTableError:
            await self.create()
            await self.initialize_tid_statements()
            await self._read_conn.execute(CREATE_TRASH)
github DevAlone / pikagraphs / bot / db.py View on Github external
async def get_pool(self):
        if self._pool is None:
            self._pool = await asyncpg.create_pool(
                user=settings.DATABASES["default"]["USER"],
                password=settings.DATABASES["default"]["PASSWORD"],
                database=settings.DATABASES["default"]["NAME"],
                max_size=settings.DATABASES["default"]["CONCURRENT_TASKS_COUNT"],
            )

        return self._pool
github alin23 / spfy / spfy / asynch / client.py View on Github external
async def dbpool(self):
        if not self._dbpool and config.database.connection.provider == "postgres":
            db_config = {
                k: v for k, v in config.database.connection.items() if k != "provider"
            }
            self._dbpool = await asyncpg.create_pool(
                **db_config, **(config.database.pool or {}), init=init_db_connection
            )
            logger.info(
                "Created DB Pool with min=%d max=%s",
                self._dbpool._minsize,
                self._dbpool._maxsize,
            )
        return self._dbpool
github plone / guillotina / guillotina / db / one_connection_storage.py View on Github external
async def initialize(self, loop=None):
        if loop is None:
            loop = asyncio.get_event_loop()
        self._pool = await asyncpg.create_pool(
            dsn=self._dsn,
            max_size=self._pool_size,
            min_size=2,
            loop=loop)

        # Check DB
        stmt = """
            CREATE TABLE IF NOT EXISTS objects (
                zoid        BIGINT NOT NULL PRIMARY KEY,
                tid         BIGINT NOT NULL,
                state_size  BIGINT NOT NULL,
                part        BIGINT NOT NULL,
                resource    BOOLEAN NOT NULL,
                of          BIGINT,
                otid        BIGINT,
                parent_id   BIGINT,
github aio-libs / aiohttp-devtools / aiohttp_devtools / start / template / app / main.py View on Github external
async def startup(app: web.Application):
    settings: Settings = app['settings']
    await prepare_database(settings, False)
    app['pg'] = await asyncpg.create_pool(dsn=settings.pg_dsn, min_size=2)
github bitaps-com / pybtc / pybtc / connector / block_loader.py View on Github external
async def message_loop(self):
        try:
            if self.dsn:
                self.db = await asyncpg.create_pool(dsn=self.dsn, min_size=1, max_size=1)
            self.reader = await self.get_pipe_reader(self.in_reader)
            self.writer = await self.get_pipe_writer(self.out_writer)
            while True:
                msg_type, msg = await self.pipe_get_msg(self.reader)
                if msg_type ==  b'pipe_read_error':
                    return

                if msg_type == b'get':
                    self.loop.create_task(self.load_blocks(bytes_to_int(msg), self.rpc_batch_limit))
                    continue

                if msg_type == b'rpc_batch_limit':
                    self.rpc_batch_limit = bytes_to_int(msg)
                    continue

                if msg_type == b'target_height':
github henry232323 / RPGBot / cogs / utils / db.py View on Github external
async def connect(self):
        self._conn = await asyncpg.create_pool(user='root', password='root',
                                               database='pokerpg', host='127.0.0.1')
github actorcloud / ActorCloud / server / app / services / tasks_scheduler / timer_tasks / app / base.py View on Github external
async def open_database_connection_poll():
    _pool = await asyncpg.create_pool(
        host=project_config.get('POSTGRES_HOST', 'localhost'),
        port=project_config.get('POSTGRES_PORT', 5432),
        user=project_config.get('POSTGRES_USER', 'actorcloud'),
        password=project_config.get('POSTGRES_PASSWORD', 'public'),
        database=project_config.get('POSTGRES_DATABASE', 'actorcloud'),
        min_size=5, max_size=10
    )
    await db.open(_pool)
github Run1e / AceBot / ace.py View on Github external
super().__init__(**attrs)

	discord.Embed = Embed

	def patched_execute(old):
		async def new(self, query, args, limit, timeout, return_status=False):
			log.debug(query)
			return await old(self, query, args, limit, timeout, return_status)

		return new

	asyncpg.Connection._execute = patched_execute(asyncpg.Connection._execute)

	# connect to db
	log.info('Creating postgres pool')
	db = await asyncpg.create_pool(DB_BIND)

	# init bot
	log.info('Initializing bot')
	bot = AceBot(db=db, loop=loop)

	# start it
	log.info('Logging in and starting bot')
	await bot.start(BOT_TOKEN)