Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UpdateBook ¶
UpdateBook updates given fields on book.
func UpsertBook ¶
func UpsertBook(ctx context.Context, params UpsertBookParams) (int64, error)
UpsertBook creates book in postgres and returns ID.
If row with the same ISBN already exists it will just update fields of existing row and returns id of old book.
Types ¶
type Book ¶
type Book struct { ID int64 `db:"id"` ISBN pgtype.Text `db:"isbn"` URL pgtype.Text `db:"url"` Title pgtype.Text `db:"title"` Image pgtype.Text `db:"image"` Description pgtype.Text `db:"description"` Authors pgtype.Array[pgtype.Text] `db:"authors"` Publisher pgtype.Text `db:"publisher"` Properties map[string]string `db:"properties"` CreatedAt pgtype.Timestamp `db:"created_at"` UpdatedAt pgtype.Timestamp `db:"updated_at"` }
Book represents book table in postgres.
type DB ¶
type DB interface { Begin(ctx context.Context) (pgx.Tx, error) Exec(ctx context.Context, sql string, arguments ...any) (commandTag pgconn.CommandTag, err error) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row }
DB is postgres database.
Click to show internal directories.
Click to hide internal directories.