1
votes

In Oracle/SQL we have provision to write user defined functions where we can write complex logic to computer some values and then return back in query.

Do we have such feature in Couchbase?

We are moving from a heavy Oracle database to Couchbase and in existing Oracle database we have a lot stored procedures and user defined functions. So I am confused how to move that entire logic into Couchbase. I had a little about eventing functions but that is for eventing purpose only I guess.

I know we have views in Couchbase, what about user defined functions? Thanks in advance.

2

2 Answers

2
votes

N1QL and javascript functions are in developer preview mode in the upcoming 6.5 release:

https://docs.couchbase.com/server/6.5/n1ql/n1ql-language-reference/userfun.html

0
votes

Just touching base on this again...

As Marco Greco noted Eventing is a "special" user defined function that responds to all mutations (inset/upsert or deletes) and allows you to can write complex logic to compute things and update the mutating document (or other documents) or contact a REST API. To lean more about Eventing refer to eventing-overview and the Eventing examples

Now of course since you said you were interested in a UDF that can return back in query as in N1QL this would be User Defined Functions (UDFs). However that is a currently in a Developer Preview Mode (not to be used for production) for more details see: n1ql-language-reference/userfun.

As I previously mentioned there two versions of N1QL JavaScript functions in the 6.5 DP the first are simple inline functions (more pure math no intermediate variables) and the second is more complex external functions (variables are allowed) refer forums.couchbase.com/t/do-we-have-stored-procedure...