[fix] always use sorted map

Signed-off-by: Anton Nesterov <anton@demiurg.io>
This commit is contained in:
Anton Nesterov 2024-08-09 17:06:15 +02:00
parent d644ef077e
commit fb13fcbece
No known key found for this signature in database
GPG key ID: 59121E8AE2851FB5
3 changed files with 5 additions and 3 deletions

View file

@ -15,8 +15,10 @@ func covert_find(ctx Context, find Find, join string) string {
if join == "" {
join = " AND "
}
keys := AggregateSortedKeys([]Map{find})
expressions := []string{}
for key, value := range find {
for _, key := range keys {
value := find[key]
if strings.Contains(key, "$and") {
v := covert_find(ctx, value.(Find), "")
expressions = append(expressions, fmt.Sprintf("(%s)", v))

View file

@ -11,7 +11,7 @@ type InsertData struct {
}
func ConvertInsert(ctx Context, inserts []Map) (InsertData, error) {
keys := AggregateKeys(inserts)
keys := AggregateSortedKeys(inserts)
placeholder := make([]string, 0)
for range keys {
placeholder = append(placeholder, "?")

View file

@ -2,7 +2,7 @@ package builder
import "sort"
func AggregateKeys(maps []Map) []string {
func AggregateSortedKeys(maps []Map) []string {
set := make(map[string]int)
keys := make([]string, 0)
for _, item := range maps {