Skip to content

Instantly share code, notes, and snippets.

@retroryan
Last active July 13, 2018 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save retroryan/faa2ad045242c2617f72021bf72a864b to your computer and use it in GitHub Desktop.
Save retroryan/faa2ad045242c2617f72021bf72a864b to your computer and use it in GitHub Desktop.
Introduction to Fauna Shell
#Create a Class
CreateClass({ name: "orders" })
#Create an Index
CreateIndex(
{
name: "orders_index",
source: Class("orders"),
values: [{ field: ["data", "orderId"], reverse:true }, { field: ["ref"] }],
serialized: true
})
#Get a specific Index
Get(Index("orders_index"))
#Get all classes
Get(Classes())
#Get all Indexes
Get(Indexes())
#Delete order class so it can be re-created
Delete(Class("orders"))
CreateClass({ name: "orders" })
#Create an instance of the orders class
Create(Class("orders"),{data:{"orderId":70,"clientName":"Jean Fuller","address":"93 Spohn Place","status":"Ready to Ship","itemDescription":"Canon T90"}})
#Delete an instance of the order class
Delete(Ref(Class("orders"),"204109895492960770"))
#Get the latest order and bind it to the latest variable
Let( {
latest:Paginate(Match(Index("orders_index")))
},
Var("latest")
)
#Get the latest order, next get the last index from that order and finally add 1 to it to get the next index
Let( {
latest:Paginate(Match(Index("orders_index")))
},
Let({
nextIndex:Add(Select([0,0], Var("latest"), 0),1)
}, Var("nextIndex"))
)
#Get the latest order index and use it to create another order entry
Let( {
latest:Paginate(Match(Index("orders_index")))
},
Let({
nextIndex:Add(Select([0,0], Var("latest"), 0),1)
},
Create(Class("orders"),{data:{"orderId":Var("nextIndex"),"clientName":"Jean Fuller","address":"93 Spohn Place","status":"Ready to Ship","itemDescription":"Canon T90"}})
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment