hiling_go/db/sqlc/store.go

49 lines
1.2 KiB
Go

package db
import (
"context"
"database/sql"
"github.com/yiplee/sqlc"
)
type Store interface {
Querier
GetTopListLocations(ctx context.Context, arg GetTopListLocationsParams) ([]GetTopListLocationsRow, error)
GetImagesByLocation(ctx context.Context, arg GetImagesByLocationParams) ([]GetImagesByLocationRow, error)
GetLocation(ctx context.Context, location_id int32) (GetLocationRow, error)
GetUser(ctx context.Context, username string) (GetUserRow, error)
CreateReview(ctx context.Context, arg CreateReviewParams) (Review, error)
GetListLocationReviews(ctx context.Context, arg GetListLocationReviewsParams) ([]GetListLocationReviewsRow, error)
}
type SQLStore struct {
*Queries
db *sql.DB
}
func NewStore(db *sql.DB) Store {
return &SQLStore{
db: db,
Queries: New(sqlc.Wrap(db)),
}
}
// TRANSACTION QUERY FUNCTION
// func (store *SQLStore) execTx(ctx context.Context, fn func(*Queries) error) error {
// tx, err := store.db.BeginTx(ctx, nil)
// if err != nil {
// return err
// }
// q := New(tx)
// err = fn(q)
// if err != nil {
// if rbErr := tx.Rollback(); rbErr != nil {
// return fmt.Errorf("tx err: %v, rb err : %v", err, rbErr)
// }
// return err
// }
// return tx.Commit()
// }