CBLQueryFunction

@interface CBLQueryFunction : NSObject

CBLQueryFunction provides query functions.

  • Creates an AVG(expr) function expression that returns the average of all the number values in the group of the values expressed by the given expression.

    Declaration

    Objective-C

    + (nonnull CBLQueryExpression *)avg:(nonnull CBLQueryExpression *)expression;

    Swift

    class func avg(_ expression: CBLQueryExpression) -> CBLQueryExpression

    Parameters

    expression

    The expression.

    Return Value

    The AVG(expr) function.

  • Creates a COUNT(expr) function expression that returns the count of all values in the group of the values expressed by the given expression.

    Declaration

    Objective-C

    + (nonnull CBLQueryExpression *)count:(nonnull CBLQueryExpression *)expression;

    Swift

    class func count(_ expression: CBLQueryExpression) -> CBLQueryExpression

    Parameters

    expression

    The expression.

    Return Value

    The COUNT(expr) function.

  • Creates a MIN(expr) function expression that returns the minimum value in the group of the values expressed by the given expression.

    Declaration

    Objective-C

    + (nonnull CBLQueryExpression *)min:(nonnull CBLQueryExpression *)expression;

    Swift

    class func min(_ expression: CBLQueryExpression) -> CBLQueryExpression

    Parameters

    expression

    The expression.

    Return Value

    The MIN(expr) function.

  • Creates a MAX(expr) function expression that returns the maximum value in the group of the values expressed by the given expression.

    Declaration

    Objective-C

    + (nonnull CBLQueryExpression *)max:(nonnull CBLQueryExpression *)expression;

    Swift

    class func max(_ expression: CBLQueryExpression) -> CBLQueryExpression

    Parameters

    expression

    The expression.

    Return Value

    The MAX(expr) function.

  • Creates a SUM(expr) function expression that return the sum of all number values in the group of the values expressed by the given expression.

    Declaration

    Objective-C

    + (nonnull CBLQueryExpression *)sum:(nonnull CBLQueryExpression *)expression;

    Swift

    class func sum(_ expression: CBLQueryExpression) -> CBLQueryExpression

    Parameters

    expression

    The expression.

    Return Value

    The SUM(expr) function.

  • Creates a STR_TO_MILLIS(expr) function that returns the number of milliseconds since the unix epoch of the given ISO 8601 date time string expression.

    Note

    Valid date strings must start with a date in the form YYYY-MM-DD (time only strings are not supported).

    Times can be of the form HH:MM, HH:MM:SS, or HH:MM:SS.FFF. Leading zero is not optional (i.e. 02 is ok, 2 is not). Hours are in 24-hour format. FFF represents milliseconds, and trailing zeros are optional (i.e. 5 == 500).

    Time zones can be in one of three forms: (+/-)HH:MM (+/-)HHMM Z (which represents UTC)

    No time zone present will default to the device local time zone.

    Declaration

    Objective-C

    + (nonnull CBLQueryExpression *)stringToMillis:
        (nonnull CBLQueryExpression *)expression;

    Swift

    class func string(toMillis expression: CBLQueryExpression) -> CBLQueryExpression

    Parameters

    expression

    The validly formatted ISO 8601 date time string expression.

    Return Value

    The corresponding function that converts the date time string to timestamp.

  • Creates a STR_TO_UTC(expr) function that returns the ISO 8601 UTC datetime string of the given ISO 8601 date time string expression.

    Note

    Valid date strings must start with a date in the form YYYY-MM-DD (time only strings are not supported).

    Times can be of the form HH:MM, HH:MM:SS, or HH:MM:SS.FFF. Leading zero is not optional (i.e. 02 is ok, 2 is not). Hours are in 24-hour format. FFF represents milliseconds, and trailing zeros are optional (i.e. 5 == 500).

    Time zones can be in one of three forms: (+/-)HH:MM (+/-)HHMM Z (which represents UTC)

    No time zone present will default to the device local time zone.

    Declaration

    Objective-C

    + (nonnull CBLQueryExpression *)stringToUTC:
        (nonnull CBLQueryExpression *)expression;

    Swift

    class func string(toUTC expression: CBLQueryExpression) -> CBLQueryExpression

    Parameters

    expression

    The validly formatted ISO 8601 date time string expression.

    Return Value

    The corresponding function that converts the string to UTC string.

  • Creates a MILLIS_TO_STR(expr) function that returns a ISO 8601 date time string in device local timezone of the given number of milliseconds since the unix epoch expression.

    Note

    If the input expression is not numeric, then the result will be null.

    Declaration

    Objective-C

    + (nonnull CBLQueryExpression *)millisToString:
        (nonnull CBLQueryExpression *)expression;

    Swift

    class func millis(toString expression: CBLQueryExpression) -> CBLQueryExpression

    Parameters

    expression

    The numeric value representing milliseconds since the unix epoch.

    Return Value

    The corresponding function that converts the timestamp to the ISO 8601 date string.

  • Creates a MILLIS_TO_UTC(expr) function that returns the UTC ISO 8601 date time string of the given number of milliseconds since the unix epoch expression.

    Note

    If the input expression is not numeric, then the result will be null.

    Declaration

    Objective-C

    + (nonnull CBLQueryExpression *)millisToUTC:
        (nonnull CBLQueryExpression *)expression;

    Swift

    class func millis(toUTC expression: CBLQueryExpression) -> CBLQueryExpression

    Parameters

    expression

    The numeric value representing milliseconds since the unix epoch.

    Return Value

    The corresponding function that converts the timestamp into the UTC ISO 8601 string.

  • Not available

    Declaration

    Objective-C

    - (nonnull instancetype)init;
  • ENTERPRISE EDITION ONLY : UNCOMMITTED

    Creates prediction function with the given model name and input. When running a query with the prediction function, the corresponding predictive model registered to CBLDatabase class will be called with the given input to predict the result.

    The prediction result returned by the predictive model will be in a form dictionary object. To create an expression that refers to a property in the prediction result, the -property: method of the created CBLQueryPredictionFunction object can be used.

    Declaration

    Objective-C

    + (nonnull CBLQueryPredictionFunction *)
        predictionUsingModel:(nonnull NSString *)model
                       input:(nonnull CBLQueryExpression *)input;

    Swift

    class func prediction(usingModel model: String, input: CBLQueryExpression) -> CBLQueryPredictionFunction

    Parameters

    model

    The predictive model name registered to the CouchbaseLite Database.

    input

    The expression evaluated to a dictionary.

    Return Value

    A CBLQueryPredictionFunction object.

  • ENTERPRISE EDITION ONLY

    Creates a function that returns the euclidean distance between the two input vectors. The result is a non-negative floating-point number. The expression1 and expression2 must be arrays of numbers, and must be the same length.

    Declaration

    Objective-C

    + (nonnull CBLQueryExpression *)
        euclideanDistanceBetween:(nonnull CBLQueryExpression *)expression1
                             and:(nonnull CBLQueryExpression *)expression2;

    Swift

    class func euclideanDistanceBetween(_ expression1: CBLQueryExpression, and expression2: CBLQueryExpression) -> CBLQueryExpression

    Parameters

    expression1

    The expression evaluated to an arrays of numbers.

    expression2

    The expression evaluated to an arrays of numbers.

    Return Value

    The euclient distance between two given input vectors.

  • ENTERPRISE EDITION ONLY

    Creates a function that returns the squared euclidean distance between the two input vectors. The result is a non-negative floating-point number. The expression1 and expression2 must be arrays of numbers, and must be the same length.

    Declaration

    Objective-C

    + (nonnull CBLQueryExpression *)
        squaredEuclideanDistanceBetween:(nonnull CBLQueryExpression *)expression1
                                    and:(nonnull CBLQueryExpression *)expression2;

    Swift

    class func squaredEuclideanDistanceBetween(_ expression1: CBLQueryExpression, and expression2: CBLQueryExpression) -> CBLQueryExpression

    Parameters

    expression1

    The expression evaluated to an arrays of numbers.

    expression2

    The expression evaluated to an arrays of numbers.

    Return Value

    The squared euclient distance between two given input vectors.

  • ENTERPRISE EDITION ONLY

    Creates a function that returns the cosine distance which one minus the cosine similarity between the two input vectors. The result is a floating-point number ranges from −1.0 to 1.0. The expression1 and expression2 must be arrays of numbers, and must be the same length.

    Declaration

    Objective-C

    + (nonnull CBLQueryExpression *)
        cosineDistanceBetween:(nonnull CBLQueryExpression *)expression1
                          and:(nonnull CBLQueryExpression *)expression2;

    Swift

    class func cosineDistanceBetween(_ expression1: CBLQueryExpression, and expression2: CBLQueryExpression) -> CBLQueryExpression

    Parameters

    expression1

    The expression evaluated to an arrays of numbers.

    expression2

    The expression evaluated to an arrays of numbers.

    Return Value

    The cosine distance between two given input vectors.