Introduction to Fauna Shell
This file contains 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
#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