Skip to content
Snippets Groups Projects
README.md 3.08 KiB
Newer Older
Franky Begue's avatar
Franky Begue committed
# Couchbase_Eventing_Script

Franky Begue's avatar
Franky Begue committed
This utility lets you programatically deploy couchbase eventing functions based on your local folder structure.
Franky Begue's avatar
Franky Begue committed
For now its just a POC but it works! and it gets you out of trying to interact with their web UI which is . . . lacking.   

Basically we're just setting up a folder with some functions in it, where each file corresponds to an eventing function name [like the ones listed here](http://128.146.12.34:8091/ui/index.html#!/eventing/summary)
Then when you want to update one, you make changes to that file and run the importDeploy script with the function (and file) name as an arg. It'll find the new code and post it
to the server and take care of importing/deploying/undeploying for you.

## Quickstart

- fill out the config (./config.js) which for now just uses YOUR login for couchbase
Franky Begue's avatar
Franky Begue committed
- `npm install`
Franky Begue's avatar
Franky Begue committed
- Run the main from the command line with two arguments: 
     - function name (or file name without '.js') where this file is located in the /functions folder
     - operation mode (true = update, false = create):  
Franky Begue's avatar
Franky Begue committed

Example: `node couchbase_eventing getErrors true`

Please check out the `example_function.js` and in general please do not break anything


## Known issues

- UI 'Edit Javascript' stickiness  
One of the serveral reasons I made this thing: if you go [here](http://128.146.12.34:8091/ui/index.html#!/eventing/summary)  you can sit and watch the UI report 'status' updates
on the eventing/summary page, but even after it finishes (status = deployed) you still need to refresh the page in order to see the new code. Meaning - if you want to double 
check that your thing is out there, make sure to refresh the page!

- NO inline n1ql queries!  
  (For now, see below)

## Todo

- inline n1ql queries
Franky Begue's avatar
Franky Begue committed
- add 'create' mode
- 
Franky Begue's avatar
Franky Begue committed
- allow user to specify path to function file in CLI (get rid of assumed folder structure?)
- change login to use some 'system' account not our 'user' logins



## Couchbase Event Scripts


#### eventing api
`https://docs.couchbase.com/server/current/eventing/eventing-api.html`



- although they do not specify, a POST to /import with the content of a function that  
already exists will actually UPDATE that function (there is no explicit PUT)
NOT however if it is deployed. must be in undeployed state to work. This is the major function
this project takes advantage of.


- these scripts have the ability to accept inline n1ql queries  
But you won't be able to run them locally obviously if you can't parse them.
On the server it does this parsing by detecting these inline statements and turning them into N1QL() calls - 
so even though we're not using them yet, best to get in the practice of properly terminating every statement with a
semicolon to help the parser out in the case you do use this inline n1ql language

- interestingly, the documentation specifically says not to use the built in N1QL() function to do the parsing before hand,
although that would be ideal...

Franky Begue's avatar
Franky Begue committed
## Couchbase Node SDK
Franky Begue's avatar
Franky Begue committed

Franky Begue's avatar
Franky Begue committed
Check out `couchbase_eventing_sdk.js` to see some examples on how to interact with the query server via [their node sdk](https://github.com/couchbase/couchnode)
Franky Begue's avatar
Franky Begue committed