Load a JavaScript UDF library

Register User-Defined Functions written in JavaScript with FalkorDB using falkor.register()

falkordb f640de6 2 files · 2.0 KB Updated

File contents

Load a JavaScript UDF library

Register User-Defined Functions (UDFs) written in JavaScript with FalkorDB.

Usage

Use the falkor.register() function within JavaScript code to register UDFs, then load the library using the FalkorDB client.

Example

from falkordb import FalkorDB

db = FalkorDB(host='localhost', port=6379)
lib = "StringUtils"
script = """
function UpperCaseOdd(s) {
  return s.split('')
    .map((c, i) => i % 2 !== 0 ? c.toUpperCase() : c)
    .join('');
};

falkor.register('UpperCaseOdd', UpperCaseOdd);
"""

db.udf_load(lib, script)

Notes

  • UDFs must be written in JavaScript
  • Use falkor.register() to make functions available in Cypher queries
  • The library name (lib) is used as a namespace for the functions
  • UDFs are stored in FalkorDB and persist across restarts
  • UDFs must be pure functions without side effects

falkordb/skills/tree/main/udf-skills/load-javascript-udf commit f640de6dd0

Frequently asked questions

npx skillmds@latest add falkordb/load-a-javascript-udf-library