blob: 3e0fc972e60177fe45f0c524cc3bb9a916253901 (
plain) (
blame)
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
|
// SPDX-License-Identifier: AGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org>
// Package database provides stubs and wrappers for databases.
package database
import (
"context"
"fmt"
"github.com/jackc/pgx/v5/pgxpool"
)
// Database is a wrapper around pgxpool.Pool to provide a common interface for
// other packages in the forge.
type Database struct {
*pgxpool.Pool
}
// Open opens a new database connection pool using the provided connection
// string. It returns a Database instance and an error if any occurs.
// It is run indefinitely in the background.
func Open(ctx context.Context, config Config) (Database, error) {
db, err := pgxpool.New(ctx, config.Conn)
if err != nil {
err = fmt.Errorf("create pgxpool: %w", err)
}
return Database{db}, err
}
type Config struct {
Type string `scfg:"type"`
Conn string `scfg:"conn"`
}
|