-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
72 lines (58 loc) · 1.66 KB
/
init.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package repository
import (
"database/sql"
"github.com/artem-malko/auth-and-go/infrastructure/caller"
"github.com/artem-malko/auth-and-go/infrastructure/database"
"github.com/artem-malko/auth-and-go/repositories/token"
sq "github.com/Masterminds/squirrel"
)
const tokensTableName = "tokens"
const repositoryPrefix = tokensTableName + " repository: "
const tokenIDFieldName = "id"
const tokenTypeFieldName = "token_type"
const tokenStatusFieldName = "token_status"
const accountIDFieldName = "account_id"
const identityIDFieldName = "identity_id"
const clientIDFieldName = "client_id"
const tokenExpiresDateFieldName = "expires_date"
type repository struct {
psql sq.StatementBuilderType
}
// New creates postgresRepository
func New() (token.Repository, error) {
psql := sq.StatementBuilder.PlaceholderFormat(sq.Dollar)
return &repository{
psql: psql,
}, nil
}
func getCaller() string {
// Remove getCaller from stack
if callerName, ok := caller.GetCaller(2); ok == true {
return callerName
}
return repositoryPrefix + "unknown caller"
}
func (r *repository) exec(executor database.QueryExecutor, queryBuilder database.QueryBuilder) error {
return database.ExecWithCaller(
getCaller(),
executor,
queryBuilder,
)
}
func (r *repository) queryRow(executor database.QueryExecutor, queryBuilder database.QueryBuilder) (*sql.Row, error) {
return database.QueryRowWithCaller(
getCaller(),
executor,
queryBuilder,
)
}
func (r *repository) query(
executor database.QueryExecutor, queryBuilder database.QueryBuilder, scanFunc func(rows *sql.Rows) error,
) error {
return database.QueryWithCaller(
getCaller(),
executor,
queryBuilder,
scanFunc,
)
}