2023-09-08 22:24:58 +07:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
// }
|