mparameter.go 880 Bytes
Newer Older
1
2
3
4
5
6
package mparameter

import (
	"database/sql"
	"github.com/pkg/errors"

k1350's avatar
k1350 committed
7
	"gitlab.com/k1350/sololog_gql/graph/model"
8
9
10
11
	customError "gitlab.com/k1350/sololog_gql/internal/errors"
)

type IMParameterRepository interface {
k1350's avatar
k1350 committed
12
	Find() (*model.MasterParameter, error)
13
14
15
16
17
18
19
20
21
22
}

type MParameterRepository struct {
	*sql.DB
}

func NewMParameterRepository(db *sql.DB) IMParameterRepository {
	return &MParameterRepository{db}
}

k1350's avatar
k1350 committed
23
24
25
26
27
28
func (r *MParameterRepository) Find() (*model.MasterParameter, error) {
	s := "SELECT max_blogs, max_blog_links FROM m_parameter LIMIT 1"
	var master model.MasterParameter
	stmt, err := r.Prepare(s)
	if err != nil {
		return nil, errors.Wrap(customError.DBError, err.Error())
29
	}
k1350's avatar
k1350 committed
30
	defer stmt.Close()
31

k1350's avatar
k1350 committed
32
33
34
	err = stmt.QueryRow().Scan(&master.MaxBlogs, &master.MaxBlogLinks)
	if err != nil {
		return nil, errors.Wrap(customError.DBError, err.Error())
35
	}
k1350's avatar
k1350 committed
36
	return &master, nil
37
}