Skip to content

Commit c01c077

Browse files
feat(command-functions): update fauna crud template (#1853)
* Update fauna crud template * Update src/functions-templates/js/fauna-crud/package.json Co-authored-by: João Antunes <[email protected]> * fix prettier Co-authored-by: João Antunes <[email protected]>
1 parent b34c2ef commit c01c077

File tree

7 files changed

+9
-9
lines changed

7 files changed

+9
-9
lines changed

src/functions-templates/js/fauna-crud/create-schema.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ const createFaunaDB = function () {
1515

1616
/* Based on your requirements, change the schema here */
1717
return client
18-
.query(query.Create(query.Ref('classes'), { name: 'items' }))
18+
.query(query.CreateCollection({ name: 'items' }))
1919
.then(() => {
2020
console.log('Created items class')
2121
return client.query(
22-
query.Create(query.Ref('indexes'), {
22+
query.CreateIndex({
2323
name: 'all_items',
24-
source: query.Ref('classes/items'),
24+
source: query.Collection('items'),
2525
active: true,
2626
}),
2727
)

src/functions-templates/js/fauna-crud/create.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const handler = async (event) => {
1717
}
1818
/* construct the fauna query */
1919
return client
20-
.query(query.Create(query.Ref('classes/items'), item))
20+
.query(query.Create(query.Collection('items'), item))
2121
.then((response) => {
2222
console.log('success', response)
2323
/* Success! return the response with statusCode 200 */

src/functions-templates/js/fauna-crud/delete.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const handler = async (event) => {
1111
const { id } = event
1212
console.log(`Function 'delete' invoked. delete id: ${id}`)
1313
return client
14-
.query(query.Delete(query.Ref(`classes/items/${id}`)))
14+
.query(query.Delete(query.Ref(query.Collection('items'), id)))
1515
.then((response) => {
1616
console.log('success', response)
1717
return {

src/functions-templates/js/fauna-crud/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
"author": "Netlify",
1616
"license": "MIT",
1717
"dependencies": {
18-
"faunadb": "^2.14.2"
18+
"faunadb": "^4.0.3"
1919
}
2020
}

src/functions-templates/js/fauna-crud/read-all.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const client = new Client({
1010
const handler = async () => {
1111
console.log('Function `read-all` invoked')
1212
return client
13-
.query(query.Paginate(query.Match(query.Ref('indexes/all_items'))))
13+
.query(query.Paginate(query.Match(query.Index('all_items'))))
1414
.then((response) => {
1515
const itemRefs = response.data
1616
// create new query out of item refs. http://bit.ly/2LG3MLg

src/functions-templates/js/fauna-crud/read.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const handler = async (event) => {
1111
const { id } = event
1212
console.log(`Function 'read' invoked. Read id: ${id}`)
1313
return client
14-
.query(query.Get(query.Ref(`classes/items/${id}`)))
14+
.query(query.Get(query.Ref(query.Collection('items'), id)))
1515
.then((response) => {
1616
console.log('success', response)
1717
return {

src/functions-templates/js/fauna-crud/update.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const handler = async (event) => {
1212
const { id } = event
1313
console.log(`Function 'update' invoked. update id: ${id}`)
1414
return client
15-
.query(query.Update(query.Ref(`classes/items/${id}`), { data }))
15+
.query(query.Update(query.Ref(query.Collection('items'), id), { data }))
1616
.then((response) => {
1717
console.log('success', response)
1818
return {

0 commit comments

Comments
 (0)