<commit_before>package parse

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/url"
)

// QueryOptions represents the parameters to a Parse query.
type QueryOptions struct {
	Where string
}

// QueryClass performs a lookup of objects based on query options.
func (c *Client) QueryClass(className string, options *QueryOptions, destination interface{}) error {
	uri, err := url.Parse(fmt.Sprintf("/1/classes/%s", className))

	if options != nil {
		params := uri.Query()
		if options.Where != "" {
			params.Set("where", options.Where)
		}
		uri.RawQuery = params.Encode()
	}

	resp, err := c.doSimple("GET", uri.String())
	if err != nil {
		return err
	}
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}
	// delay parsing of results
	c.trace("Query", uri, string(body))
	results := struct {
		Results json.RawMessage `json:"results"`
	}{}
	// first pass
	err = json.Unmarshal(body, &results)
	if err != nil {
		return err
	}
	return json.Unmarshal(results.Results, destination)
}

// Query performs a lookup of objects based on query options. destination must be<commit_msg>limit support<commit_after>package parse

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/url"
)

// QueryOptions represents the parameters to a Parse query.
type QueryOptions struct {
	Where string
	Limit int
}

// QueryClass performs a lookup of objects based on query options.
func (c *Client) QueryClass(className string, options *QueryOptions, destination interface{}) error {
	uri, err := url.Parse(fmt.Sprintf("/1/classes/%s", className))

	if options != nil {
		params := uri.Query()
		if options.Where != "" {
			params.Set("where", options.Where)
		}
		if options.Limit != 0 {
			params.Set("limit", fmt.Sprint(options.Limit))
		}
		uri.RawQuery = params.Encode()
	}

	resp, err := c.doSimple("GET", uri.String())
	if err != nil {
		return err
	}
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}
	// delay parsing of results
	c.trace("Query", uri, string(body))
	results := struct {
		Results json.RawMessage `json:"results"`
	}{}
	// first pass
	err = json.Unmarshal(body, &results)
	if err != nil {
		return err
	}
	return json.Unmarshal(results.Results, destination)
}

// Query performs a lookup of objects based on query options. destination must be
{'fraction_non_alphanumeric': 0.13737461840383777, 'fraction_numerical': 0.0013083296990841692, 'mean_word_length': 3.759336099585062, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1383384', 'n_tokens_mistral': 772, 'n_tokens_neox': 736, 'n_words': 227}