| 728 | } |
| 729 | |
| 730 | func buildFilterFnQuery(filter *models.FnFilter) (string, []interface{}, error) { |
| 731 | if filter == nil { |
| 732 | return "", nil, nil |
| 733 | } |
| 734 | var b bytes.Buffer |
| 735 | var args []interface{} |
| 736 | |
| 737 | // where(fmt.Sprintf("image LIKE '%s%%'"), filter.Image) // TODO needs escaping, prob we want prefix query to ignore tags |
| 738 | args = where(&b, args, "app_id=? ", filter.AppID) |
| 739 | |
| 740 | if filter.Cursor != "" { |
| 741 | s, err := base64.RawURLEncoding.DecodeString(filter.Cursor) |
| 742 | if err != nil { |
| 743 | return "", args, err |
| 744 | } |
| 745 | args = where(&b, args, "name>?", string(s)) |
| 746 | } |
| 747 | if filter.Name != "" { |
| 748 | args = where(&b, args, "name=?", filter.Name) |
| 749 | } |
| 750 | |
| 751 | fmt.Fprintf(&b, ` ORDER BY name ASC`) |
| 752 | if filter.PerPage > 0 { |
| 753 | fmt.Fprintf(&b, ` LIMIT ?`) |
| 754 | args = append(args, filter.PerPage) |
| 755 | } |
| 756 | return b.String(), args, nil |
| 757 | } |
| 758 | |
| 759 | func where(b *bytes.Buffer, args []interface{}, colOp string, val interface{}) []interface{} { |
| 760 | if val == nil { |