trepa/internal/variables/repository/variable.go

24 lines
519 B
Go

package repository
import (
"gitea.qpismont.fr/qpismont/trepa/internal/variables/domain"
"github.com/jmoiron/sqlx"
)
type VariableRepository struct {
db *sqlx.DB
}
func NewRepository(db *sqlx.DB) *VariableRepository {
return &VariableRepository{db: db}
}
func (r *VariableRepository) FetchOneByName(name string) (*domain.Variable, error) {
var variable domain.Variable
err := r.db.Get(&variable, "SELECT * FROM variables WHERE name = $1", name)
if err != nil {
return nil, err
}
return &variable, nil
}