Uploaded image for project: 'Couchbase Documentation'
  1. Couchbase Documentation
  2. DOC-11704

Add documentation for N1QL managed Javascript UDFs

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • Trinity
    • Trinity
    • query
    • 8

    Description

      Add a new type of javascript user defined function :

      • CREATE FUNCTION doc page

      https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/createfunction.html

      • Javascript UDFs with Couchbase:

      https://docs.couchbase.com/server/current/javascript-udfs/javascript-functions-with-couchbase.html

      And any other doc pages necessary.

      N1QL Managed Javascript Functions

      Allows users to create a Javascript function and its corresponding N1QL function in a single statement.

      There is a one to one relationship between the Javascript function and the N1QL UDF.

       

      Edit:

      • In N1QL managed JS UDFs the library of javascript code is specified inline along with the SQL++ function creation.

       

      • Functions defined in this inline library of javascript code can only be invoked/ referenced within this library.

                 And cannot be accessed in other libraries.

       

      • Note that: All the RBAC pre-requisites, constraints on allowed Javascript constructs, SQL++ invocation methods - are the same for both the existing external JS UDFs and the new N1QL managed JS UDFs.

       

      Syntax

       

      create-function-query-managed-javascript ::= 
      'CREATE' ( 'OR' 'REPLACE' )? 'FUNCTION' function '(' params? ')'
                     ( 'IF' 'NOT' 'EXISTS' )?
                     'LANGUAGE' 'JAVASCRIPT' 'AS' javascript-code
      

       

       

      Function : function name

      Params : function parameters

      Javascript-code : A string that contains Javascript code. It must contain a function definition with the SAME name as the corresponding N1QL function.

      The javascript-code can contain multiple function definitions. But these functions can only be referenced within this N1QL function and cannot be shared.

       

      Example:

      Create N1QL managed JS UDF:

      CREATE FUNCTION func1() LANGUAGE JAVASCRIPT AS "function func1(param1) { return param1+100;}”;

       

      Execute the function:

       

      EXECUTE FUNCTION func1(100);
      

      [
        200
      ]

       

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              simon.dew Simon Dew
              dhanya.gowrish Dhanya Gowrish
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty