Skip to content

abhirockzz/fn-oracledb-golang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Example for Go functions in Fn talking to Oracle DB

step 0

  • git clone https://github.com/abhirockzz/fn-oracledb-golang
  • run seed-db.sql to create the table in your DB
  • replace config section func.yaml with DB connectivity details for your specific environment

step 1

  • fn start

Configure Docker

  • docker login (use your docker registry credentials)
  • export FN_REGISTRY=<name of your docker repository>

your function docker image name will end up being - <docker repo name>/<function name in func.yaml>:<version in func.yaml>

Moving on....

  • cd fn-oracledb-golang
  • fn -v deploy --all (-v will activate verbose mode)

adding --local to above command will build & push docker images locally (and run it from there). Remove it if you want use a dedicated/external Docker registry

All your functions (create, read, update, delete) should now be deployed. Check it using fn inspect app fn-oradb-go-app and fn list routes fn-oradb-go-app

Behind the scenes

Build and runtime Docker images

Custom Docker images have been used for build_image and run_image (see func.yaml) - this Docker image pre-packages a Go Oracle driver. You can also build you own image

Hot functions and DB connection

DB connection is not closed at end of every function invocation - this is to leverage hot functions. If the function is called before the idle_timeout (default is 30 seconds and can be configured via func.yaml), the call will be routed to a hot function (already used) DB connection will not be repeated again

app.yaml

Bare minimum config file which defines the name of the app i.e. fn-oradb-go-app

Test

... with Fn CLI using fn call

Create

echo -n '{"emp_email": "a@b.com","emp_name": "abhishek","emp_dept": "Product Divison"}' | fn call fn-oradb-go-app /create

Create as many as you want

Read

  • fn call fn-oradb-go-app /read (to fetch all employees)
  • echo -n 'a@b.com' | fn call fn-oradb-go-app /read (to fetch employee with email a@b.com)

Update

It is possible to update the department of an employee

echo -n '{"emp_email": "a@b.com", "emp_dept": "Support Operations"}' | fn call fn-oradb-go-app /update

check to make sure - echo a@b.com | fn call fn-oradb-go-app /read

Delete

Use employee email to specify which employee record you want to delete

echo -n 'a@b.com' | fn call fn-oradb-go-app /delete

check to make sure - echo -n 'a@b.com' | fn call fn-oradb-go-app /read

About

Example for Go functions in Fn talking to Oracle DB

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published