Skip to content

Commit

Permalink
renamed build method
Browse files Browse the repository at this point in the history
  • Loading branch information
rmilejcz committed Apr 18, 2024
1 parent ff56592 commit 8744ea8
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,49 +220,49 @@ func BuildReadQueryWithNotList(target string, source interface{}, notList []stri
return sqlx.Named(result, source)
}

type ReadQuery struct {
type Query struct {
Target string
Source interface{}
NotList []string
FieldMask []string
Collate bool
}

func (rq *ReadQuery) Build() (string, []interface{}, error) {
reflectedValue := reflect.ValueOf(rq.Source).Elem()
func (q *Query) BuildRead() (string, []interface{}, error) {
reflectedValue := reflect.ValueOf(q.Source).Elem()
var qb queryBuilder
qb.Core.WriteString("SELECT ")
qb.Predicate.WriteString(" WHERE true")

for i := 0; i < reflectedValue.NumField(); i++ {
field := parseReflection(reflectedValue, i, rq.Target)
field := parseReflection(reflectedValue, i, q.Target)
if field.name != "" {
if !field.shouldIgnore && !field.selectFunc.ok {
qb.writeSelectField(field)
if field.value.CanAddr() {
if findInMask(rq.NotList, field.self.Name) {
qb.writeNotPredicate(field, rq.NotList, andPredicate)
if findInMask(q.NotList, field.self.Name) {
qb.writeNotPredicate(field, q.NotList, andPredicate)
} else {
qb.writePredicate(field, rq.FieldMask, andPredicate)
qb.writePredicate(field, q.FieldMask, andPredicate)
}
}
} else if field.selectFunc.ok {
qb.writeSelectFunc(field)
} else if field.isMultiValue && field.value.CanAddr() {
if findInMask(rq.NotList, field.self.Name) {
qb.writeNotPredicate(field, rq.NotList, andPredicate)
if findInMask(q.NotList, field.self.Name) {
qb.writeNotPredicate(field, q.NotList, andPredicate)
} else {
qb.writePredicate(field, rq.FieldMask, andPredicate)
qb.writePredicate(field, q.FieldMask, andPredicate)
}
}
}
if field.hasForeignKey {
qb.handleForeignKey(field)
}
}
qb.handleDateRange(rq.Target, &reflectedValue)
result := qb.getReadResult(rq.Target, &reflectedValue)
return sqlx.Named(result, rq.Source)
qb.handleDateRange(q.Target, &reflectedValue)
result := qb.getReadResult(q.Target, &reflectedValue)
return sqlx.Named(result, q.Source)
}

// BuildUpdateQuery accepts a target table name `target`, a struct `source`, and a list of struct fields `fieldMask`
Expand Down

0 comments on commit 8744ea8

Please sign in to comment.