agendas/db.go

61 lines
1.5 KiB
Go
Raw Normal View History

2024-12-30 15:00:42 -05:00
package main
import (
"context"
"fmt"
2024-12-30 19:13:05 -05:00
"log"
2024-12-30 15:00:42 -05:00
2024-12-30 19:13:05 -05:00
"git.agecem.com/bottin/agendas/queries"
2024-12-30 15:00:42 -05:00
"github.com/jackc/pgx/v5/pgxpool"
)
type DBClient struct {
Pool *pgxpool.Pool
}
func (d DBClient) Ping(ctx context.Context) error {
select {
case <-ctx.Done():
return ctx.Err()
default:
if d.Pool == nil {
return fmt.Errorf("db: cannot check health using nil connection pool")
}
return d.Pool.Ping(ctx)
}
}
func (d DBClient) Init(ctx context.Context) error {
//TODO check context is not closed
//TODO check *DB is not nil
2024-12-30 19:13:05 -05:00
log.Println("warning: DBClient [Init] not properly checked")
// Init
if _, err := d.Pool.Exec(ctx, queries.SQLSchema()); err != nil {
return err
}
return nil
2024-12-30 15:00:42 -05:00
}
func (d DBClient) CreateTransaction(ctx context.Context, transaction Transaction) error {
//TODO check context is not closed
//TODO check *DB is not nil
//TODO CreateTransaction
return fmt.Errorf("db: CreateTransaction not implemented")
}
func (d DBClient) ReadTransaction(ctx context.Context, membreID string, isPerpetual bool) error {
//TODO check context is not closed
//TODO check *DB is not nil
//TODO ReadTransaction
return fmt.Errorf("db: ReadTransaction not implemented")
}
func (d DBClient) CountTransactions(ctx context.Context) (membresSansAgenda, membresAvecPerpetuel, membresAvecNonPerpetuel, membresAvecTout int, err error) {
//TODO check context is not closed
//TODO check *DB is not nil
//TODO CountTransactions
return 0, 0, 0, 0, fmt.Errorf("db: CountTransactions not implemented")
}