Rock U - Lava - Entity Commands

Transcribed Video Content

Lava is powerful on its own, but entity commands really bring it up a notch. With a single command, you can access Rock's entire data model. So let's look at how to write an entity commands in Rock right now. Now I'm looking at the documentation for our entity commands and you can find this under the lava portion of our community site. And this entity command is super special because it allows you to access something that's really prevalent in the Rock database, and that is entities. If you don't know what an entity is, we have another video on that. I suggest you go find out what an entity is so that this video makes a bit more sense. But basically, everything that's stored in our database is an entity. So we're looking at the entity command, and I'm in the Lava documentation, which is on our community site. And the entity command is really special because it allows you to access something that's really prevalent in the Rock database. Now if you don't know what an entity is, I suggest that you go watch our videos on it as it's really important to know what an entity is for this video to make sense. But I'm gonna step briefly through what the commands looks , what you can do with it, and more. So this command is really simple. You just open your tag this. And in within our tag for this entity commands, we simply type in the name of the entity. One you'll use pretty often probably is person, then we will add a parameter here. I'll explain what parameters are and what your options are in just a second. Then you close the tag. Then after you put the lava that you want to use, you can put an end tag. So we'll simply say end entity here, and it's the same pattern for any other entity that you use. But we're using a parameter here to narrow down the results since if we actually just looked for every every single thing we'd get back, if we did straight up person, end person, we'd be overwhelmed by the number of results because we have so many entries for a person entity in our database. So this parameter, which will be one you use pretty often, just says where colon, and then we have a single quote, and we're wrapping this parameter in single quotes. We're basically just saying where the last name property equals Decker. So rather than getting every person, we're only getting the people with the last name of Decker. Then we've created an array, some data we can pull from, and we can use additional lava, just a for statement, which we have another video on if you wanna learn more about it. And we're looping through the results. So it's pretty simple. Let's quickly go over some more things. So there's all sorts of parameters you can use. We have them all listed in our documentation and there's different operators you can use for the most important or one of the most used parameters which is where. For example, you can pick a condition of equaling something property equals Decker or not equal starts with. There's way way more options. You can even pick an and or an or operator so that you get back more results. And there's lots of other helpful parameters, but one other thing I want to mention is that you can turn off security for these commands. And you only want to do this when you don't need security. But by default, this is really helpful. Rock makes sure to respect the security in your database. So if a person doesn't have access to seeing person entities, then they won't get those results if they don't have security. But that means the statement runs a little bit slower because especially for getting a lot of results, Rock is just checking constantly. Does this person have security for this? Does this person have security? But you can say security enabled false if you want to skip that check. Let's look at some real examples of entity commands. So here again is that example we saw before, pretty similar. We have our where parameter. We're looking for last name Decker. And in the database, it pulled out those four people that have the last name of Decker. We're simply displaying their full name. Then here's a more complex version of that statement. So we're looking for a person where the last name equals Decker or the position contains pastor. So then we're looping through that and outputting what the results are. And as you can see, we get the deckers as before, but we're also getting to see the position attribute. And this is something that's pretty special. You can access attributes, properties more on an entity. If you don't know what the difference is between an attribute and a property, please read our documentation or watch our other Rock You videos as that's an important concept. But we get Ted Decker and it says outreach pastor, then we get someone who isn't a Decker because we said we're looking for people with last name Decker or position of pastor. So we get Pete Foster senior pastor. Now another really helpful parameter that makes your statements a little bit cleaner and shorter is simply the ID parameter. If you wanna look for a person by ID or any kind of entity, you can do that just this. And if that's if the ID off the top of your head, of course, and that's Ted Decker for us. So we see Ted Decker gets output. You can even use a comma and put in multiple IDs. And if you wanna know more about the different parameters available to you, again, just look at the documentation. But we've output the people with the ID of five and six, Ted and Cindy Decker. Now a data view. This is really special because data views are a great way to store information based off filters and Rock. And you can take the ID of a data view and you can iterate or loop the results or whatever you wanna do to take the data you get from this command. But we're using the data view with an ID of one, and it's it's genuinely just outputting the name of everyone who's in that data view. Now you may be thinking, that, but I'm probably gonna have to go create multiple data views or edit my data view to get the information I want. But you can actually stack some parameters. So we're getting people from our data view, then we're using the where parameter to say where the gender equals male. So it's not only taking all the people in this data view, it's filtering again to showing the people that have a gender of male. Then you can even sort on top of that another super helpful parameter that allows allows you to pick whether you want to do a descending or ascending order on some different properties. right now, we're sorting by last name, then first name, descending. And you can see right now, we get a little bit of a different order than we had before. Then you can do some more iteration such as we can sort, then we can offset, and what an offset does is it skips a certain number of entries. So we've done this sort, then the top five people that came back, we skipped them, and we limited the results to the top five of those so you can really slice up the data that you're getting. Now this is another great example. We can sort and do things on other entity commands or other entities. This is an entity we haven't shown yet, but you'll probably end up using entity commands with a lot. We're just finding a group where the group type ID is 10, and that's just families in our database. Then we're sorting them by name. And there we go, we can see all of the families that are in that group type that we're looking for. Now you can easily pull all kinds of data from Rock in a really flexible way. So start to pair this with some other things in Lava such as if statements, for loops, and more, and you can do some really powerful things. Thanks for watching this video on entity commands.