Skip to content

database

DatabaseResource

Bases: ConfigurableResource

Database connection.

Source code in bag3d/common/resources/database.py
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
49
50
51
52
53
54
55
56
57
58
59
60
class DatabaseResource(ConfigurableResource):
    """
    Database connection.
    """

    host: str
    user: str
    password: str
    dbname: str
    port: str
    other_params: Permissive()

    def __init__(
        self,
        host: str,
        user: str,
        password: str,
        dbname: str,
        port: str,
        other_params: Optional[Permissive()] = None,
    ):
        super().__init__(
            host=host,
            user=user,
            password=password,
            dbname=dbname,
            port=port,
            other_params=other_params or {},
        )
        conn = DatabaseConnection(
            user=self.user,
            password=self.password,
            host=self.host,
            port=self.port,
            dbname=self.dbname,
            **self.other_params,
        )
        # Create the utility Postgres functions
        PostgresFunctions(conn)

    @property
    def connect(self):
        conn = DatabaseConnection(
            user=self.user,
            password=self.password,
            host=self.host,
            port=self.port,
            dbname=self.dbname,
            **self.other_params,
        )
        return conn