Skip to content
This repository was archived by the owner on Sep 8, 2021. It is now read-only.

Commit 679f2dd

Browse files
committed
move fauna client inside function handler
Signed-off-by: DavidWells <[email protected]>
1 parent 85f4def commit 679f2dd

10 files changed

+6423
-20370
lines changed

functions/todos-create.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
/* Import faunaDB sdk */
22
const faunadb = require('faunadb')
3-
4-
/* configure faunaDB Client with our secret */
53
const q = faunadb.query
6-
const client = new faunadb.Client({
7-
secret: process.env.FAUNADB_SERVER_SECRET
8-
})
94

105
/* export our lambda function as named "handler" export */
116
exports.handler = async (event, context) => {
7+
/* configure faunaDB Client with our secret */
8+
const client = new faunadb.Client({
9+
secret: process.env.FAUNADB_SERVER_SECRET
10+
})
1211
/* parse the string body into a useable JS object */
1312
const data = JSON.parse(event.body)
1413
console.log('Function `todo-create` invoked', data)

functions/todos-delete-batch.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/* Import faunaDB sdk */
22
const faunadb = require('faunadb')
3-
43
const q = faunadb.query
5-
const client = new faunadb.Client({
6-
secret: process.env.FAUNADB_SERVER_SECRET
7-
})
84

95
exports.handler = async (event, context) => {
6+
/* configure faunaDB Client with our secret */
7+
const client = new faunadb.Client({
8+
secret: process.env.FAUNADB_SERVER_SECRET
9+
})
1010
const data = JSON.parse(event.body)
1111
console.log('data', data)
1212
console.log('Function `todo-delete-batch` invoked', data.ids)

functions/todos-delete.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/* Import faunaDB sdk */
22
const faunadb = require('faunadb')
33
const getId = require('./utils/getId')
4-
54
const q = faunadb.query
6-
const client = new faunadb.Client({
7-
secret: process.env.FAUNADB_SERVER_SECRET
8-
})
5+
96

107
exports.handler = async (event, context) => {
8+
/* configure faunaDB Client with our secret */
9+
const client = new faunadb.Client({
10+
secret: process.env.FAUNADB_SERVER_SECRET
11+
})
1112
const id = getId(event.path)
1213
console.log(`Function 'todo-delete' invoked. delete id: ${id}`)
1314
return client.query(q.Delete(q.Ref(`classes/todos/${id}`)))

functions/todos-read-all.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/* Import faunaDB sdk */
22
const faunadb = require('faunadb')
3-
43
const q = faunadb.query
5-
const client = new faunadb.Client({
6-
secret: process.env.FAUNADB_SERVER_SECRET
7-
})
4+
85

96
exports.handler = (event, context) => {
107
console.log('Function `todo-read-all` invoked')
8+
/* configure faunaDB Client with our secret */
9+
const client = new faunadb.Client({
10+
secret: process.env.FAUNADB_SERVER_SECRET
11+
})
1112
return client.query(q.Paginate(q.Match(q.Ref('indexes/all_todos'))))
1213
.then((response) => {
1314
const todoRefs = response.data

functions/todos-read.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/* Import faunaDB sdk */
22
const faunadb = require('faunadb')
33
const getId = require('./utils/getId')
4-
54
const q = faunadb.query
6-
const client = new faunadb.Client({
7-
secret: process.env.FAUNADB_SERVER_SECRET
8-
})
95

106
exports.handler = (event, context) => {
7+
/* configure faunaDB Client with our secret */
8+
const client = new faunadb.Client({
9+
secret: process.env.FAUNADB_SERVER_SECRET
10+
})
1111
const id = getId(event.path)
1212
console.log(`Function 'todo-read' invoked. Read id: ${id}`)
1313
return client.query(q.Get(q.Ref(`classes/todos/${id}`)))

functions/todos-update.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const faunadb = require('faunadb')
22
const getId = require('./utils/getId')
3-
43
const q = faunadb.query
5-
const client = new faunadb.Client({
6-
secret: process.env.FAUNADB_SERVER_SECRET
7-
})
84

95
exports.handler = (event, context) => {
6+
/* configure faunaDB Client with our secret */
7+
const client = new faunadb.Client({
8+
secret: process.env.FAUNADB_SERVER_SECRET
9+
})
1010
const data = JSON.parse(event.body)
1111
const id = getId(event.path)
1212
console.log(`Function 'todo-update' invoked. update id: ${id}`)

0 commit comments

Comments
 (0)