27 lines
574 B
Go
27 lines
574 B
Go
package repository
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
models "vibeStonk/server/models/v1"
|
|
)
|
|
|
|
type TransactionRepo interface {
|
|
Create(transaction *models.Transaction) (*models.Transaction, error)
|
|
DeleteBySaleID(saleID int64) error
|
|
List() ([]*models.Transaction, error)
|
|
}
|
|
|
|
func NewTransactionRepo(config *Config, db *sql.DB) (TransactionRepo, error) {
|
|
switch config.DBEngine {
|
|
case Sqlite:
|
|
repo, err := newSqliteTransactionRepo(db)
|
|
if err != nil {
|
|
return nil, fmt.Errorf(errMsgFailed, "Sqlite", err)
|
|
}
|
|
return repo, nil
|
|
default:
|
|
return nil, ErrBadEngine
|
|
}
|
|
}
|