コード例 #1
0
// Compile takes an expression and compiles it to a where clause for use with gorm.DB.Where()
// Returns the number of expected parameters for the query and a slice of errors if something goes wrong
func Compile(where criteria.Expression) (whereClause string, parameters []interface{}, err []error) {
	criteria.IteratePostOrder(where, bubbleUpJSONContext)

	compiler := newExpressionCompiler()
	compiled := where.Accept(&compiler)

	return compiled.(string), compiler.parameters, compiler.err
}
コード例 #2
0
// iterate the parent chain to see if this expression references json fields
func isInJSONContext(exp criteria.Expression) bool {
	result := false
	criteria.IterateParents(exp, func(exp criteria.Expression) bool {
		if exp.Annotation(jsonAnnotation) == true {
			result = true
			return false
		}
		return true
	})
	return result
}