2026-04-23 17:27:09: merge [main:48ccd130b2c03616d9d7fa2fecb57426bbf3c6c4];
This commit is contained in:
1 parent
e571aa709a
commit
5bf1807cb3
25 files changed
+453
-156
No files matched your search
+13
-2
@@ -93,6 +93,7 @@ func (r Backend) DeleteByConfigServiceNodeId(ctx context.Context, configServiceN
|
||||
func (r Backend) GetByConfigServiceNodeId(ctx context.Context, configServiceNodeId string) ([]entity.Backend, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Backend.GetByConfigServiceNodeId")
|
||||
|
||||
// nolint:unqueryvet
|
||||
query, args, err := squirrel.Select("*").
|
||||
From(Table("backend")).
|
||||
Where(squirrel.Eq{
|
||||
@@ -116,8 +117,17 @@ func (r Backend) All(ctx context.Context) ([]entity.Backend, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Backend.All")
|
||||
|
||||
result := make([]entity.Backend, 0)
|
||||
query := fmt.Sprintf("SELECT * FROM %s order by created_at desc", Table("backend"))
|
||||
err := r.db.Select(ctx, &result, query)
|
||||
|
||||
// nolint:unqueryvet
|
||||
query, args, err := squirrel.Select("*").
|
||||
From(Table("backend")).
|
||||
OrderBy("created_at desc").
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
err = r.db.Select(ctx, &result, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select: %s", query)
|
||||
}
|
||||
@@ -127,6 +137,7 @@ func (r Backend) All(ctx context.Context) ([]entity.Backend, error) {
|
||||
func (r Backend) GetByModuleId(ctx context.Context, moduleId string) ([]entity.Backend, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Backend.GetByModuleId")
|
||||
|
||||
// nolint:unqueryvet
|
||||
query, args, err := squirrel.Select("*").
|
||||
From(Table("backend")).
|
||||
Where(squirrel.Eq{
|
||||
|
||||
@@ -46,6 +46,7 @@ func (r Config) Insert(ctx context.Context, cfg entity.Config) error {
|
||||
func (r Config) GetActive(ctx context.Context, moduleId string) (*entity.Config, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Config.GetActive")
|
||||
|
||||
// nolint:unqueryvet
|
||||
query, args, err := squirrel.Select("*").
|
||||
From(Table("config")).
|
||||
Where(squirrel.Eq{
|
||||
@@ -64,6 +65,7 @@ func (r Config) GetActive(ctx context.Context, moduleId string) (*entity.Config,
|
||||
func (r Config) GetByModuleId(ctx context.Context, moduleId string) ([]entity.Config, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Config.GetByModuleId")
|
||||
|
||||
// nolint:unqueryvet
|
||||
query, args, err := squirrel.Select("*").
|
||||
From(Table("config")).
|
||||
Where(squirrel.Eq{
|
||||
@@ -86,6 +88,7 @@ func (r Config) GetByModuleId(ctx context.Context, moduleId string) ([]entity.Co
|
||||
func (r Config) GetById(ctx context.Context, id string) (*entity.Config, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Config.GetById")
|
||||
|
||||
// nolint:unqueryvet
|
||||
query, args, err := squirrel.Select("*").
|
||||
From(Table("config")).
|
||||
Where(squirrel.Eq{
|
||||
|
||||
@@ -24,12 +24,23 @@ func NewConfigHistory(db db.DB) ConfigHistory {
|
||||
func (r ConfigHistory) GetByConfigId(ctx context.Context, configId string) ([]entity.ConfigHistory, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "ConfigHistory.GetByConfigId")
|
||||
|
||||
query := fmt.Sprintf(`select * from %s where config_id = ? order by version desc`, Table("config_history"))
|
||||
// nolint:unqueryvet
|
||||
query, args, err := squirrel.Select("*").
|
||||
From(Table("config_history")).
|
||||
Where(squirrel.Eq{
|
||||
"config_id": configId,
|
||||
}).OrderBy("version desc").
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
result := make([]entity.ConfigHistory, 0)
|
||||
err := r.db.Select(ctx, &result, query, configId)
|
||||
err = r.db.Select(ctx, &result, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select: %s", query)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package repository
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
@@ -46,18 +45,28 @@ func (r ConfigSchema) Upsert(ctx context.Context, schema entity.ConfigSchema) er
|
||||
func (r ConfigSchema) All(ctx context.Context) ([]entity.ConfigSchema, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "ConfigSchema.All")
|
||||
|
||||
// nolint:unqueryvet
|
||||
query, args, err := squirrel.Select("*").
|
||||
From(Table("config_schema")).
|
||||
OrderBy("created_at").
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
result := make([]entity.ConfigSchema, 0)
|
||||
query := fmt.Sprintf("select * from %s order by created_at", Table("config_schema"))
|
||||
err := r.db.Select(ctx, &result, query)
|
||||
err = r.db.Select(ctx, &result, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select: %s", query)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r ConfigSchema) GetByModuleId(ctx context.Context, moduleId string) (*entity.ConfigSchema, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "ConfigSchema.GetByModuleId")
|
||||
|
||||
// nolint:unqueryvet
|
||||
query, args, err := squirrel.Select("*").
|
||||
From(Table("config_schema")).
|
||||
Where(squirrel.Eq{"module_id": moduleId}).
|
||||
@@ -88,7 +97,7 @@ func (r ConfigSchema) UpdateByModuleId(ctx context.Context, moduleId string, dat
|
||||
}
|
||||
|
||||
//nolint:nilnil
|
||||
func selectRow[T any](ctx context.Context, db db.DB, query string, args ...interface{}) (*T, error) {
|
||||
func selectRow[T any](ctx context.Context, db db.DB, query string, args ...any) (*T, error) {
|
||||
var result T
|
||||
err := db.SelectRow(ctx, &result, query, args...)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
|
||||
+16
-2
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
"isp-config-service/entity"
|
||||
"isp-config-service/entity/xtypes"
|
||||
@@ -35,12 +36,25 @@ func (r Event) Insert(ctx context.Context, event entity.Event) error {
|
||||
func (r Event) Get(ctx context.Context, lastEventId int, limit int) ([]entity.Event, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Event.Get")
|
||||
|
||||
query := fmt.Sprintf("select * from %s where id > ? order by id limit ?", Table("event"))
|
||||
// nolint:unqueryvet,gosec
|
||||
query, args, err := squirrel.Select("*").
|
||||
From(Table("event")).
|
||||
Where(squirrel.Gt{
|
||||
"id": lastEventId,
|
||||
}).
|
||||
OrderBy("id").
|
||||
Limit(uint64(limit)).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
result := make([]entity.Event, 0)
|
||||
err := r.db.Select(ctx, &result, query, lastEventId, limit)
|
||||
err = r.db.Select(ctx, &result, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select: %s", query)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
|
||||
+24
-4
@@ -66,6 +66,7 @@ func (r Module) SetDisconnectedAtNow(
|
||||
func (r Module) GetByNames(ctx context.Context, names []string) ([]entity.Module, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Module.GetByNames")
|
||||
|
||||
// nolint:unqueryvet
|
||||
query, args, err := squirrel.Select("*").
|
||||
From(Table("module")).
|
||||
Where(squirrel.Eq{
|
||||
@@ -88,19 +89,38 @@ func (r Module) GetByNames(ctx context.Context, names []string) ([]entity.Module
|
||||
func (r Module) GetById(ctx context.Context, id string) (*entity.Module, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Module.GetById")
|
||||
|
||||
query := fmt.Sprintf("select * from %s where id = ?", Table("module"))
|
||||
return selectRow[entity.Module](ctx, r.db, query, id)
|
||||
// nolint:unqueryvet
|
||||
query, args, err := squirrel.Select("*").
|
||||
From(Table("module")).
|
||||
Where(squirrel.Eq{
|
||||
"id": id,
|
||||
}).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
return selectRow[entity.Module](ctx, r.db, query, args...)
|
||||
}
|
||||
|
||||
func (r Module) All(ctx context.Context) ([]entity.Module, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Module.All")
|
||||
|
||||
// nolint:unqueryvet
|
||||
query, args, err := squirrel.Select("*").
|
||||
From(Table("module")).
|
||||
OrderBy("name").
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
result := make([]entity.Module, 0)
|
||||
query := fmt.Sprintf("select * from %s order by name", Table("module"))
|
||||
err := r.db.Select(ctx, &result, query)
|
||||
err = r.db.Select(ctx, &result, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select: %s", query)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
|
||||
+12
-3
@@ -3,7 +3,6 @@ package repository
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
@@ -26,18 +25,28 @@ func NewVariable(db db.DB) Variable {
|
||||
func (r Variable) All(ctx context.Context) ([]entity.Variable, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Variable.All")
|
||||
|
||||
// nolint:unqueryvet
|
||||
query, args, err := squirrel.Select("*").
|
||||
From(Table("variable")).
|
||||
OrderBy("created_at desc").
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "build query")
|
||||
}
|
||||
|
||||
result := make([]entity.Variable, 0)
|
||||
query := fmt.Sprintf("SELECT * FROM %s order by created_at desc", Table("variable"))
|
||||
err := r.db.Select(ctx, &result, query)
|
||||
err = r.db.Select(ctx, &result, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "select: %s", query)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r Variable) GetByName(ctx context.Context, name string) (*entity.Variable, error) {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Variable.GetByName")
|
||||
|
||||
// nolint:unqueryvet
|
||||
query, args, err := squirrel.Select("*").
|
||||
From(Table("variable")).
|
||||
Where(squirrel.Eq{"name": name}).
|
||||
|
||||
Reference in new issue
Block a user