// Creates a new query builder with a base query that is the conjunction of all queries passed
326078
func NewBuilder(queries ...string) *Builder {
	qb := new(Builder)
	qb.queryString = qb.and(stringIterator(queries...))
	return qb
}
1346741
func (q *ConjunctionQuery) And(queries ...FtsQuery) *ConjunctionQuery {
	q.options["conjuncts"] = append(q.options["conjuncts"].([]FtsQuery), queries...)
	return q
}
146924
func (qb *MySQLQueryBuilder) And(cond string) QueryBuilder {
	qb.Tokens = append(qb.Tokens, "AND", cond)
	return qb
}
528950
func NewBoolQuery() BoolQuery {
	q := BoolQuery{
		mustClauses:    make([]Query, 0),
		shouldClauses:  make([]Query, 0),
		mustNotClauses: make([]Query, 0),
	}
	return q
}
813131
func (ptree *ptree) Query(start, stop common.Comparator) common.Comparators {
	cmps := make(common.Comparators, 0, 32)
	aa := newApplyAction(func(cmp common.Comparator) bool {
		cmps = append(cmps, cmp)
		return true
	}, start, stop)
	ptree.checkAndRun(aa)
	aa.completer.Wait()
	return cmps
}
1102577
func (self *Query) extendQuery(mgoQuery *mgo.Query) {

	if self.selector != nil {
		mgoQuery.Select(self.selector)
	}

	if len(self.sort) > 0 {
		mgoQuery.Sort(self.sort...)
	}

	if self.limit != 0 {
		mgoQuery.Limit(self.limit)
	}

	if self.skip != 0 {
		mgoQuery.Skip(self.skip)
	}
}
1256203
func (o *querySet) All(container interface{}, cols ...string) (int64, error) {
	return o.orm.alias.DbBaser.ReadBatch(o.orm.db, o, o.mi, o.cond, container, o.orm.alias.TZ, cols)
}
1064893
func NewPgsqlBuilder(db *DB, executor Executor) Builder {
	return &PgsqlBuilder{
		NewBaseBuilder(db, executor),
		NewBaseQueryBuilder(db),
	}
}
1089619
func (me *DefaultAdapter) CompoundExpressionSql(buf *SqlBuilder, compound CompoundExpression) error {
	switch compound.Type() {
	case UNION:
		buf.Write(me.UnionFragment)
	case UNION_ALL:
		buf.Write(me.UnionAllFragment)
	case INTERSECT:
		buf.Write(me.IntersectFragment)
	case INTERSECT_ALL:
		buf.Write(me.IntersectAllFragment)
	}
	return me.Literal(buf, compound.Rhs())
}
966158
func NewCommonQuery(name string, query string) CommonQuery {
	q := CommonQuery{name: name, query: query}
	return q
}
1026229
func (db *DB) AddQuery(query string, expectedResult *sqltypes.Result) *ExpectedResult {
	if len(expectedResult.Rows) > 0 && len(expectedResult.Fields) == 0 {
		panic(fmt.Errorf("please add Fields to this Result so it's valid: %v", query))
	}
	resultCopy := &sqltypes.Result{}
	*resultCopy = *expectedResult
	db.mu.Lock()
	defer db.mu.Unlock()
	key := strings.ToLower(query)
	r := &ExpectedResult{resultCopy, nil}
	db.data[key] = r
	db.queryCalled[key] = 0
	return r
}
1050416
func NewMysqlBuilder(db *DB, executor Executor) Builder {
	return &MysqlBuilder{
		NewBaseBuilder(db, executor),
		NewBaseQueryBuilder(db),
	}
}
939423
func (qb *MySQLQueryBuilder) Or(cond string) QueryBuilder {
	qb.Tokens = append(qb.Tokens, "OR", cond)
	return qb
}
61572
func NewQueryBuilder(driver string) (qb QueryBuilder, err error) {
	if driver == "mysql" {
		qb = new(MySQLQueryBuilder)
	} else if driver == "tidb" {
		qb = new(TiDBQueryBuilder)
	} else if driver == "postgres" {
		err = errors.New("postgres query builder is not supported yet")
	} else if driver == "sqlite" {
		err = errors.New("sqlite query builder is not supported yet")
	} else {
		err = errors.New("unknown driver for query builder")
	}
	return
}
209313
func (conn *FakeVTGateConn) AddQuery(
	sql string,
	bindVariables map[string]*querypb.BindVariable,
	session *vtgatepb.Session,
	expectedResult *sqltypes.Result) {
	conn.execMap[sql] = &queryResponse{
		execQuery: &queryExecute{
			SQL:           sql,
			BindVariables: bindVariables,
			Session:       session,
		},
		reply: expectedResult,
	}
}
1066468
func MergeQuery(u url.URL, q url.Values) url.URL {
	uv := u.Query()
	for k, vs := range q {
		for _, v := range vs {
			uv.Add(k, v)
		}
	}
	u.RawQuery = uv.Encode()
	return u
}
149258
func (exporter *logExporter) buildQuery(getServices func() ([]service.ServiceDetails, error)) (string, error) {
	query := "*"
	if len(exporter.ServiceIDs) > 0 {
		services, e := getServices()
		if e != nil {
			return "", e
		}
		serviceMap := make(map[string]service.ServiceDetails)
		for _, service := range services {
			serviceMap[service.ID] = service
		}
		serviceIDMap := make(map[string]bool) //includes serviceIds, and their children as well
		for _, serviceID := range exporter.ServiceIDs {
			serviceIDMap[serviceID] = true
		}
		for _, service := range services {
			srvc := service
			for {
				found := false
				for _, serviceID := range exporter.ServiceIDs {
					if srvc.ID == serviceID {
						serviceIDMap[service.ID] = true
						found = true
						break
					}
				}
				if found || srvc.ParentServiceID == "" || exporter.ExcludeChildren {
					break
				}
				srvc = serviceMap[srvc.ParentServiceID]
			}
		}
		re := regexp.MustCompile("\\A[\\w\\-]+\\z") //only letters, numbers, underscores, and dashes
		queryParts := []string{}
		for serviceID := range serviceIDMap {
			if re.FindStringIndex(serviceID) == nil {
				return "", fmt.Errorf("invalid service ID format: %s", serviceID)
			}
			queryParts = append(queryParts, fmt.Sprintf("\"%s\"", strings.Replace(serviceID, "-", "\\-", -1)))
		}
		// sort the query parts for predictable testability of the query string
		sort.Sort(sort.StringSlice(queryParts))

		query = fmt.Sprintf("fields.service:(%s)", strings.Join(queryParts, " OR "))
	}

	if len(exporter.FileNames) > 0 {
		for i, filename := range exporter.FileNames {
			exporter.FileNames[i] = strconv.Quote(filename)
		}
		fileQuery := fmt.Sprintf("file:(%s)", strings.Join(exporter.FileNames, " OR "))
		if len(exporter.ServiceIDs) > 0 {
			query = fmt.Sprintf("%s AND %s", query, fileQuery)
		} else {
			query = fileQuery
		}
	}

	if exporter.Debug {
		log.WithFields(logrus.Fields{
			"servicecount": len(exporter.ServiceIDs),
			"filecount":    len(exporter.FileNames),
			"query":        query,
		}).Info("Looking for log messages")
	}
	return query, nil
}