add a couple post endpoints + /timelines/home
This commit is contained in:
parent
dd72a1f4c1
commit
9f052dc9ef
24 changed files with 462 additions and 32 deletions
|
@ -8,8 +8,11 @@ import (
|
|||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
"github.com/keegancsmith/sqlf"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
var LogQueries = true
|
||||
|
||||
type Querier interface {
|
||||
Query(ctx context.Context, query string, args ...interface{}) (pgx.Rows, error)
|
||||
QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
|
||||
|
@ -32,6 +35,10 @@ type Tx interface {
|
|||
func Select[T any](ctx context.Context, querier Querier, query *sqlf.Query) ([]T, error) {
|
||||
dst := make([]T, 0)
|
||||
|
||||
if LogQueries {
|
||||
log.Debug().Str("query", query.Query(sqlf.PostgresBindVar)).Msg("executing select query")
|
||||
}
|
||||
|
||||
err := pgxscan.Select(ctx, querier, &dst, query.Query(sqlf.PostgresBindVar), query.Args()...)
|
||||
if err != nil {
|
||||
return []T{}, errors.Wrap(err, "executing query")
|
||||
|
@ -42,6 +49,10 @@ func Select[T any](ctx context.Context, querier Querier, query *sqlf.Query) ([]T
|
|||
func Get[T any](ctx context.Context, querier Querier, query *sqlf.Query) (T, error) {
|
||||
var dst T
|
||||
|
||||
if LogQueries {
|
||||
log.Debug().Str("query", query.Query(sqlf.PostgresBindVar)).Msg("executing get query")
|
||||
}
|
||||
|
||||
err := pgxscan.Get(ctx, querier, &dst, query.Query(sqlf.PostgresBindVar), query.Args()...)
|
||||
if err != nil {
|
||||
return dst, errors.Wrap(err, "executing query")
|
||||
|
@ -50,6 +61,10 @@ func Get[T any](ctx context.Context, querier Querier, query *sqlf.Query) (T, err
|
|||
}
|
||||
|
||||
func Exec(ctx context.Context, querier Querier, query *sqlf.Query) error {
|
||||
if LogQueries {
|
||||
log.Debug().Str("query", query.Query(sqlf.PostgresBindVar)).Msg("executing exec query")
|
||||
}
|
||||
|
||||
_, err := querier.Exec(ctx, query.Query(sqlf.PostgresBindVar), query.Args()...)
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue