45 lines
902 B
Go
45 lines
902 B
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)
|
|
}
|
|
|
|
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()
|
|
// }
|