fix(storage,document,sqlite): fix nil pointer exception in query options
This commit is contained in:
parent
8789b85d92
commit
8680e139e7
|
@ -102,7 +102,7 @@ func (m *Module) query(call goja.FunctionCall, rt *goja.Runtime) goja.Value {
|
|||
}
|
||||
|
||||
if queryOptions.Offset != nil {
|
||||
queryOptionsFuncs = append(queryOptionsFuncs, storage.WithOffset(*queryOptions.Limit))
|
||||
queryOptionsFuncs = append(queryOptionsFuncs, storage.WithOffset(*queryOptions.Offset))
|
||||
}
|
||||
|
||||
if queryOptions.OrderDirection != nil {
|
||||
|
|
|
@ -127,7 +127,12 @@ func (s *DocumentStore) Query(ctx context.Context, collection string, filter *fi
|
|||
args = append([]interface{}{collection}, args...)
|
||||
|
||||
if opts.OrderBy != nil {
|
||||
query, args = withOrderByClause(query, args, *opts.OrderBy, *opts.OrderDirection)
|
||||
direction := storage.OrderDirectionAsc
|
||||
if opts.OrderDirection != nil {
|
||||
direction = *opts.OrderDirection
|
||||
}
|
||||
|
||||
query, args = withOrderByClause(query, args, *opts.OrderBy, direction)
|
||||
}
|
||||
|
||||
if opts.Offset != nil || opts.Limit != nil {
|
||||
|
@ -378,13 +383,13 @@ func withOrderByClause(query string, args []any, orderBy string, orderDirection
|
|||
args = append(args, orderBy)
|
||||
}
|
||||
|
||||
query += fmt.Sprintf(`ORDER BY %s %s`, column, direction)
|
||||
query += fmt.Sprintf(` ORDER BY %s %s`, column, direction)
|
||||
|
||||
return query, args
|
||||
}
|
||||
|
||||
func withLimitOffsetClause(query string, args []any, limit int, offset int) (string, []any) {
|
||||
query += fmt.Sprintf(`LIMIT $%d OFFSET $%d`, len(args)+1, len(args)+2)
|
||||
query += fmt.Sprintf(` LIMIT $%d OFFSET $%d`, len(args)+1, len(args)+2)
|
||||
args = append(args, limit, offset)
|
||||
|
||||
return query, args
|
||||
|
|
Loading…
Reference in New Issue