~liberachat/beryllia

ref: bb37c8118ef45799fe6abe5955094585c829429c beryllia/beryllia/database/__init__.py -rw-r--r-- 1.7 KiB
bb37c811 — Jess Porter fix a number of kcheck-related SELECTs that were not ordering output (#57) 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import asyncpg
from typing import Optional

from .cliconn import CliconnTable, CliexitTable
from .nick_change import NickChangeTable
from .statsp import StatsPTable
from .kline import KLineTable
from .kline_kill import KLineKillTable
from .kline_reject import KLineRejectTable
from .kline_remove import KLineRemoveTable
from .kline_tag import KLineTagTable
from .preference import PreferenceTable

from .registration import RegistrationTable
from .email_resolve import EmailResolveTable

from ..normalise import SearchNormaliser


class Database(object):
    def __init__(self, pool: asyncpg.Pool, normaliser: SearchNormaliser):

        self.kline = KLineTable(pool, normaliser)
        self.kline_reject = KLineRejectTable(pool, normaliser)
        self.kline_remove = KLineRemoveTable(pool, normaliser)
        self.kline_kill = KLineKillTable(pool, normaliser)
        self.kline_tag = KLineTagTable(pool, normaliser)
        self.cliconn = CliconnTable(pool, normaliser)
        self.cliexit = CliexitTable(pool, normaliser)
        self.nick_change = NickChangeTable(pool, normaliser)
        self.statsp = StatsPTable(pool, normaliser)
        self.preference = PreferenceTable(pool, normaliser)
        self.registration = RegistrationTable(pool, normaliser)
        self.email_resolve = EmailResolveTable(pool, normaliser)

    @staticmethod
    async def connect(
        username: str,
        password: Optional[str],
        hostname: Optional[str],
        db_name: str,
        normaliser: SearchNormaliser,
    ):

        pool = await asyncpg.create_pool(
            user=username, password=password, host=hostname, database=db_name
        )
        return Database(pool, normaliser)