Module project, commit, submission
All checks were successful
Build and Release / release (push) Successful in 1m15s

This commit is contained in:
2026-04-26 16:31:03 +07:00
parent ac90236022
commit 6918a100fc
60 changed files with 5957 additions and 1020 deletions

View File

@@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
"history-api/internal/gen/sqlc"
@@ -22,6 +23,7 @@ type EntityRepository interface {
Create(ctx context.Context, params sqlc.CreateEntityParams) (*models.EntityEntity, error)
Update(ctx context.Context, params sqlc.UpdateEntityParams) (*models.EntityEntity, error)
Delete(ctx context.Context, id pgtype.UUID) error
WithTx(tx pgx.Tx) EntityRepository
}
type entityRepository struct {
@@ -36,6 +38,13 @@ func NewEntityRepository(db sqlc.DBTX, c cache.Cache) EntityRepository {
}
}
func (r *entityRepository) WithTx(tx pgx.Tx) EntityRepository {
return &entityRepository{
q: r.q.WithTx(tx),
c: r.c,
}
}
func (r *entityRepository) generateQueryKey(prefix string, params any) string {
b, _ := json.Marshal(params)
hash := fmt.Sprintf("%x", md5.Sum(b))
@@ -193,8 +202,6 @@ func (r *entityRepository) Create(ctx context.Context, params sqlc.CreateEntityP
CreatedAt: convert.TimeToPtr(row.CreatedAt),
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
}
_ = r.c.Set(ctx, fmt.Sprintf("entity:id:%s", entity.ID), entity, constants.NormalCacheDuration)
go func() {
_ = r.c.DelByPattern(context.Background(), "entity:search*")
}()
@@ -215,7 +222,7 @@ func (r *entityRepository) Update(ctx context.Context, params sqlc.UpdateEntityP
CreatedAt: convert.TimeToPtr(row.CreatedAt),
UpdatedAt: convert.TimeToPtr(row.UpdatedAt),
}
_ = r.c.Set(ctx, fmt.Sprintf("entity:id:%s", entity.ID), entity, constants.NormalCacheDuration)
_ = r.c.Del(ctx, fmt.Sprintf("entity:id:%s", entity.ID))
return &entity, nil
}