-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
63 lines (50 loc) · 1.54 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
package repository
import (
"database/sql"
"github.com/artem-malko/auth-and-go/infrastructure/caller"
"github.com/artem-malko/auth-and-go/infrastructure/database"
sq "github.com/Masterminds/squirrel"
"github.com/artem-malko/auth-and-go/repositories/session"
)
const sessionsTableName = "sessions"
const repositoryPrefix = sessionsTableName + " repository: "
const sessionIDFieldName = "id"
const accountIDFieldName = "account_id"
const identityIDFieldName = "identity_id"
const clientIDFieldName = "client_id"
const accessTokenFieldName = "access_token"
const accessTokenExpiresDateFieldName = "access_token_expires_date"
const refreshTokenFieldName = "refresh_token"
const refreshTokenExpiresDateFieldName = "refresh_token_expires_date"
type repository struct {
db *sql.DB
psql sq.StatementBuilderType
}
// New creates postgresRepository
func New() (session.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 "session repository: 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,
)
}