Skip to content

Commit

Permalink
Fix bug adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
minhduc140583 committed Jul 7, 2024
1 parent 563fe99 commit 18ab4bf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (a *Adapter[T, K]) Load(ctx context.Context, id K) (*T, error) {
}
var objs []T
query := fmt.Sprintf("select %s from %s ", a.Fields, a.Table)
query1, args := q.BuildFindByIdWithDB(a.DB, query, ip, a.JsonColumnMap, a.Schema.SKeys, a.BuildParam)
query1, args := q.BuildFindByIdWithDB(a.DB, query, ip, a.JsonColumnMap, a.Keys, a.BuildParam)
tx := q.GetExec(ctx, a.DB, a.TxKey)
err := q.Query(ctx, tx, a.Map, &objs, query1, args...)
if err != nil {
Expand All @@ -108,7 +108,7 @@ func (a *Adapter[T, K]) Exist(ctx context.Context, id K) (bool, error) {
return false, er0
}
query := fmt.Sprintf("select %s from %s ", a.Schema.SColumns[0], a.Table)
query1, args := q.BuildFindByIdWithDB(a.DB, query, ip, a.JsonColumnMap, a.Schema.SKeys, a.BuildParam)
query1, args := q.BuildFindByIdWithDB(a.DB, query, ip, a.JsonColumnMap, a.Keys, a.BuildParam)
tx := q.GetExec(ctx, a.DB, a.TxKey)
rows, err := tx.QueryContext(ctx, query1, args...)
if err != nil {
Expand All @@ -126,7 +126,7 @@ func (a *Adapter[T, K]) Delete(ctx context.Context, id K) (int64, error) {
return -1, er0
}
query := fmt.Sprintf("delete from %s ", a.Table)
query1, args := q.BuildFindByIdWithDB(a.DB, query, ip, a.JsonColumnMap, a.Schema.SKeys, a.BuildParam)
query1, args := q.BuildFindByIdWithDB(a.DB, query, ip, a.JsonColumnMap, a.Keys, a.BuildParam)
tx := q.GetExec(ctx, a.DB, a.TxKey)
res, err := tx.ExecContext(ctx, query1, args...)
if err != nil {
Expand Down
File renamed without changes.
9 changes: 5 additions & 4 deletions template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ type TemplateNode struct {
Property string `yaml:"property" mapstructure:"property" json:"property,omitempty" gorm:"column:property" bson:"property,omitempty" dynamodbav:"property,omitempty" firestore:"property,omitempty"`
Value string `yaml:"value" mapstructure:"value" json:"value,omitempty" gorm:"column:value" bson:"value,omitempty" dynamodbav:"value,omitempty" firestore:"value,omitempty"`
Array string `yaml:"array" mapstructure:"array" json:"array,omitempty" gorm:"column:array" bson:"array,omitempty" dynamodbav:"array,omitempty" firestore:"array,omitempty"`
Separator string `yaml:"separator" mapstructure:"separator" json:"array,omitempty" gorm:"column:separator" bson:"separator,omitempty" dynamodbav:"separator,omitempty" firestore:"separator,omitempty"`
Prefix string `yaml:"prefix" mapstructure:"prefix" json:"array,omitempty" gorm:"column:prefix" bson:"prefix,omitempty" dynamodbav:"prefix,omitempty" firestore:"prefix,omitempty"`
Suffix string `yaml:"suffix" mapstructure:"suffix" json:"array,omitempty" gorm:"column:suffix" bson:"suffix,omitempty" dynamodbav:"suffix,omitempty" firestore:"suffix,omitempty"`
Separator string `yaml:"separator" mapstructure:"separator" json:"separator,omitempty" gorm:"column:separator" bson:"separator,omitempty" dynamodbav:"separator,omitempty" firestore:"separator,omitempty"`
Prefix string `yaml:"prefix" mapstructure:"prefix" json:"prefix,omitempty" gorm:"column:prefix" bson:"prefix,omitempty" dynamodbav:"prefix,omitempty" firestore:"prefix,omitempty"`
Suffix string `yaml:"suffix" mapstructure:"suffix" json:"suffix,omitempty" gorm:"column:suffix" bson:"suffix,omitempty" dynamodbav:"suffix,omitempty" firestore:"suffix,omitempty"`
Format StringFormat `yaml:"format" mapstructure:"format" json:"format,omitempty" gorm:"column:format" bson:"format,omitempty" dynamodbav:"format,omitempty" firestore:"format,omitempty"`
}
type Template struct {
Expand Down Expand Up @@ -619,6 +619,7 @@ func Build(obj map[string]interface{}, template Template, param func(int) string
}
return strings.Join(results, ""), params
}

type QueryBuilder struct {
Template Template
ModelType *reflect.Type
Expand Down Expand Up @@ -684,7 +685,7 @@ func GetQueryBuilder(isTemplate bool, builder Builder, id string, m map[string]*
}
return NewQueryBuilder(id, m, modelType, mp, param, buildSort, opts...)
}
func NewQueryBuilderWithArray(id string, m map[string]*Template, modelType *reflect.Type, mp func(interface{}, *reflect.Type, ...func(string, reflect.Type) string) map[string]interface{}, param func(i int) string, buildSort func(string, reflect.Type) string, q func(string) string, opts...func(interface{}) interface {
func NewQueryBuilderWithArray(id string, m map[string]*Template, modelType *reflect.Type, mp func(interface{}, *reflect.Type, ...func(string, reflect.Type) string) map[string]interface{}, param func(i int) string, buildSort func(string, reflect.Type) string, q func(string) string, opts ...func(interface{}) interface {
driver.Valuer
sql.Scanner
}) (*QueryBuilder, error) {
Expand Down

0 comments on commit 18ab4bf

Please sign in to comment.