package repositories import ( "context" sq "github.com/Masterminds/squirrel" "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/helpers/errors" "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/models" ) const languageTableName = "language" var languageTableColumns = []string{ "id", "url", "title", "is_default", } type LanguageRepository struct { db DB } func InitLanguageRepository(db DB) *LanguageRepository { return &LanguageRepository{db: db} } func (a LanguageRepository) GetAll( ctx context.Context, ) ([]models.Language, error) { var res []models.Language q, v, err := sq.Select(languageTableColumns...). From(languageTableName). ToSql() if err != nil { return nil, errors.Wrap(err, "build query") } err = a.db.SelectContext(ctx, &res, q, v...) if err != nil { return nil, errors.Wrap(err, "select") } return res, nil }