MSP-7042 Add sql metrics
This commit is contained in:
1 parent
0688ca082a
commit
4932568c64
5 files changed
+106
-21
No files matched your search
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/db"
|
||||
"github.com/txix-open/isp-kit/db/query"
|
||||
"github.com/txix-open/isp-kit/metrics/sql_metrics"
|
||||
)
|
||||
|
||||
type AccessList struct {
|
||||
@@ -24,11 +25,13 @@ func NewAccessList(db db.DB) AccessList {
|
||||
}
|
||||
|
||||
func (r AccessList) GetAccessListByAppIdAndMethod(ctx context.Context, appId int, method string) (*entity.AccessList, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "AccessList.GetAccessListByAppIdAndMethod")
|
||||
|
||||
q := `
|
||||
SELECT app_id, method, value
|
||||
FROM access_list
|
||||
WHERE app_id = $1 AND method = $2
|
||||
`
|
||||
`
|
||||
result := entity.AccessList{}
|
||||
err := r.db.SelectRow(ctx, &result, q, appId, method)
|
||||
switch {
|
||||
@@ -42,11 +45,13 @@ func (r AccessList) GetAccessListByAppIdAndMethod(ctx context.Context, appId int
|
||||
}
|
||||
|
||||
func (r AccessList) GetAccessListByAppId(ctx context.Context, appId int) ([]entity.AccessList, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "AccessList.GetAccessListByAppId")
|
||||
|
||||
q := `
|
||||
SELECT app_id, method, value
|
||||
FROM access_list
|
||||
WHERE app_id = $1
|
||||
`
|
||||
`
|
||||
result := make([]entity.AccessList, 0)
|
||||
err := r.db.Select(ctx, &result, q, appId)
|
||||
if err != nil {
|
||||
@@ -57,6 +62,8 @@ func (r AccessList) GetAccessListByAppId(ctx context.Context, appId int) ([]enti
|
||||
}
|
||||
|
||||
func (r AccessList) GetAccessListByAppIdList(ctx context.Context, appIdList []int) ([]entity.AccessList, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "AccessList.GetAccessListByAppIdList")
|
||||
|
||||
q, args, err := query.New().
|
||||
Select("app_id", "method", "value").
|
||||
From("access_list").
|
||||
@@ -76,6 +83,8 @@ func (r AccessList) GetAccessListByAppIdList(ctx context.Context, appIdList []in
|
||||
}
|
||||
|
||||
func (r AccessList) InsertArrayAccessList(ctx context.Context, entity []entity.AccessList) error {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "AccessList.InsertArrayAccessList")
|
||||
|
||||
qBuilder := query.New().
|
||||
Insert("access_list").
|
||||
Columns("app_id", "method", "value")
|
||||
@@ -96,6 +105,8 @@ func (r AccessList) InsertArrayAccessList(ctx context.Context, entity []entity.A
|
||||
}
|
||||
|
||||
func (r AccessList) UpsertAccessList(ctx context.Context, e entity.AccessList) (int, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "AccessList.UpsertAccessList")
|
||||
|
||||
q := `
|
||||
INSERT INTO access_list
|
||||
(app_id, method, value)
|
||||
@@ -103,7 +114,7 @@ func (r AccessList) UpsertAccessList(ctx context.Context, e entity.AccessList) (
|
||||
ON CONFLICT (app_id, method)
|
||||
DO UPDATE
|
||||
SET (value) = (SELECT EXCLUDED.value)
|
||||
`
|
||||
`
|
||||
result, err := r.db.Exec(ctx, q, e.AppId, e.Method, e.Value)
|
||||
if err != nil {
|
||||
return 0, errors.WithMessagef(err, "exec query %s", q)
|
||||
@@ -118,6 +129,8 @@ func (r AccessList) UpsertAccessList(ctx context.Context, e entity.AccessList) (
|
||||
}
|
||||
|
||||
func (r AccessList) DeleteAccessList(ctx context.Context, appId int, methods []string) error {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "AccessList.DeleteAccessList")
|
||||
|
||||
q, args, err := query.New().
|
||||
Delete("access_list").
|
||||
Where(squirrel.Eq{
|
||||
@@ -139,11 +152,13 @@ func (r AccessList) DeleteAccessList(ctx context.Context, appId int, methods []s
|
||||
}
|
||||
|
||||
func (r AccessList) DeleteAccessListByAppId(ctx context.Context, appId int) ([]entity.AccessList, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "AccessList.DeleteAccessListByAppId")
|
||||
|
||||
q := `
|
||||
DELETE FROM access_list
|
||||
WHERE app_id = $1
|
||||
RETURNING app_id, method, value
|
||||
`
|
||||
`
|
||||
result := make([]entity.AccessList, 0)
|
||||
err := r.db.Select(ctx, &result, q, appId)
|
||||
if err != nil {
|
||||
|
||||
+21
-4
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/db"
|
||||
"github.com/txix-open/isp-kit/db/query"
|
||||
"github.com/txix-open/isp-kit/metrics/sql_metrics"
|
||||
)
|
||||
|
||||
type AppGroup struct {
|
||||
@@ -25,11 +26,13 @@ func NewAppGroup(db db.DB) AppGroup {
|
||||
}
|
||||
|
||||
func (r AppGroup) GetAppGroupById(ctx context.Context, id int) (*entity.AppGroup, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "AppGroup.GetAppGroupById")
|
||||
|
||||
q := `
|
||||
SELECT id, name, description, domain_id, created_at, updated_at
|
||||
FROM application_group
|
||||
WHERE id = $1
|
||||
`
|
||||
`
|
||||
result := entity.AppGroup{}
|
||||
err := r.db.SelectRow(ctx, &result, q, id)
|
||||
switch {
|
||||
@@ -43,6 +46,8 @@ func (r AppGroup) GetAppGroupById(ctx context.Context, id int) (*entity.AppGroup
|
||||
}
|
||||
|
||||
func (r AppGroup) GetAppGroupByIdList(ctx context.Context, idList []int) ([]entity.AppGroup, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "AppGroup.GetAppGroupByIdList")
|
||||
|
||||
q, arg, err := query.New().
|
||||
Select("id", "name", "description", "domain_id", "created_at", "updated_at").
|
||||
From("application_group").
|
||||
@@ -63,6 +68,8 @@ func (r AppGroup) GetAppGroupByIdList(ctx context.Context, idList []int) ([]enti
|
||||
}
|
||||
|
||||
func (r AppGroup) GetAppGroupByDomainId(ctx context.Context, domainIdList []int) ([]entity.AppGroup, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "AppGroup.GetAppGroupByDomainId")
|
||||
|
||||
q, arg, err := query.New().
|
||||
Select("id", "name", "description", "domain_id", "created_at", "updated_at").
|
||||
From("application_group").
|
||||
@@ -83,11 +90,13 @@ func (r AppGroup) GetAppGroupByDomainId(ctx context.Context, domainIdList []int)
|
||||
}
|
||||
|
||||
func (r AppGroup) GetAppGroupByNameAndDomainId(ctx context.Context, name string, domainId int) (*entity.AppGroup, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "AppGroup.GetAppGroupByNameAndDomainId")
|
||||
|
||||
q := `
|
||||
SELECT id, name, description, domain_id, created_at, updated_at
|
||||
FROM application_group
|
||||
WHERE name = $1 AND domain_id = $2
|
||||
`
|
||||
`
|
||||
result := entity.AppGroup{}
|
||||
err := r.db.SelectRow(ctx, &result, q, name, domainId)
|
||||
switch {
|
||||
@@ -101,13 +110,15 @@ func (r AppGroup) GetAppGroupByNameAndDomainId(ctx context.Context, name string,
|
||||
}
|
||||
|
||||
func (r AppGroup) CreateAppGroup(ctx context.Context, name string, desc string, domainId int) (*entity.AppGroup, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "AppGroup.CreateAppGroup")
|
||||
|
||||
q := `
|
||||
INSERT INTO application_group
|
||||
(name, description, domain_id)
|
||||
VALUES ($1, $2, $3)
|
||||
ON CONFLICT (name, domain_id) DO NOTHING
|
||||
RETURNING id, name, description, domain_id, created_at, updated_at
|
||||
`
|
||||
`
|
||||
result := entity.AppGroup{}
|
||||
err := r.db.SelectRow(ctx, &result, q, name, desc, domainId)
|
||||
switch {
|
||||
@@ -121,12 +132,14 @@ func (r AppGroup) CreateAppGroup(ctx context.Context, name string, desc string,
|
||||
}
|
||||
|
||||
func (r AppGroup) UpdateAppGroup(ctx context.Context, id int, name string, description string) (*entity.AppGroup, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "AppGroup.UpdateAppGroup")
|
||||
|
||||
q := `
|
||||
UPDATE application_group
|
||||
SET name = $1, description = $2
|
||||
WHERE id = $3
|
||||
RETURNING id, name, description, domain_id, created_at, updated_at
|
||||
`
|
||||
`
|
||||
result := entity.AppGroup{}
|
||||
err := r.db.SelectRow(ctx, &result, q, name, description, id)
|
||||
var pgErr *pgconn.PgError
|
||||
@@ -143,6 +156,8 @@ func (r AppGroup) UpdateAppGroup(ctx context.Context, id int, name string, descr
|
||||
}
|
||||
|
||||
func (r AppGroup) DeleteAppGroup(ctx context.Context, idList []int) (int, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "AppGroup.DeleteAppGroup")
|
||||
|
||||
q, args, err := query.New().
|
||||
Delete("application_group").
|
||||
Where(squirrel.Eq{"id": idList}).
|
||||
@@ -165,6 +180,8 @@ func (r AppGroup) DeleteAppGroup(ctx context.Context, idList []int) (int, error)
|
||||
}
|
||||
|
||||
func (r AppGroup) GetAllAppGroups(ctx context.Context) ([]entity.AppGroup, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "AppGroup.GetAllAppGroups")
|
||||
|
||||
q, arg, err := query.New().
|
||||
Select("id", "name", "description", "domain_id", "created_at", "updated_at").
|
||||
From("application_group").
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/db"
|
||||
"github.com/txix-open/isp-kit/db/query"
|
||||
"github.com/txix-open/isp-kit/metrics/sql_metrics"
|
||||
)
|
||||
|
||||
type Application struct {
|
||||
@@ -25,11 +26,13 @@ func NewApplication(db db.DB) Application {
|
||||
}
|
||||
|
||||
func (r Application) GetApplicationById(ctx context.Context, id int) (*entity.Application, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Application.GetApplicationById")
|
||||
|
||||
q := `
|
||||
SELECT id, name, description, application_group_id, type, created_at, updated_at
|
||||
FROM application
|
||||
WHERE id = $1
|
||||
`
|
||||
`
|
||||
result := entity.Application{}
|
||||
err := r.db.SelectRow(ctx, &result, q, id)
|
||||
switch {
|
||||
@@ -43,6 +46,8 @@ func (r Application) GetApplicationById(ctx context.Context, id int) (*entity.Ap
|
||||
}
|
||||
|
||||
func (r Application) GetApplicationByIdList(ctx context.Context, idList []int) ([]entity.Application, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Application.GetApplicationByIdList")
|
||||
|
||||
q, args, err := query.New().
|
||||
Select("id", "name", "description", "application_group_id", "type", "created_at", "updated_at").
|
||||
From("application").
|
||||
@@ -63,6 +68,8 @@ func (r Application) GetApplicationByIdList(ctx context.Context, idList []int) (
|
||||
}
|
||||
|
||||
func (r Application) GetApplicationByAppGroupIdList(ctx context.Context, appGroupIdList []int) ([]entity.Application, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Application.GetApplicationByAppGroupIdList")
|
||||
|
||||
q, args, err := query.New().
|
||||
Select("id", "name", "description", "application_group_id", "type", "created_at", "updated_at").
|
||||
From("application").
|
||||
@@ -83,11 +90,13 @@ func (r Application) GetApplicationByAppGroupIdList(ctx context.Context, appGrou
|
||||
}
|
||||
|
||||
func (r Application) GetApplicationByNameAndAppGroupId(ctx context.Context, name string, serviceId int) (*entity.Application, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Application.GetApplicationByNameAndAppGroupId")
|
||||
|
||||
q := `
|
||||
SELECT id, name, description, application_group_id, type, created_at, updated_at
|
||||
FROM application
|
||||
WHERE name = $1 AND application_group_id = $2
|
||||
`
|
||||
`
|
||||
result := entity.Application{}
|
||||
err := r.db.SelectRow(ctx, &result, q, name, serviceId)
|
||||
switch {
|
||||
@@ -100,14 +109,22 @@ func (r Application) GetApplicationByNameAndAppGroupId(ctx context.Context, name
|
||||
}
|
||||
}
|
||||
|
||||
func (r Application) CreateApplication(ctx context.Context, id int, name string, desc string, appGroupId int, appType string) (
|
||||
*entity.Application, error) {
|
||||
func (r Application) CreateApplication(
|
||||
ctx context.Context,
|
||||
id int,
|
||||
name string,
|
||||
desc string,
|
||||
appGroupId int,
|
||||
appType string,
|
||||
) (*entity.Application, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Application.CreateApplication")
|
||||
|
||||
q := `
|
||||
INSERT INTO application
|
||||
(id, name, description, application_group_id, type)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING id, name, description, application_group_id, type, created_at, updated_at
|
||||
`
|
||||
`
|
||||
result := entity.Application{}
|
||||
err := r.db.SelectRow(ctx, &result, q, id, name, desc, appGroupId, appType)
|
||||
if err != nil {
|
||||
@@ -122,13 +139,15 @@ func (r Application) UpdateApplication(
|
||||
name string,
|
||||
description string,
|
||||
) (*entity.Application, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Application.UpdateApplication")
|
||||
|
||||
q := `
|
||||
UPDATE application
|
||||
SET name = $2,
|
||||
description = $3
|
||||
WHERE id = $1
|
||||
RETURNING id, name, description, application_group_id, type, created_at, updated_at
|
||||
`
|
||||
`
|
||||
result := entity.Application{}
|
||||
err := r.db.SelectRow(ctx, &result, q, id, name, description)
|
||||
if err != nil {
|
||||
@@ -144,6 +163,8 @@ func (r Application) UpdateApplicationWithNewId(
|
||||
name string,
|
||||
description string,
|
||||
) (*entity.Application, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Application.UpdateApplicationWithNewId")
|
||||
|
||||
q := `
|
||||
UPDATE application
|
||||
SET id = $2,
|
||||
@@ -151,7 +172,7 @@ func (r Application) UpdateApplicationWithNewId(
|
||||
description = $4
|
||||
WHERE id = $1
|
||||
RETURNING id, name, description, application_group_id, type, created_at, updated_at
|
||||
`
|
||||
`
|
||||
result := entity.Application{}
|
||||
err := r.db.SelectRow(ctx, &result, q, oldId, newId, name, description)
|
||||
if err != nil {
|
||||
@@ -161,6 +182,8 @@ func (r Application) UpdateApplicationWithNewId(
|
||||
}
|
||||
|
||||
func (r Application) DeleteApplicationByIdList(ctx context.Context, idList []int) (int, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Application.DeleteApplicationByIdList")
|
||||
|
||||
q, args, err := query.New().
|
||||
Delete("application").
|
||||
Where(squirrel.Eq{"id": idList}).
|
||||
@@ -183,6 +206,8 @@ func (r Application) DeleteApplicationByIdList(ctx context.Context, idList []int
|
||||
}
|
||||
|
||||
func (r Application) NextApplicationId(ctx context.Context) (int, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Application.NextApplicationId")
|
||||
|
||||
q := `SELECT COALESCE(MAX(id)+1, 1) FROM application;`
|
||||
nextAppId := 0
|
||||
err := r.db.SelectRow(ctx, &nextAppId, q)
|
||||
@@ -193,6 +218,8 @@ func (r Application) NextApplicationId(ctx context.Context) (int, error) {
|
||||
}
|
||||
|
||||
func (r Application) GetAllApplications(ctx context.Context) ([]entity.Application, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Application.GetAllApplications")
|
||||
|
||||
q, args, err := query.New().
|
||||
Select("id", "name", "description", "application_group_id", "type", "created_at", "updated_at").
|
||||
From("application").
|
||||
|
||||
+19
-4
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/db"
|
||||
"github.com/txix-open/isp-kit/db/query"
|
||||
"github.com/txix-open/isp-kit/metrics/sql_metrics"
|
||||
)
|
||||
|
||||
type Domain struct {
|
||||
@@ -24,11 +25,13 @@ func NewDomain(db db.DB) Domain {
|
||||
}
|
||||
|
||||
func (r Domain) GetDomainById(ctx context.Context, id int) (*entity.Domain, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Domain.GetDomainById")
|
||||
|
||||
q := `
|
||||
SELECT id, name, description, system_id, created_at, updated_at
|
||||
FROM domain
|
||||
WHERE id = $1
|
||||
`
|
||||
`
|
||||
result := entity.Domain{}
|
||||
err := r.db.SelectRow(ctx, &result, q, id)
|
||||
switch {
|
||||
@@ -42,6 +45,8 @@ func (r Domain) GetDomainById(ctx context.Context, id int) (*entity.Domain, erro
|
||||
}
|
||||
|
||||
func (r Domain) GetDomainByIdList(ctx context.Context, idList []int) ([]entity.Domain, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Domain.GetDomainByIdList")
|
||||
|
||||
q, args, err := query.New().
|
||||
Select("id", "name", "description", "system_id", "created_at", "updated_at").
|
||||
From("domain").
|
||||
@@ -61,12 +66,14 @@ func (r Domain) GetDomainByIdList(ctx context.Context, idList []int) ([]entity.D
|
||||
}
|
||||
|
||||
func (r Domain) GetDomainBySystemId(ctx context.Context, systemId int) ([]entity.Domain, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Domain.GetDomainBySystemId")
|
||||
|
||||
q := `
|
||||
SELECT id, name, description, system_id, created_at, updated_at
|
||||
FROM domain
|
||||
WHERE system_id = $1
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
`
|
||||
result := make([]entity.Domain, 0)
|
||||
err := r.db.Select(ctx, &result, q, systemId)
|
||||
if err != nil {
|
||||
@@ -77,11 +84,13 @@ func (r Domain) GetDomainBySystemId(ctx context.Context, systemId int) ([]entity
|
||||
}
|
||||
|
||||
func (r Domain) GetDomainByNameAndSystemId(ctx context.Context, name string, systemId int) (*entity.Domain, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Domain.GetDomainByNameAndSystemId")
|
||||
|
||||
q := `
|
||||
SELECT id, name, description, system_id, created_at, updated_at
|
||||
FROM domain
|
||||
WHERE name = $1 AND system_id = $2
|
||||
`
|
||||
`
|
||||
result := entity.Domain{}
|
||||
err := r.db.SelectRow(ctx, &result, q, name, systemId)
|
||||
switch {
|
||||
@@ -95,12 +104,14 @@ func (r Domain) GetDomainByNameAndSystemId(ctx context.Context, name string, sys
|
||||
}
|
||||
|
||||
func (r Domain) CreateDomain(ctx context.Context, name string, desc string, systemId int) (*entity.Domain, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Domain.CreateDomain")
|
||||
|
||||
q := `
|
||||
INSERT INTO domain
|
||||
(name, description, system_id)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING id, name, description, system_id, created_at, updated_at
|
||||
`
|
||||
`
|
||||
result := entity.Domain{}
|
||||
err := r.db.SelectRow(ctx, &result, q, name, desc, systemId)
|
||||
if err != nil {
|
||||
@@ -110,6 +121,8 @@ func (r Domain) CreateDomain(ctx context.Context, name string, desc string, syst
|
||||
}
|
||||
|
||||
func (r Domain) UpdateDomain(ctx context.Context, id int, name string, description string) (*entity.Domain, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Domain.UpdateDomain")
|
||||
|
||||
q := `
|
||||
UPDATE domain
|
||||
SET name = $1, description = $2
|
||||
@@ -129,6 +142,8 @@ func (r Domain) UpdateDomain(ctx context.Context, id int, name string, descripti
|
||||
}
|
||||
|
||||
func (r Domain) DeleteDomain(ctx context.Context, idList []int) (int, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Domain.DeleteDomain")
|
||||
|
||||
q, args, err := query.New().
|
||||
Delete("domain").
|
||||
Where(squirrel.Eq{"id": idList}).
|
||||
|
||||
+13
-2
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/db"
|
||||
"github.com/txix-open/isp-kit/db/query"
|
||||
"github.com/txix-open/isp-kit/metrics/sql_metrics"
|
||||
)
|
||||
|
||||
type Token struct {
|
||||
@@ -24,12 +25,14 @@ func NewToken(db db.DB) Token {
|
||||
}
|
||||
|
||||
func (r Token) SaveToken(ctx context.Context, token string, appId int, expireTime int) (*entity.Token, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Token.SaveToken")
|
||||
|
||||
q := `
|
||||
INSERT INTO token
|
||||
(token, app_id, expire_time)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING token, app_id, expire_time, created_at
|
||||
`
|
||||
`
|
||||
result := entity.Token{}
|
||||
err := r.db.SelectRow(ctx, &result, q, token, appId, expireTime)
|
||||
if err != nil {
|
||||
@@ -40,11 +43,13 @@ func (r Token) SaveToken(ctx context.Context, token string, appId int, expireTim
|
||||
}
|
||||
|
||||
func (r Token) GetTokenById(ctx context.Context, token string) (*entity.Token, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Token.GetTokenById")
|
||||
|
||||
q := `
|
||||
SELECT token, app_id, expire_time, created_at
|
||||
FROM token
|
||||
WHERE token = $1
|
||||
`
|
||||
`
|
||||
result := entity.Token{}
|
||||
err := r.db.SelectRow(ctx, &result, q, token)
|
||||
switch {
|
||||
@@ -58,6 +63,8 @@ func (r Token) GetTokenById(ctx context.Context, token string) (*entity.Token, e
|
||||
}
|
||||
|
||||
func (r Token) GetTokenByAppIdList(ctx context.Context, appIdList []int) ([]entity.Token, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Token.GetTokenByAppIdList")
|
||||
|
||||
q, args, err := query.New().
|
||||
Select("token", "app_id", "expire_time", "created_at").
|
||||
From("token").
|
||||
@@ -78,6 +85,8 @@ func (r Token) GetTokenByAppIdList(ctx context.Context, appIdList []int) ([]enti
|
||||
}
|
||||
|
||||
func (r Token) DeleteToken(ctx context.Context, tokens []string) (int, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Token.DeleteToken")
|
||||
|
||||
q, args, err := query.New().
|
||||
Delete("token").
|
||||
Where(squirrel.Eq{"token": tokens}).
|
||||
@@ -100,6 +109,8 @@ func (r Token) DeleteToken(ctx context.Context, tokens []string) (int, error) {
|
||||
}
|
||||
|
||||
func (r Token) AuthDataByToken(ctx context.Context, token string) (*entity.AuthData, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Token.AuthDataByToken")
|
||||
|
||||
q := `
|
||||
SELECT system_id, domain_id, application_group_id, app_id, application.name AS app_name , token.expire_time, token.created_at
|
||||
FROM token
|
||||
|
||||
Reference in new issue
Block a user