Last active
June 21, 2019 15:14
-
-
Save recursivecodes/93df9ff57bc1baf1a4a52133498a0005 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fdk = require('@fnproject/fdk'); | |
| const oracledb = require('oracledb'); | |
| const dateFormat = require('dateformat'); | |
| oracledb.outFormat = oracledb.OBJECT; | |
| oracledb.fetchAsString = [oracledb.CLOB]; | |
| let pool; | |
| fdk.handle( async function(input){ | |
| if( !pool ) { | |
| pool = await oracledb.createPool({ | |
| user: process.env.DB_USER, | |
| password: process.env.DB_PASSWORD, | |
| connectString: process.env.CONNECT_STRING, | |
| }); | |
| } | |
| const connection = await pool.getConnection(); | |
| const insert = await connection.execute("insert into json_demo (data, captured_at) values (:data, to_timestamp(:capturedAt, 'yyyy-mm-dd HH24:mi:ss'))", | |
| { | |
| data: JSON.stringify(input), | |
| capturedAt: dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss') | |
| }, | |
| { autoCommit: true } | |
| ); | |
| await connection.close(); | |
| return {insert: insert, complete: true}; | |
| }, {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment