hiling_go/db/sqlc/store.go

46 lines
969 B
Go
Raw Normal View History

2023-09-08 22:24:58 +07:00
package db
import (
2023-09-17 16:32:48 +07:00
"context"
2023-09-08 22:24:58 +07:00
"database/sql"
2023-09-14 13:49:03 +07:00
"github.com/yiplee/sqlc"
2023-09-08 22:24:58 +07:00
)
type Store interface {
Querier
2023-09-17 16:32:48 +07:00
GetTopListLocations(ctx context.Context, arg GetTopListLocationsParams) ([]GetTopListLocationsRow, error)
2023-09-19 21:49:48 +07:00
GetImagesByLocation(ctx context.Context, arg GetImagesByLocationParams) ([]GetImagesByLocationRow, error)
2023-09-23 15:24:21 +07:00
GetUser(ctx context.Context, username string) (GetUserRow, error)
2023-09-08 22:24:58 +07:00
}
type SQLStore struct {
*Queries
db *sql.DB
}
func NewStore(db *sql.DB) Store {
return &SQLStore{
db: db,
2023-09-14 13:49:03 +07:00
Queries: New(sqlc.Wrap(db)),
2023-09-08 22:24:58 +07:00
}
}
// 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()
// }