Intro To RavenDB - Auto Indexing, Change Tracking, and More
Read full transcript 63 segments
-
The heart of almost any application is The heart of almost any application is its database. The performance and its database. The performance and its database. The performance and features of your database will be either features of your database will be either features of your database will be either a limiting factor or a launching point a limiting factor or a launching point a limiting factor or a launching point for your application. Today we're going for your application. Today we're going for your application. Today we're going to be looking at Raven DB, a multimodal to be looking at Raven DB, a multimodal to be looking at Raven DB, a multimodal NoSQL database that autoindexes your NoSQL database that autoindexes your NoSQL database that autoindexes your queries, can track changes to your data, queries, can track changes to your data, queries, can track changes to your data, and that returns your queries in and that returns your queries in and that returns your queries in milliseconds while being acid compliant. milliseconds while being acid compliant. milliseconds while being acid compliant. Oh, and it can run on a Raspberry Pi. Oh, and it can run on a Raspberry Pi. Oh, and it can run on a Raspberry Pi. Now, in this video, I'm going to give Now, in this video, I'm going to give Now, in this video, I'm going to give you an overview of what Raven DB is you an overview of what Raven DB is you an overview of what Raven DB is before we jump right into the code. In before we jump right into the code. In before we jump right into the code. In just a few minutes, we'll have a just a few minutes, we'll have a just a few minutes, we'll have a database up and running, and we'll be database up and running, and we'll be database up and running, and we'll be performing full CRUD operations on it performing full CRUD operations on it performing full CRUD operations on it from C. And along the way, we'll look at from C. And along the way, we'll look at from C. And along the way, we'll look at autoindexing, change tracking, working autoindexing, change tracking, working autoindexing, change tracking, working with Aspire, and more. We'll also with Aspire, and more. We'll also with Aspire, and more. We'll also discuss the pricing around Raven DB. And discuss the pricing around Raven DB. And discuss the pricing around Raven DB. And the good news is that for developers, the good news is that for developers, the good news is that for developers, it's free. You can also get a free it's free. You can also get a free it's free. You can also get a free community license to start working in community license to start working in community license to start working in production with Raven DB. Now, this production with Raven DB. Now, this production with Raven DB. Now, this video has been sponsored by Raven DB. video has been sponsored by Raven DB. video has been sponsored by Raven DB. So, I want to explain what that means. I So, I want to explain what that means. I So, I want to explain what that means. I only take sponsorships where I believe only take sponsorships where I believe only take sponsorships where I believe in the product and I believe it would in the product and I believe it would in the product and I believe it would benefit my audience as well. Basically, benefit my audience as well. Basically, benefit my audience as well. Basically, I take money from vendors to create I take money from vendors to create I take money from vendors to create videos that I would have created for videos that I would have created for videos that I would have created for free. Raven DB is no different. As you free. Raven DB is no different. As you free. Raven DB is no different. As you will see, it's a great database with a will see, it's a great database with a will see, it's a great database with a lot of great features and it also lot of great features and it also lot of great features and it also integrates well withnet. So, you as a integrates well withnet. So, you as a integrates well withnet. So, you as a viewer get a video with even more viewer get a video with even more viewer get a video with even more content than normal. Plus, you get some content than normal. Plus, you get some content than normal. Plus, you get some extras. In this case, you'll get a $200 extras. In this case, you'll get a $200 extras. In this case, you'll get a $200 credit for the cloud if you use code I
-
credit for the cloud if you use code I credit for the cloud if you use code I am Tim Court. The details are in the am Tim Court. The details are in the am Tim Court. The details are in the description. And if you use the link description. And if you use the link description. And if you use the link below to download the source code, I'll below to download the source code, I'll below to download the source code, I'll also email you the details to get the also email you the details to get the also email you the details to get the free crowd cloud credit as well. So, free crowd cloud credit as well. So, free crowd cloud credit as well. So, let's jump right into looking at Raven let's jump right into looking at Raven let's jump right into looking at Raven DB. A good place to start is raindb.net. DB. A good place to start is raindb.net. DB. A good place to start is raindb.net. This is the page where there's a lot of This is the page where there's a lot of This is the page where there's a lot of information about Raven DB, including information about Raven DB, including information about Raven DB, including the the documentation, which by the way, the the documentation, which by the way, the the documentation, which by the way, when I talked to the developers, one of when I talked to the developers, one of when I talked to the developers, one of the first things I said was, "I love the first things I said was, "I love the first things I said was, "I love your docs. They're so good. There's lots your docs. They're so good. There's lots your docs. They're so good. There's lots of great stuff in here. They're really of great stuff in here. They're really of great stuff in here. They're really helpful for reading through and helpful for reading through and helpful for reading through and understanding the various parts of the understanding the various parts of the understanding the various parts of the system." Now, there's also AI tools for system." Now, there's also AI tools for system." Now, there's also AI tools for helping you understand the docs, helping helping you understand the docs, helping helping you understand the docs, helping you understand in context. We're going you understand in context. We're going you understand in context. We're going to talk more about that. Just a quick to talk more about that. Just a quick to talk more about that. Just a quick note, one of the first thing I talked to note, one of the first thing I talked to note, one of the first thing I talked to them about when it came to my concerns them about when it came to my concerns them about when it came to my concerns or or questions that I had was about AI. or or questions that I had was about AI. or or questions that I had was about AI. And I said, I don't want an AI that's And I said, I don't want an AI that's And I said, I don't want an AI that's that's looking at my production data. that's looking at my production data. that's looking at my production data. And that's not what happens. So the AI And that's not what happens. So the AI And that's not what happens. So the AI is only allowed to see what you give it is only allowed to see what you give it is only allowed to see what you give it a connection string to see. So you can't a connection string to see. So you can't a connection string to see. So you can't it's not going to be accidentally it's not going to be accidentally it's not going to be accidentally looking at your production data. So looking at your production data. So looking at your production data. So that's an really important uh point for that's an really important uh point for that's an really important uh point for me was that it didn't it didn't start me was that it didn't it didn't start me was that it didn't it didn't start kind of peeking at things it shouldn't.
-
kind of peeking at things it shouldn't. kind of peeking at things it shouldn't. I recommend that you only ever allow the I recommend that you only ever allow the I recommend that you only ever allow the the AI to look at at most scrubbed the AI to look at at most scrubbed the AI to look at at most scrubbed developer data. You know scrubbed dev developer data. You know scrubbed dev developer data. You know scrubbed dev databases that can be fine. Um, but databases that can be fine. Um, but databases that can be fine. Um, but don't give it access to production. don't give it access to production. don't give it access to production. That's my recommendation. It's more That's my recommendation. It's more That's my recommendation. It's more useful for helping you work with Raven useful for helping you work with Raven useful for helping you work with Raven DB and helping you configure things, but DB and helping you configure things, but DB and helping you configure things, but otherwise I would not allow it to to otherwise I would not allow it to to otherwise I would not allow it to to access your data necessarily. Now, there access your data necessarily. Now, there access your data necessarily. Now, there are potential exceptions to that and one are potential exceptions to that and one are potential exceptions to that and one of them is the fact that you can of them is the fact that you can of them is the fact that you can integrate Gen AI into a a background integrate Gen AI into a a background integrate Gen AI into a a background worker so that when data comes in, let's worker so that when data comes in, let's worker so that when data comes in, let's say you you have data come in and you say you you have data come in and you say you you have data come in and you want it translated. You could have that want it translated. You could have that want it translated. You could have that record go right to the Gen AI, it could record go right to the Gen AI, it could record go right to the Gen AI, it could translate it and put the translation in translate it and put the translation in translate it and put the translation in a field. That's potential. Um, you gota a field. That's potential. Um, you gota a field. That's potential. Um, you gota be very careful though to make sure that be very careful though to make sure that be very careful though to make sure that you have some really good uh protections you have some really good uh protections you have some really good uh protections around what it can and can't do. It can around what it can and can't do. It can around what it can and can't do. It can also work on external things like also work on external things like also work on external things like attachments to the database. Uh, you can attachments to the database. Uh, you can attachments to the database. Uh, you can do file attachments. It could process do file attachments. It could process do file attachments. It could process those file attachments. There's other those file attachments. There's other those file attachments. There's other things it can do in Jai. You just be things it can do in Jai. You just be things it can do in Jai. You just be really really careful when it comes to really really careful when it comes to really really careful when it comes to production data that you don't have an production data that you don't have an production data that you don't have an AI that could go could go rogue or could AI that could go could go rogue or could AI that could go could go rogue or could be prompt injected. So be very careful be prompt injected. So be very careful be prompt injected. So be very careful of that. Okay. So on here as well is the of that. Okay. So on here as well is the of that. Okay. So on here as well is the pricing real quick. Um you can do pricing real quick. Um you can do pricing real quick. Um you can do installation using Docker. You can do installation using Docker. You can do installation using Docker. You can do which we're going to do today. You can which we're going to do today. You can which we're going to do today. You can do installation using Aspire which I'll
-
do installation using Aspire which I'll do installation using Aspire which I'll hopefully demonstrate today. We can do hopefully demonstrate today. We can do hopefully demonstrate today. We can do installation on prem which means your installation on prem which means your installation on prem which means your own server and then you just pay based own server and then you just pay based own server and then you just pay based upon the cores. And the last option is upon the cores. And the last option is upon the cores. And the last option is you can install via the cloud. You'd you can install via the cloud. You'd you can install via the cloud. You'd have the the cloud version. So pricing I have the the cloud version. So pricing I have the the cloud version. So pricing I would encourage you to look through this would encourage you to look through this would encourage you to look through this because there's different pricing models because there's different pricing models because there's different pricing models here. But the important part here to me here. But the important part here to me here. But the important part here to me is not the pricing because notice it is not the pricing because notice it is not the pricing because notice it says contact us. That's just because says contact us. That's just because says contact us. That's just because it's based upon a number of cores of it's based upon a number of cores of it's based upon a number of cores of your machine. And so it's going to your machine. And so it's going to your machine. And so it's going to change. But uh the important part for me change. But uh the important part for me change. But uh the important part for me is all the things here on the left that is all the things here on the left that is all the things here on the left that allows us to do right. These are all the allows us to do right. These are all the allows us to do right. These are all the features. And notice how many features features. And notice how many features features. And notice how many features there are. This is a great way to come there are. This is a great way to come there are. This is a great way to come in and say, "Hey, what other features in and say, "Hey, what other features in and say, "Hey, what other features does this does this database have?" does this does this database have?" does this does this database have?" Because there's so many. you can kind of Because there's so many. you can kind of Because there's so many. you can kind of look and say, "Hey, let's learn more look and say, "Hey, let's learn more look and say, "Hey, let's learn more about Raven DB ETL and learn more about about Raven DB ETL and learn more about about Raven DB ETL and learn more about what that does or about the security um what that does or about the security um what that does or about the security um of storage encryption versus the read of storage encryption versus the read of storage encryption versus the read only certificates or encryption and only certificates or encryption and only certificates or encryption and transit um tasks and analyzers and transit um tasks and analyzers and transit um tasks and analyzers and studio configuration, all the rest that studio configuration, all the rest that studio configuration, all the rest that can do. This is a great list of here's can do. This is a great list of here's can do. This is a great list of here's some cool features that it does. You can some cool features that it does. You can some cool features that it does. You can look through and kind of expand your look through and kind of expand your look through and kind of expand your knowledge about Raven DB. Also notice in knowledge about Raven DB. Also notice in knowledge about Raven DB. Also notice in here that the cloud pricing has a really here that the cloud pricing has a really here that the cloud pricing has a really great configuration tool that allows us great configuration tool that allows us great configuration tool that allows us to configure for any of the portals or to configure for any of the portals or to configure for any of the portals or any of the cloud providers and see how any of the cloud providers and see how any of the cloud providers and see how much is per hour or per month based upon
-
much is per hour or per month based upon much is per hour or per month based upon our configuration down here. Also note our configuration down here. Also note our configuration down here. Also note there's also a version for serverless. there's also a version for serverless. there's also a version for serverless. This is great for if you have a low This is great for if you have a low This is great for if you have a low usage usually but every once in a while usage usually but every once in a while usage usually but every once in a while you have a spike. that spike is going to you have a spike. that spike is going to you have a spike. that spike is going to cost you more, but the rest of the time cost you more, but the rest of the time cost you more, but the rest of the time you're paying the least amount. So that you're paying the least amount. So that you're paying the least amount. So that can be really great. Just be careful you can be really great. Just be careful you can be really great. Just be careful you don't have too many spikes, otherwise it don't have too many spikes, otherwise it don't have too many spikes, otherwise it gets very very expensive. So the other gets very very expensive. So the other gets very very expensive. So the other thing is if you're on AWS, there is a thing is if you're on AWS, there is a thing is if you're on AWS, there is a free tier. It's not on Azure or on uh free tier. It's not on Azure or on uh free tier. It's not on Azure or on uh Google, but it is on AWS. There's a free Google, but it is on AWS. There's a free Google, but it is on AWS. There's a free tier. It's it's just for testing tier. It's it's just for testing tier. It's it's just for testing purposes. It's not for really production purposes. It's not for really production purposes. It's not for really production use. I mean, you technically probably use. I mean, you technically probably use. I mean, you technically probably could, but it is restricted community could, but it is restricted community could, but it is restricted community license. And that's one more thing I license. And that's one more thing I license. And that's one more thing I want to point out. Um, is back in the want to point out. Um, is back in the want to point out. Um, is back in the licensing page down at the bottom, there licensing page down at the bottom, there licensing page down at the bottom, there is developer licenses, which are free. is developer licenses, which are free. is developer licenses, which are free. You just can't use them in production. You just can't use them in production. You just can't use them in production. There's a couple other restrictions, but There's a couple other restrictions, but There's a couple other restrictions, but that's the big one. And then also the that's the big one. And then also the that's the big one. And then also the community license, which is free as community license, which is free as community license, which is free as well. You can use it in production. It well. You can use it in production. It well. You can use it in production. It just requires you stay on the latest just requires you stay on the latest just requires you stay on the latest major version of Raven DB. And you can major version of Raven DB. And you can major version of Raven DB. And you can you're limited to 60 cores per customer you're limited to 60 cores per customer you're limited to 60 cores per customer entity. That's a core is a number of uh entity. That's a core is a number of uh entity. That's a core is a number of uh a part of a CPU.
-
a part of a CPU. a part of a CPU. So and the license is valid for one So and the license is valid for one So and the license is valid for one year, but you can renew it. So that's year, but you can renew it. So that's year, but you can renew it. So that's community license is typically for community license is typically for community license is typically for getting started in production before you getting started in production before you getting started in production before you move up to I guess more of a real move up to I guess more of a real move up to I guess more of a real license, more of a um a professional or license, more of a um a professional or license, more of a um a professional or enterprise license depending on your enterprise license depending on your enterprise license depending on your usage. Okay, that's Raven DB. Um the big usage. Okay, that's Raven DB. Um the big usage. Okay, that's Raven DB. Um the big one here though is Docs. stocks are one here though is Docs. stocks are one here though is Docs. stocks are great. Definitely dive right into these great. Definitely dive right into these great. Definitely dive right into these and learn more about well everything. and learn more about well everything. and learn more about well everything. But for us, what we're going to do is But for us, what we're going to do is But for us, what we're going to do is we're going to jump into code because I we're going to jump into code because I we're going to jump into code because I think that's important. But one last think that's important. But one last think that's important. But one last thing, we're going to write code thing, we're going to write code thing, we're going to write code manually. But if you're using codeex or manually. But if you're using codeex or manually. But if you're using codeex or or cloud code or others, you may be or cloud code or others, you may be or cloud code or others, you may be familiar with context 7. Um, but this is familiar with context 7. Um, but this is familiar with context 7. Um, but this is basically an MCP for documentation for a basically an MCP for documentation for a basically an MCP for documentation for a whole bunch of different tools. And whole bunch of different tools. And whole bunch of different tools. And Raven DB has official docs on here for Raven DB has official docs on here for Raven DB has official docs on here for working with Raven DB. Now, I would working with Raven DB. Now, I would working with Raven DB. Now, I would always encourage you to only use things always encourage you to only use things always encourage you to only use things from Context 7 that you trust. My from Context 7 that you trust. My from Context 7 that you trust. My personal opinion is if you're going to personal opinion is if you're going to personal opinion is if you're going to use Context 7 at all, then you should use Context 7 at all, then you should use Context 7 at all, then you should have a white list only, meaning it only have a white list only, meaning it only have a white list only, meaning it only works on the whitelisted items and not works on the whitelisted items and not works on the whitelisted items and not anything else. That way, nothing can anything else. That way, nothing can anything else. That way, nothing can slip in there accidentally. But there slip in there accidentally. But there slip in there accidentally. But there are documentation um entries for Raven are documentation um entries for Raven are documentation um entries for Raven DB and these go right to the docs. So, DB and these go right to the docs. So, DB and these go right to the docs. So, here's a repo of of the latest here's a repo of of the latest here's a repo of of the latest documentation. That just makes sure that documentation. That just makes sure that documentation. That just makes sure that your um your AI tool has the latest your um your AI tool has the latest your um your AI tool has the latest documentation and make sure it does the documentation and make sure it does the documentation and make sure it does the latest um most modern way of doing latest um most modern way of doing latest um most modern way of doing things. Okay, let's jump right into
-
things. Okay, let's jump right into things. Okay, let's jump right into code. Here I have, let's even get rid of code. Here I have, let's even get rid of code. Here I have, let's even get rid of this. This is a um a console app. It's this. This is a um a console app. It's this. This is a um a console app. It's .NET 10. This is going to be our our .NET 10. This is going to be our our .NET 10. This is going to be our our demo, our first demo for working with demo, our first demo for working with demo, our first demo for working with Raven DB. But you might say, well, Tim, Raven DB. But you might say, well, Tim, Raven DB. But you might say, well, Tim, how can you write C# code? But we don't how can you write C# code? But we don't how can you write C# code? But we don't have a database yet. You're right. Let's have a database yet. You're right. Let's have a database yet. You're right. Let's create one. create one. create one. And to do that, I'm going to And to do that, I'm going to And to do that, I'm going to run this Docker command. Now, I want to run this Docker command. Now, I want to run this Docker command. Now, I want to talk through this Docker command because talk through this Docker command because talk through this Docker command because I think it's important that you I think it's important that you I think it's important that you understand what's going on. If you're understand what's going on. If you're understand what's going on. If you're not familiar with Docker, I would really not familiar with Docker, I would really not familiar with Docker, I would really encourage you to get familiar with encourage you to get familiar with encourage you to get familiar with Docker. I have other videos on this, but Docker. I have other videos on this, but Docker. I have other videos on this, but essentially this is a way to get a essentially this is a way to get a essentially this is a way to get a database up and running on our machine database up and running on our machine database up and running on our machine in a way that we can use it as long as in a way that we can use it as long as in a way that we can use it as long as you want, but then we can also just you want, but then we can also just you want, but then we can also just destroy it and it's it's not going to destroy it and it's it's not going to destroy it and it's it's not going to hurt anything. It's not going to install hurt anything. It's not going to install hurt anything. It's not going to install DLS on our machine or have to have DLS on our machine or have to have DLS on our machine or have to have updates. This will work just as is. If updates. This will work just as is. If updates. This will work just as is. If you ever wanted a newer version, we just you ever wanted a newer version, we just you ever wanted a newer version, we just delete the current one and restart it. delete the current one and restart it. delete the current one and restart it. [snorts] So, this is going to run in a [snorts] So, this is going to run in a [snorts] So, this is going to run in a disconnected mode. a a a container.
-
disconnected mode. a a a container. disconnected mode. a a a container. We're going to call it Raven DB and We're going to call it Raven DB and We're going to call it Raven DB and we're going to restart the container we're going to restart the container we're going to restart the container unless stopped. So that means if we unless stopped. So that means if we unless stopped. So that means if we restart the PC, it will restart this restart the PC, it will restart this restart the PC, it will restart this Raven DB instance again. The only port Raven DB instance again. The only port Raven DB instance again. The only port we're mapping is 8080. You can change we're mapping is 8080. You can change we're mapping is 8080. You can change that if you're using port 8080 for that if you're using port 8080 for that if you're using port 8080 for something else. Um you can change to something else. Um you can change to something else. Um you can change to whatever port you want. And then there's whatever port you want. And then there's whatever port you want. And then there's a couple uh arguments. Setup mode equals a couple uh arguments. Setup mode equals a couple uh arguments. Setup mode equals none. The security unsecured access none. The security unsecured access none. The security unsecured access allowed equals private network. allowed equals private network. allowed equals private network. essentially saying, hey, on the private essentially saying, hey, on the private essentially saying, hey, on the private network, we can um access Raven DB network, we can um access Raven DB network, we can um access Raven DB without any type of security. That's so without any type of security. That's so without any type of security. That's so we don't have to install certificates we don't have to install certificates we don't have to install certificates for our dev box. And then this is just for our dev box. And then this is just for our dev box. And then this is just using the latest version of the Raven DB using the latest version of the Raven DB using the latest version of the Raven DB image. Now, one thing I'm not doing is image. Now, one thing I'm not doing is image. Now, one thing I'm not doing is I'm not including a uh a path or mapping I'm not including a uh a path or mapping I'm not including a uh a path or mapping for a a local drive. So all the data for a a local drive. So all the data for a a local drive. So all the data will be stored in this running container will be stored in this running container will be stored in this running container which means if I delete the container my which means if I delete the container my which means if I delete the container my data goes away and that might not be data goes away and that might not be data goes away and that might not be what you want if you want to have a long what you want if you want to have a long what you want if you want to have a long running uh dev database. So you might running uh dev database. So you might running uh dev database. So you might want to also have store the data in a want to also have store the data in a want to also have store the data in a place on this drive and then map that to place on this drive and then map that to place on this drive and then map that to your local PC. That might be something your local PC. That might be something your local PC. That might be something you want to add. Uh but for me I don't you want to add. Uh but for me I don't you want to add. Uh but for me I don't want that. I want everything to go away want that. I want everything to go away want that. I want everything to go away when I shut down this instance. So I hit when I shut down this instance. So I hit when I shut down this instance. So I hit enter. And if you have um downloaded enter. And if you have um downloaded enter. And if you have um downloaded already the um the database or the the
-
already the um the database or the the already the um the database or the the image then this is all you get. It's image then this is all you get. It's image then this is all you get. It's it's already installed. It's already it's already installed. It's already it's already installed. It's already running. That's it. It's all it took. running. That's it. It's all it took. running. That's it. It's all it took. It's now running. Which means we can It's now running. Which means we can It's now running. Which means we can come back over here to our browser. They come back over here to our browser. They come back over here to our browser. They can go to localhost can go to localhost can go to localhost colon 8080 colon 8080 colon 8080 and this is my raven db server. That's and this is my raven db server. That's and this is my raven db server. That's it. We're done. It's running. So let's it. We're done. It's running. So let's it. We're done. It's running. So let's take a peek at a couple of different take a peek at a couple of different take a peek at a couple of different things here. One down here. We can look things here. One down here. We can look things here. One down here. We can look at the license information. There's no at the license information. There's no at the license information. There's no license currently on this server. So license currently on this server. So license currently on this server. So it's not yet part of a cluster. It's in it's not yet part of a cluster. It's in it's not yet part of a cluster. It's in passive state and it's not licensed yet. passive state and it's not licensed yet. passive state and it's not licensed yet. So we can get a free license. I So we can get a free license. I So we can get a free license. I encourage you to click that button. I'm encourage you to click that button. I'm encourage you to click that button. I'm going to register my license. Notice going to register my license. Notice going to register my license. Notice down here it has comparison, etc. I'm down here it has comparison, etc. I'm down here it has comparison, etc. I'm going to register my license. I'm going going to register my license. I'm going going to register my license. I'm going to paste in I'm going to do it off to paste in I'm going to do it off to paste in I'm going to do it off camera, but I'll paste in my license. camera, but I'll paste in my license. camera, but I'll paste in my license. That's free. I have the free community That's free. I have the free community That's free. I have the free community or developer edition. or developer edition. or developer edition. Okay, I pasted in. Now, it says Okay, I pasted in. Now, it says Okay, I pasted in. Now, it says developer license, not for production developer license, not for production developer license, not for production use. So, that's totally fine. But now use. So, that's totally fine. But now use. So, that's totally fine. But now I'm licensed as a developer edition and I'm licensed as a developer edition and I'm licensed as a developer edition and I'm using the latest version and all the I'm using the latest version and all the I'm using the latest version and all the rest. Okay. So now we can come up here rest. Okay. So now we can come up here rest. Okay. So now we can come up here to databases. We have no databases. What to databases. We have no databases. What to databases. We have no databases. What does it take to create a database? Well, does it take to create a database? Well, does it take to create a database? Well, just saying demo DB.
-
just saying demo DB. just saying demo DB. There's a a database, right? We can There's a a database, right? We can There's a a database, right? We can quick create uh but let's go through quick create uh but let's go through quick create uh but let's go through next. [snorts] This is the idea of next. [snorts] This is the idea of next. [snorts] This is the idea of replication and sharding. Typically for replication and sharding. Typically for replication and sharding. Typically for a database you want to have replication a database you want to have replication a database you want to have replication number of nodes is probably a three um number of nodes is probably a three um number of nodes is probably a three um at least and then maybe sharding as well at least and then maybe sharding as well at least and then maybe sharding as well depending on if you need it. And again depending on if you need it. And again depending on if you need it. And again there's what is sharding right there there's what is sharding right there there's what is sharding right there which is great. Um so we're not going to which is great. Um so we're not going to which is great. Um so we're not going to do that because we're in development. do that because we're in development. do that because we're in development. This is just about creating something we This is just about creating something we This is just about creating something we can work with very easily. So we hit can work with very easily. So we hit can work with very easily. So we hit next and then the data directory. Again, next and then the data directory. Again, next and then the data directory. Again, if you were mapping your data to a a if you were mapping your data to a a if you were mapping your data to a a place on your PC through Docker, then place on your PC through Docker, then place on your PC through Docker, then you might want to come here and and pick you might want to come here and and pick you might want to come here and and pick where it goes. Otherwise, you keep the where it goes. Otherwise, you keep the where it goes. Otherwise, you keep the box checked and we'll put it in a a a box checked and we'll put it in a a a box checked and we'll put it in a a a space that's, you know, used to putting space that's, you know, used to putting space that's, you know, used to putting it. Hit finish. Done. We have a it. Hit finish. Done. We have a it. Hit finish. Done. We have a database. So, now I can look at this database. So, now I can look at this database. So, now I can look at this database. I can click on demo DB and it database. I can click on demo DB and it database. I can click on demo DB and it goes right up here at documents. goes right up here at documents. goes right up here at documents. Now, Raven DB is a NoSQL database, which Now, Raven DB is a NoSQL database, which Now, Raven DB is a NoSQL database, which means it's a document database. Now, it means it's a document database. Now, it means it's a document database. Now, it does more than that. It does multimodal, does more than that. It does multimodal, does more than that. It does multimodal, it does, you know, time and all the it does, you know, time and all the it does, you know, time and all the rest. Um, but rest. Um, but rest. Um, but a document means basically a JSON a document means basically a JSON a document means basically a JSON object. You can think of that way. It object. You can think of that way. It object. You can think of that way. It stores it differently, but that's stores it differently, but that's stores it differently, but that's basically what we've got going on here.
-
basically what we've got going on here. basically what we've got going on here. Right now, there's none. So you don't Right now, there's none. So you don't Right now, there's none. So you don't structure, you don't set up tables, you structure, you don't set up tables, you structure, you don't set up tables, you don't set up um you know the the don't set up um you know the the don't set up um you know the the structure of okay, these are the columns structure of okay, these are the columns structure of okay, these are the columns we're going to have. You do that through we're going to have. You do that through we're going to have. You do that through the objects you put in here. So right the objects you put in here. So right the objects you put in here. So right now there's no collections, which would now there's no collections, which would now there's no collections, which would be basically think of it kind of like a be basically think of it kind of like a be basically think of it kind of like a table um in SQL. There's no collections table um in SQL. There's no collections table um in SQL. There's no collections yet and there's no documents, which yet and there's no documents, which yet and there's no documents, which think of those documents as a row in a think of those documents as a row in a think of those documents as a row in a SQL table. So let's get started, I SQL table. So let's get started, I SQL table. So let's get started, I guess, right? Let's do it. So, we're guess, right? Let's do it. So, we're guess, right? Let's do it. So, we're gonna minimize this and come back over gonna minimize this and come back over gonna minimize this and come back over to our um to our program. We're going to to our um to our program. We're going to to our um to our program. We're going to go to dependencies. We're gonna say go to dependencies. We're gonna say go to dependencies. We're gonna say manage nougat packages and we're going manage nougat packages and we're going manage nougat packages and we're going to search for raven db to search for raven db to search for raven db and the first option option here is and the first option option here is and the first option option here is raven db.client. raven db.client. raven db.client. This is what we need to connect to a This is what we need to connect to a This is what we need to connect to a raven db database. So, we hit install, raven db database. So, we hit install, raven db database. So, we hit install, accept, accept, accept, done. All right. So now I can start done. All right. So now I can start done. All right. So now I can start connecting to the database. The first connecting to the database. The first connecting to the database. The first thing I need to do is set up a a store.
-
thing I need to do is set up a a store. thing I need to do is set up a a store. So using So using So using I document I document I document store which control dot to add a um a store which control dot to add a um a store which control dot to add a um a using directive for that which it's not using directive for that which it's not using directive for that which it's not doing. Um doing. Um doing. Um I don't know why. Oh, probably because I don't know why. Oh, probably because I don't know why. Oh, probably because it doesn't realize I'm not using a using it doesn't realize I'm not using a using it doesn't realize I'm not using a using directive here. Let's just type it out directive here. Let's just type it out directive here. Let's just type it out manually. using raven.client. Wow, I can spell right today. Right. Wow, I can spell right today. Right. Using raven.client.doccuments. And then we'll also just add this here And then we'll also just add this here since we're going to need it. Using since we're going to need it. Using since we're going to need it. Using raven.client.doccuments. Okay. So I document store store equals Okay. So I document store store equals new document store. So this the first thing we need to do is So this the first thing we need to do is create a document store. So this is create a document store. So this is create a document store. So this is something you do once. You don't do it a something you do once. You don't do it a something you do once. You don't do it a bunch of times throughout your bunch of times throughout your bunch of times throughout your application. This is once per lifetime application. This is once per lifetime application. This is once per lifetime of your application. So what goes into of your application. So what goes into of your application. So what goes into this? Uh it's very simple. We're going this? Uh it's very simple. We're going this? Uh it's very simple. We're going to have URLs to have URLs to have URLs and this is going to be an array. So and this is going to be an array. So and this is going to be an array. So let's just create an array and we'll say let's just create an array and we'll say let's just create an array and we'll say http http http colon back slashbacks slashlohost colon back slashbacks slashlohost colon back slashbacks slashlohost colon 8080. That's our database. If we colon 8080. That's our database. If we colon 8080. That's our database. If we had multiple nodes we're talking to
-
had multiple nodes we're talking to had multiple nodes we're talking to multiple uh URLs, we put multiple in multiple uh URLs, we put multiple in multiple uh URLs, we put multiple in here. And then what's our default here. And then what's our default here. And then what's our default database? database? database? This is going to be demob. Now notice I This is going to be demob. Now notice I This is going to be demob. Now notice I use all lowercase doesn't matter even use all lowercase doesn't matter even use all lowercase doesn't matter even though my database that I created I use though my database that I created I use though my database that I created I use capital D and capital DB it doesn't capital D and capital DB it doesn't capital D and capital DB it doesn't matter you can have all lowercase matter you can have all lowercase matter you can have all lowercase and then conventions and we're going to and then conventions and we're going to and then conventions and we're going to say no conventions say no conventions say no conventions cool so that's all we need for our store cool so that's all we need for our store cool so that's all we need for our store except for one last step which is store except for one last step which is store except for one last step which is store initialize now I want to say at this initialize now I want to say at this initialize now I want to say at this point that I am writing this code in point that I am writing this code in point that I am writing this code in line to show you how to do each step. line to show you how to do each step. line to show you how to do each step. However, we're going to go back through However, we're going to go back through However, we're going to go back through and redo this code so that it's more in and redo this code so that it's more in and redo this code so that it's more in line with what you would do in line with what you would do in line with what you would do in production. Okay, so this right here is production. Okay, so this right here is production. Okay, so this right here is demo code. I will make it better demo demo code. I will make it better demo demo code. I will make it better demo code for you after we learn all the code for you after we learn all the code for you after we learn all the different CRUD actions. Also note, you different CRUD actions. Also note, you different CRUD actions. Also note, you can get all the source code in a link can get all the source code in a link can get all the source code in a link down the description. All right, so down the description. All right, so down the description. All right, so we've initialized the store. This is not we've initialized the store. This is not we've initialized the store. This is not creating an open connection to the creating an open connection to the creating an open connection to the database. This is just setting up the database. This is just setting up the database. This is just setting up the fact that this is how you connect to the fact that this is how you connect to the fact that this is how you connect to the database. It's information. It's not a database. It's information. It's not a database. It's information. It's not a connect open connection. But we need to connect open connection. But we need to connect open connection. But we need to have this set up once. All right. Now, have this set up once. All right. Now, have this set up once. All right. Now, what we need to do is we need to create what we need to do is we need to create what we need to do is we need to create a new object. Let's control shift A and
-
a new object. Let's control shift A and a new object. Let's control shift A and we'll say uh let's go with user model. we'll say uh let's go with user model. we'll say uh let's go with user model. Let's go with user first. um are users. Let's go with user first. um are users. Let's go with user first. um are users. I I'll explain why in just a minute. Um I I'll explain why in just a minute. Um I I'll explain why in just a minute. Um but we're going to but we're going to but we're going to say name space is all we need. And then say name space is all we need. And then say name space is all we need. And then mark this as public. mark this as public. mark this as public. And I'm going to create three And I'm going to create three And I'm going to create three properties. properties. properties. The first one is string, a nullable The first one is string, a nullable The first one is string, a nullable string called ID. string called ID. string called ID. And then we're going to have a nullable And then we're going to have a nullable And then we're going to have a nullable string called first name. string called first name. string called first name. And then we're going to have a nullable And then we're going to have a nullable And then we're going to have a nullable string called last name. Really simple. string called last name. Really simple. string called last name. Really simple. Right now I called it users plural which Right now I called it users plural which Right now I called it users plural which is not what we do normally for uh a is not what we do normally for uh a is not what we do normally for uh a model. But I want to show you the reason model. But I want to show you the reason model. But I want to show you the reason why. So this is going to be a mapping why. So this is going to be a mapping why. So this is going to be a mapping thing when it comes to storing records. thing when it comes to storing records. thing when it comes to storing records. So I am going to add now a a a using So I am going to add now a a a using So I am going to add now a a a using which by the way these are two different which by the way these are two different which by the way these are two different ways of doing using. So this right here ways of doing using. So this right here ways of doing using. So this right here is just a shortcut. This is just saying is just a shortcut. This is just saying is just a shortcut. This is just saying hey instead of typing hey instead of typing hey instead of typing raven.client.document.id raven.client.document.id raven.client.document.id document store just type document store.
-
document store just type document store. document store just type document store. This right here is opening up a a kind This right here is opening up a a kind This right here is opening up a a kind of a loop. So what this is saying is hey of a loop. So what this is saying is hey of a loop. So what this is saying is hey I want you to open this store but at the I want you to open this store but at the I want you to open this store but at the end of this this area wherever you're in end of this this area wherever you're in end of this this area wherever you're in whatever the context is you're in in whatever the context is you're in in whatever the context is you're in in this case program.cs at the end of this this case program.cs at the end of this this case program.cs at the end of this I want you to close down store properly. I want you to close down store properly. I want you to close down store properly. So do the dispose method on that. We're So do the dispose method on that. We're So do the dispose method on that. We're going to do the same thing here for the going to do the same thing here for the going to do the same thing here for the Async document Async document Async document session called session. session called session. session called session. We're going to say equals store.open We're going to say equals store.open We're going to say equals store.open async session. async session. async session. Okay. So, we now have a a session open. Okay. So, we now have a a session open. Okay. So, we now have a a session open. Sessions are short. They're only open Sessions are short. They're only open Sessions are short. They're only open long enough to do long enough to do long enough to do one transactions worth of of things. So one transactions worth of of things. So one transactions worth of of things. So you really don't want to have sessions you really don't want to have sessions you really don't want to have sessions open long running. You want sessions to open long running. You want sessions to open long running. You want sessions to be really short, open for a little bit be really short, open for a little bit be really short, open for a little bit and closed back down. Now I'm going to and closed back down. Now I'm going to and closed back down. Now I'm going to leave a session open for the rest of leave a session open for the rest of leave a session open for the rest of program.cs. Again, this is the demo program.cs. Again, this is the demo program.cs. Again, this is the demo version. We're going to kind of redo version. We're going to kind of redo version. We're going to kind of redo this in a minute. [snorts] Okay. So what this in a minute. [snorts] Okay. So what this in a minute. [snorts] Okay. So what do you want to do with with your do you want to do with with your do you want to do with with your session? Well, I'm going to say await session? Well, I'm going to say await session? Well, I'm going to say await session session session store async store async store async and say new users and say new users and say new users and I'll say uh let's go with um uh
-
and I'll say uh let's go with um uh and I'll say uh let's go with um uh first name. first name. first name. Whoops. I have to have the uh using Whoops. I have to have the uh using Whoops. I have to have the uh using directive here. So using directive here. So using directive here. So using raven db demo because we're in raven db demo because we're in raven db demo because we're in programcs. So, first first name equals programcs. So, first first name equals programcs. So, first first name equals Tim and last name equals Corey. Now, I Tim and last name equals Corey. Now, I Tim and last name equals Corey. Now, I didn't add an ID. didn't add an ID. didn't add an ID. Okay, so this is going to store one new Okay, so this is going to store one new Okay, so this is going to store one new user in the users collection, user in the users collection, user in the users collection, but it's not doing it yet. We have to but it's not doing it yet. We have to but it's not doing it yet. We have to say await session.save say await session.save say await session.save changes async. changes async. changes async. So what this does is we first create a So what this does is we first create a So what this does is we first create a connection to the store. Doesn't connection to the store. Doesn't connection to the store. Doesn't actually keep an open line to the actually keep an open line to the actually keep an open line to the database. It just has the the store database. It just has the the store database. It just has the the store being um set up. And then we have the being um set up. And then we have the being um set up. And then we have the session which opens a session but we session which opens a session but we session which opens a session but we still don't have a long running open still don't have a long running open still don't have a long running open connection. This is where we actually do connection. This is where we actually do connection. This is where we actually do our connection. So this right here is our connection. So this right here is our connection. So this right here is basically queuing up changes and then basically queuing up changes and then basically queuing up changes and then right here we save those changes. That's right here we save those changes. That's right here we save those changes. That's where the actual data gets transmitted where the actual data gets transmitted where the actual data gets transmitted across the wire to our database.
-
across the wire to our database. across the wire to our database. So just to be clear right here we open a So just to be clear right here we open a So just to be clear right here we open a brief connection to the database just to brief connection to the database just to brief connection to the database just to set some things up but it's not a long set some things up but it's not a long set some things up but it's not a long running connection. Then here we don't running connection. Then here we don't running connection. Then here we don't even do that. We're just waiting here. even do that. We're just waiting here. even do that. We're just waiting here. no connection. It's only here that we no connection. It's only here that we no connection. It's only here that we actually open up that connection, talk actually open up that connection, talk actually open up that connection, talk to the database and then close back to the database and then close back to the database and then close back down. So right now we have created an down. So right now we have created an down. So right now we have created an insert statement essentially what we're insert statement essentially what we're insert statement essentially what we're doing here. So we've taken a model which doing here. So we've taken a model which doing here. So we've taken a model which I created in line and we we're going to I created in line and we we're going to I created in line and we we're going to store it async and this is where we store it async and this is where we store it async and this is where we actually save it. Let's just run this as actually save it. Let's just run this as actually save it. Let's just run this as is. So we run the applications should is. So we run the applications should is. So we run the applications should pop up. It should be done. It's done. So pop up. It should be done. It's done. So pop up. It should be done. It's done. So now let's go over to our database. And now let's go over to our database. And now let's go over to our database. And if we come over here to documents again, if we come over here to documents again, if we come over here to documents again, we'll see users slash1-. we'll see users slash1-. we'll see users slash1-. We also have a collection down here We also have a collection down here We also have a collection down here called users. And notice first name Tim, called users. And notice first name Tim, called users. And notice first name Tim, last name Corey. So if we click this last name Corey. So if we click this last name Corey. So if we click this here is the the the document that we here is the the the document that we here is the the the document that we just inserted. We have first name and just inserted. We have first name and just inserted. We have first name and last name. Notice there are other last name. Notice there are other last name. Notice there are other things. The metadata uh it's collection things. The metadata uh it's collection things. The metadata uh it's collection users and the CLR type is um Raven DB users and the CLR type is um Raven DB users and the CLR type is um Raven DB demo users from Raven DB demo. So we can demo users from Raven DB demo. So we can demo users from Raven DB demo. So we can just ignore that as information we don't just ignore that as information we don't just ignore that as information we don't need to worry about because it's grayed need to worry about because it's grayed need to worry about because it's grayed out showing us that it's just metadata out showing us that it's just metadata out showing us that it's just metadata about the object. But this is the data
-
about the object. But this is the data about the object. But this is the data we sent to our our user. Notice there's we sent to our our user. Notice there's we sent to our our user. Notice there's no ID that that's up here and this can no ID that that's up here and this can no ID that that's up here and this can be used to identify our user. And notice be used to identify our user. And notice be used to identify our user. And notice the the convention here users slash one- the the convention here users slash one- the the convention here users slash one- A. And what that's saying is this is the A. And what that's saying is this is the A. And what that's saying is this is the first ID in the users collection. And first ID in the users collection. And first ID in the users collection. And that's it's on uh node A. So that's that's it's on uh node A. So that's that's it's on uh node A. So that's going to be the the structure for how going to be the the structure for how going to be the the structure for how you get ids. It's not kind of the same you get ids. It's not kind of the same you get ids. It's not kind of the same as what you might see in other places as what you might see in other places as what you might see in other places where it might be a gooid which you can where it might be a gooid which you can where it might be a gooid which you can do if you want. And you can also specify do if you want. And you can also specify do if you want. And you can also specify your own. So let's just do that real your own. So let's just do that real your own. So let's just do that real quick. I'm going to comment out let's quick. I'm going to comment out let's quick. I'm going to comment out let's control D here first and duplicate this. control D here first and duplicate this. control D here first and duplicate this. And comment out this one. Actually I'm And comment out this one. Actually I'm And comment out this one. Actually I'm going to do this twice. So duplicate going to do this twice. So duplicate going to do this twice. So duplicate again. So let's do why not sue store again. So let's do why not sue store again. So let's do why not sue store but we're going to do sue a bit but we're going to do sue a bit but we're going to do sue a bit different. Uh we're going to say ID different. Uh we're going to say ID different. Uh we're going to say ID equals and let's put a uh comma here. So equals and let's put a uh comma here. So equals and let's put a uh comma here. So instead of saying um we want to have an instead of saying um we want to have an instead of saying um we want to have an ID that's just you know whatever we're ID that's just you know whatever we're ID that's just you know whatever we're going to say uh users and then I'm going going to say uh users and then I'm going going to say uh users and then I'm going to say pipe character.
-
to say pipe character. to say pipe character. What this will do is it will generate a What this will do is it will generate a What this will do is it will generate a a number that's going to be so it's a number that's going to be so it's a number that's going to be so it's going to say users slash not pipe slash going to say users slash not pipe slash going to say users slash not pipe slash and then a number not one a it's going and then a number not one a it's going and then a number not one a it's going to say like two. [snorts] So this just to say like two. [snorts] So this just to say like two. [snorts] So this just says hey I want you use an ID um after says hey I want you use an ID um after says hey I want you use an ID um after the slash or in place of the slash. So, the slash or in place of the slash. So, the slash or in place of the slash. So, the last one, let's do um how about uh the last one, let's do um how about uh the last one, let's do um how about uh let's stick with Tim, but last name of let's stick with Tim, but last name of let's stick with Tim, but last name of Smith. Smith. Smith. And again, I'm going to put an ID here, And again, I'm going to put an ID here, And again, I'm going to put an ID here, but this time I'm going to say, you know but this time I'm going to say, you know but this time I'm going to say, you know what? I actually want it to be uh T what? I actually want it to be uh T what? I actually want it to be uh T Smith uh 85235. Okay, that's the idea I want to use. Okay, that's the idea I want to use. Cool. Let's run this again. Cool. Let's run this again. Cool. Let's run this again. All right, we're done. So let's go back All right, we're done. So let's go back All right, we're done. So let's go back to our database. Go back to our user to our database. Go back to our user to our database. Go back to our user collection. Notice we now have user collection. Notice we now have user collection. Notice we now have user slash one because 1A is different. So slash one because 1A is different. So slash one because 1A is different. So slash1 that's Sue Storm. And if we come slash1 that's Sue Storm. And if we come slash1 that's Sue Storm. And if we come back here, we also have T Smith 85235 back here, we also have T Smith 85235 back here, we also have T Smith 85235 which is the ID of Tim Smith in this which is the ID of Tim Smith in this which is the ID of Tim Smith in this collection.
-
collection. collection. So you get to choose. If you want to put So you get to choose. If you want to put So you get to choose. If you want to put a good here, you can generate a new a good here, you can generate a new a good here, you can generate a new GOID. Not a problem. Um you can do GOID. Not a problem. Um you can do GOID. Not a problem. Um you can do whatever you want for the ID but just whatever you want for the ID but just whatever you want for the ID but just note that um if you don't specify note that um if you don't specify note that um if you don't specify anything it uses this convention. If you anything it uses this convention. If you anything it uses this convention. If you specify the collection name in a pipe specify the collection name in a pipe specify the collection name in a pipe character it uses just a numeric character it uses just a numeric character it uses just a numeric designator after that. Um also note that designator after that. Um also note that designator after that. Um also note that I kind of glossed over this but if you I kind of glossed over this but if you I kind of glossed over this but if you see in documents there's four documents see in documents there's four documents see in documents there's four documents even though we've created three. One's even though we've created three. One's even though we've created three. One's called raven/hy low users um seem to called raven/hy low users um seem to called raven/hy low users um seem to indicate that it has something to do indicate that it has something to do indicate that it has something to do with the user collection. If we click on with the user collection. If we click on with the user collection. If we click on this, you'll see that max of one. Um, this, you'll see that max of one. Um, this, you'll see that max of one. Um, what this is doing is that since we are what this is doing is that since we are what this is doing is that since we are generating documents with an ID number, generating documents with an ID number, generating documents with an ID number, um, that what it's doing is it's it's um, that what it's doing is it's it's um, that what it's doing is it's it's keeping track of that. So, it knows what keeping track of that. So, it knows what keeping track of that. So, it knows what the next document number should be. Um, the next document number should be. Um, the next document number should be. Um, you don't have to worry about that. It's you don't have to worry about that. It's you don't have to worry about that. It's when it says at system just means ignore when it says at system just means ignore when it says at system just means ignore me. Leave it alone. me. Leave it alone. me. Leave it alone. Okay. So, now notice it created the Okay. So, now notice it created the Okay. So, now notice it created the collection called users. Where did I collection called users. Where did I collection called users. Where did I specify that in my code? Well, I didn't.
-
specify that in my code? Well, I didn't. specify that in my code? Well, I didn't. I just said, "Hey, store this document." I just said, "Hey, store this document." I just said, "Hey, store this document." But what it did is it looked at the But what it did is it looked at the But what it did is it looked at the model and said, "Oh, users. Therefore, model and said, "Oh, users. Therefore, model and said, "Oh, users. Therefore, you you want that to be in the users you you want that to be in the users you you want that to be in the users collection, collection, collection, which yeah, makes sense, but at the same which yeah, makes sense, but at the same which yeah, makes sense, but at the same time, it doesn't because it depends on time, it doesn't because it depends on time, it doesn't because it depends on how you want to structure things, right? how you want to structure things, right? how you want to structure things, right? So, I might say, you know what, I hate So, I might say, you know what, I hate So, I might say, you know what, I hate this. I don't want to call it user. I this. I don't want to call it user. I this. I don't want to call it user. I want to call this the the person model. want to call this the the person model. want to call this the the person model. And let's just rename everywhere to And let's just rename everywhere to And let's just rename everywhere to person model. And let's even do it here. So now person model I can undo this by So now person model I can undo this by the way. And the way. And the way. And because it's commented it didn't it because it's commented it didn't it because it's commented it didn't it didn't rename it here. So this is going didn't rename it here. So this is going didn't rename it here. So this is going to be the same thing. If I run this app to be the same thing. If I run this app to be the same thing. If I run this app again, it should be done pretty quick. again, it should be done pretty quick. again, it should be done pretty quick. Um, it goes, "Hey, wait. Um, I've got a Um, it goes, "Hey, wait. Um, I've got a Um, it goes, "Hey, wait. Um, I've got a problem here. Um, problem here. Um, problem here. Um, this T-smith 85235 this T-smith 85235 this T-smith 85235 from users to person model isn't from users to person model isn't from users to person model isn't supported. We got a problem." Um, that's supported. We got a problem." Um, that's supported. We got a problem." Um, that's because it's trying to save this third because it's trying to save this third because it's trying to save this third object and it's the same ID is another object and it's the same ID is another object and it's the same ID is another one. This is why typically we see the um one. This is why typically we see the um one. This is why typically we see the um the name of the collection and then a the name of the collection and then a the name of the collection and then a slash which here's a problem too. So slash which here's a problem too. So slash which here's a problem too. So let's say person model. So let's call let's say person model. So let's call let's say person model. So let's call this um six, right? Which is why you this um six, right? Which is why you this um six, right? Which is why you don't want me doing this manually.
-
don't want me doing this manually. don't want me doing this manually. So uh we might even want to say you know So uh we might even want to say you know So uh we might even want to say you know what instead of doing this let's do uh what instead of doing this let's do uh what instead of doing this let's do uh was it gooid dot new to um new gooid uh was it gooid dot new to um new gooid uh was it gooid dot new to um new gooid uh to string. So it'll create a gooid right to string. So it'll create a gooid right to string. So it'll create a gooid right in line. That'll solve that problem. in line. That'll solve that problem. in line. That'll solve that problem. Okay. So now if you come back over here Okay. So now if you come back over here Okay. So now if you come back over here first and look at our collections. So first and look at our collections. So first and look at our collections. So all documents. Notice that there we all documents. Notice that there we all documents. Notice that there we don't have another document, right? We don't have another document, right? We don't have another document, right? We don't have a document for um we have don't have a document for um we have don't have a document for um we have person models. We have this hyo um which person models. We have this hyo um which person models. We have this hyo um which says one, but we don't have any records says one, but we don't have any records says one, but we don't have any records for the person model nor we have a for the person model nor we have a for the person model nor we have a person model collection. And the reason person model collection. And the reason person model collection. And the reason why is because of how this save changes why is because of how this save changes why is because of how this save changes async works. Save changes async. What async works. Save changes async. What async works. Save changes async. What it's going to do is treat this whole it's going to do is treat this whole it's going to do is treat this whole thing as a transaction. If you're not thing as a transaction. If you're not thing as a transaction. If you're not familiar in database lingo, what that familiar in database lingo, what that familiar in database lingo, what that means is that it all succeeds or all means is that it all succeeds or all means is that it all succeeds or all fails. So if you write the first two fails. So if you write the first two fails. So if you write the first two records, but the third record um causes records, but the third record um causes records, but the third record um causes a problem like we saw, then it's going a problem like we saw, then it's going a problem like we saw, then it's going to roll back those other changes. That to roll back those other changes. That to roll back those other changes. That way, for example, if you were saying, way, for example, if you were saying, way, for example, if you were saying, "Take $100 out of my checking account "Take $100 out of my checking account "Take $100 out of my checking account and put it in a savings," that's be two and put it in a savings," that's be two and put it in a savings," that's be two actions. But if you took the $100 out of actions. But if you took the $100 out of actions. But if you took the $100 out of checking, but didn't yet put it in a checking, but didn't yet put it in a checking, but didn't yet put it in a savings and the thing crashed. Well, now savings and the thing crashed. Well, now savings and the thing crashed. Well, now your $100 is missing. That wouldn't be your $100 is missing. That wouldn't be your $100 is missing. That wouldn't be okay. That's why you have transactions okay. That's why you have transactions okay. That's why you have transactions that say, "No, the whole thing has to that say, "No, the whole thing has to that say, "No, the whole thing has to work or the whole thing has to fail."
-
work or the whole thing has to fail." work or the whole thing has to fail." This is part of the acid um test for This is part of the acid um test for This is part of the acid um test for databases and it's one that Raven DB databases and it's one that Raven DB databases and it's one that Raven DB supports. supports. supports. So now we've fixed all of that. We can So now we've fixed all of that. We can So now we've fixed all of that. We can run this again and it should work. It run this again and it should work. It run this again and it should work. It does. So now you can come back over does. So now you can come back over does. So now you can come back over here. We can see have person models here. We can see have person models here. We can see have person models collection. Notice we have our GID here collection. Notice we have our GID here collection. Notice we have our GID here for Tim Smith. We have person model one for Tim Smith. We have person model one for Tim Smith. We have person model one for Sue and person model models because for Sue and person model models because for Sue and person model models because I spelled uh this model and this one is I spelled uh this model and this one is I spelled uh this model and this one is models um as 2A. So models um as 2A. So models um as 2A. So this is a bit better. But now it says this is a bit better. But now it says this is a bit better. But now it says person models and that's not a great person models and that's not a great person models and that's not a great collection any name. I want to have I collection any name. I want to have I collection any name. I want to have I want to have it say people or I want to want to have it say people or I want to want to have it say people or I want to say users. So what do we do about this? say users. So what do we do about this? say users. So what do we do about this? Well, there's a way to make this better. Well, there's a way to make this better. Well, there's a way to make this better. By the way, you can come through and By the way, you can come through and By the way, you can come through and just say, you know what, delete just say, you know what, delete just say, you know what, delete everything. Or you can come to everything. Or you can come to everything. Or you can come to collections and delete the collection collections and delete the collection collections and delete the collection and so on. Um I'll show you how to and so on. Um I'll show you how to and so on. Um I'll show you how to delete in a little bit. But um this is delete in a little bit. But um this is delete in a little bit. But um this is for testing, right? You can create a for testing, right? You can create a for testing, right? You can create a lots of test data. So right up here, lots of test data. So right up here, lots of test data. So right up here, conventions, I'm going to show you a conventions, I'm going to show you a conventions, I'm going to show you a convention that will make life a little convention that will make life a little convention that will make life a little bit easier for you if you would like to bit easier for you if you would like to bit easier for you if you would like to use it. So let's bring us down to a new use it. So let's bring us down to a new use it. So let's bring us down to a new line.
-
line. line. And in here, I'm going to say find And in here, I'm going to say find And in here, I'm going to say find collection name. collection name. collection name. Um I'm going to say type and then the Um I'm going to say type and then the Um I'm going to say type and then the arrow. And then we're going to have arrow. And then we're going to have arrow. And then we're going to have curly braces. So in here, what we're curly braces. So in here, what we're curly braces. So in here, what we're going to do is we're going to say varame going to do is we're going to say varame going to do is we're going to say varame equals type.name. that name. And what equals type.name. that name. And what equals type.name. that name. And what that's going to do is get the type of that's going to do is get the type of that's going to do is get the type of the object you're storing in your the object you're storing in your the object you're storing in your collection or using with your collection or using with your collection or using with your collection. So in this case, person collection. So in this case, person collection. So in this case, person model. And that's going to be right model. And that's going to be right model. And that's going to be right here. Person model. We're going to put here. Person model. We're going to put here. Person model. We're going to put that into name. And now we're gonna do that into name. And now we're gonna do that into name. And now we're gonna do is we're gonna say for each and we're is we're gonna say for each and we're is we're gonna say for each and we're gonna say var suffix gonna say var suffix gonna say var suffix in new in new in new um and we'll say um um and we'll say um um and we'll say um actually I can just say do this way in actually I can just say do this way in actually I can just say do this way in record record record and model like so. and model like so. and model like so. So, what this is doing is we're going to So, what this is doing is we're going to So, what this is doing is we're going to loop over these two. Um, no target type, loop over these two. Um, no target type, loop over these two. Um, no target type, of course not.
-
of course not. of course not. So, what we'll do instead is just do I So, what we'll do instead is just do I So, what we'll do instead is just do I was going to do in the first place. Uh, was going to do in the first place. Uh, was going to do in the first place. Uh, new and then close that out and make new and then close that out and make new and then close that out and make these curly braces. There we go. So, what this is going to There we go. So, what this is going to do is it's going to loop over these two do is it's going to loop over these two do is it's going to loop over these two options right now. We can have more options right now. We can have more options right now. We can have more later. Um, but there's two options and later. Um, but there's two options and later. Um, but there's two options and say, hey, if it ends in record or if it say, hey, if it ends in record or if it say, hey, if it ends in record or if it ends in model, here's what I want you to ends in model, here's what I want you to ends in model, here's what I want you to do. I want you to say name equals name do. I want you to say name equals name do. I want you to say name equals name and then we're going to say dot dot and and then we're going to say dot dot and and then we're going to say dot dot and the carrot the carrot the carrot and we're going to say suffix.length. And what this will do is we're going to And what this will do is we're going to say break, meaning we're we're done say break, meaning we're we're done say break, meaning we're we're done loop. What it's going to do is say right loop. What it's going to do is say right loop. What it's going to do is say right now we have person model. Well, if we now we have person model. Well, if we now we have person model. Well, if we find model in the name, which we do, find model in the name, which we do, find model in the name, which we do, then we're going to trim off the model. then we're going to trim off the model. then we're going to trim off the model. Okay? So, we're trimming off all the Okay? So, we're trimming off all the Okay? So, we're trimming off all the characters for the length of in this characters for the length of in this characters for the length of in this case five. The last five characters get case five. The last five characters get case five. The last five characters get trimmed off, which means it's going to trimmed off, which means it's going to trimmed off, which means it's going to say person in here instead of saying say person in here instead of saying say person in here instead of saying person model. If it's person record, it person model. If it's person record, it person model. If it's person record, it do the same thing. So, whatever your do the same thing. So, whatever your do the same thing. So, whatever your your default extensions are that you use your default extensions are that you use your default extensions are that you use for your your models, if you said DTO, for your your models, if you said DTO, for your your models, if you said DTO, you throw DTO in here as well. Now, now you throw DTO in here as well. Now, now you throw DTO in here as well. Now, now that I have that, what I'm going to do that I have that, what I'm going to do that I have that, what I'm going to do is I'm going to say uh name equals name
-
is I'm going to say uh name equals name is I'm going to say uh name equals name switch switch switch and then I'm going to say person. So, if and then I'm going to say person. So, if and then I'm going to say person. So, if it says person, so person model is now it says person, so person model is now it says person, so person model is now turned into a person. If it says person, turned into a person. If it says person, turned into a person. If it says person, I want you to say people I want you to say people I want you to say people otherwise so that's the discard otherwise so that's the discard otherwise so that's the discard character meaning anything else I want character meaning anything else I want character meaning anything else I want you to say name plus s you to say name plus s you to say name plus s and I want you to return name. So what and I want you to return name. So what and I want you to return name. So what this is doing in this find collection this is doing in this find collection this is doing in this find collection name is that we have a convention now name is that we have a convention now name is that we have a convention now that if you set pass in person model that if you set pass in person model that if you set pass in person model it's going to say okay trim off model it's going to say okay trim off model it's going to say okay trim off model and since it's person I want you to and since it's person I want you to and since it's person I want you to translate to people that's the plural translate to people that's the plural translate to people that's the plural version of person and return people version of person and return people version of person and return people that's a people collection. Now what if that's a people collection. Now what if that's a people collection. Now what if you had a user model? Well it cut off you had a user model? Well it cut off you had a user model? Well it cut off model and so it's now just user and user model and so it's now just user and user model and so it's now just user and user is not person. So it's going to say okay is not person. So it's going to say okay is not person. So it's going to say okay just put s the end. So now it's users. just put s the end. So now it's users. just put s the end. So now it's users. So those are the collection names. So So those are the collection names. So So those are the collection names. So this right here makes things a little this right here makes things a little this right here makes things a little easier for making sure your your easier for making sure your your easier for making sure your your conventions match. If you have other conventions match. If you have other conventions match. If you have other pluralizers to do, you can do that right pluralizers to do, you can do that right pluralizers to do, you can do that right here. So um if there's other thing other here. So um if there's other thing other here. So um if there's other thing other ways of, you know, other models you find ways of, you know, other models you find ways of, you know, other models you find that don't just pluralize by putting an that don't just pluralize by putting an that don't just pluralize by putting an s at the end, you can modify them here.
-
s at the end, you can modify them here. s at the end, you can modify them here. So without changing anything else except So without changing anything else except So without changing anything else except for this fine collection, let's run this for this fine collection, let's run this for this fine collection, let's run this again. again. again. We're done. We can come back to our We're done. We can come back to our We're done. We can come back to our object and notice. Wow. Um I I'm object and notice. Wow. Um I I'm object and notice. Wow. Um I I'm I have a I have a problem. Uh because it I have a I have a problem. Uh because it I have a I have a problem. Uh because it looks like I I'm missing one character. looks like I I'm missing one character. looks like I I'm missing one character. Ah, I see the problem. So I do this Ah, I see the problem. So I do this Ah, I see the problem. So I do this every time. And so it's going to look every time. And so it's going to look every time. And so it's going to look through record and say, "Okay, on the through record and say, "Okay, on the through record and say, "Okay, on the record for each, we're going to just record for each, we're going to just record for each, we're going to just trim off record." That's not the That's trim off record." That's not the That's trim off record." That's not the That's not what we're supposed to do. Let's cut not what we're supposed to do. Let's cut not what we're supposed to do. Let's cut this out real briefly and say if this out real briefly and say if this out real briefly and say if name.end ends with suffix. That's much name.end ends with suffix. That's much name.end ends with suffix. That's much better. Knew I missed something. So if better. Knew I missed something. So if better. Knew I missed something. So if it ends with the suffix record, then it ends with the suffix record, then it ends with the suffix record, then trim it off. If it ends with model, trim trim it off. If it ends with model, trim trim it off. If it ends with model, trim it off. The cool thing is again demo. We it off. The cool thing is again demo. We it off. The cool thing is again demo. We can just run this again. And what it's can just run this again. And what it's can just run this again. And what it's going to do is now we have the personos going to do is now we have the personos going to do is now we have the personos collection, but we also have the people collection, but we also have the people collection, but we also have the people collection now. And there we go. Now collection now. And there we go. Now collection now. And there we go. Now notice person model slash3. That's notice person model slash3. That's notice person model slash3. That's because we are manually setting what the because we are manually setting what the because we are manually setting what the um the collection name is which is um the collection name is which is um the collection name is which is probably not the best idea to hardcode probably not the best idea to hardcode probably not the best idea to hardcode that. Um but we'd say uh this is the that. Um but we'd say uh this is the that. Um but we'd say uh this is the people like so. And now that should people like so. And now that should people like so. And now that should insert more properly. Let's run this insert more properly. Let's run this insert more properly. Let's run this again.
-
again. again. And it's going to now have six records And it's going to now have six records And it's going to now have six records which are basically three duplicates. which are basically three duplicates. which are basically three duplicates. Um, it does. Uh, let's hit the refresh Um, it does. Uh, let's hit the refresh Um, it does. Uh, let's hit the refresh button here. And now we have our button here. And now we have our button here. And now we have our information. But now Soustorm has people information. But now Soustorm has people information. But now Soustorm has people slash one. So you can do our IDs a slash one. So you can do our IDs a slash one. So you can do our IDs a number of different ways. I don't number of different ways. I don't number of different ways. I don't recommend that you have ids of different recommend that you have ids of different recommend that you have ids of different structures. structures. structures. Personally, just don't include the ID Personally, just don't include the ID Personally, just don't include the ID and it will take care of it for you. It and it will take care of it for you. It and it will take care of it for you. It will handle um setting things up will handle um setting things up will handle um setting things up properly. properly. properly. That's what my [clears throat] That's what my [clears throat] That's what my [clears throat] recommendation is for you. So now we recommendation is for you. So now we recommendation is for you. So now we have data going in. We can, you know, have data going in. We can, you know, have data going in. We can, you know, make these better if we want by cleaning make these better if we want by cleaning make these better if we want by cleaning up how they work. But let's move on to up how they work. But let's move on to up how they work. But let's move on to different actions. different actions. different actions. So let's comment out all of this because So let's comment out all of this because So let's comment out all of this because I want you to have the code, but we I want you to have the code, but we I want you to have the code, but we don't want to keep inserting every time don't want to keep inserting every time don't want to keep inserting every time you run this. And what I'm going to do you run this. And what I'm going to do you run this. And what I'm going to do is I'm gonna say let's grab all of the is I'm gonna say let's grab all of the is I'm gonna say let's grab all of the users. And let's actually put up here at users. And let's actually put up here at users. And let's actually put up here at the top. Um, we're going to do a a list the top. Um, we're going to do a a list the top. Um, we're going to do a a list of of person model of of person model of of person model and we're going to call it people.
-
and we're going to call it people. and we're going to call it people. And then down here we can initialize And then down here we can initialize And then down here we can initialize that list by saying um await that list by saying um await that list by saying um await and we'll say actually no I'm sorry and we'll say actually no I'm sorry and we'll say actually no I'm sorry people equals await people equals await people equals await session session session query session. session. Ah I commented out session up here. Ah I commented out session up here. Ah I commented out session up here. [snorts] I was gonna say why is that not [snorts] I was gonna say why is that not [snorts] I was gonna say why is that not there? Uh session.query query and we're there? Uh session.query query and we're there? Uh session.query query and we're going to query a person model and we're going to query a person model and we're going to query a person model and we're going to say going to say going to say uh to list async uh to list async uh to list async like so. So it's an a we're doing like so. So it's an a we're doing like so. So it's an a we're doing everything asynchronously. I just everything asynchronously. I just everything asynchronously. I just encourage you always do asynchronous encourage you always do asynchronous encourage you always do asynchronous when talking to a database. It just when talking to a database. It just when talking to a database. It just we don't really need to have synchronous we don't really need to have synchronous we don't really need to have synchronous anymore talking databases. There's no anymore talking databases. There's no anymore talking databases. There's no reason to lock our our application up. reason to lock our our application up. reason to lock our our application up. So this is going to get every person in So this is going to get every person in So this is going to get every person in a list. So let's do a for each just so a list. So let's do a for each just so a list. So let's do a for each just so we can see it. So for each p in people we can see it. So for each p in people we can see it. So for each p in people we're say console right line and let's we're say console right line and let's we're say console right line and let's do uh string interpolation and say p do uh string interpolation and say p do uh string interpolation and say p first name and then space past first name and then space past first name and then space past name.
-
name. name. So nothing crazy. We won't put the ids So nothing crazy. We won't put the ids So nothing crazy. We won't put the ids on here. We'll throw a list of all the on here. We'll throw a list of all the on here. We'll throw a list of all the people just we can see that yes it's people just we can see that yes it's people just we can see that yes it's working. There you go. Tim, Corey, Sue, working. There you go. Tim, Corey, Sue, working. There you go. Tim, Corey, Sue, Storm, Tim Smith, Tim, Corey, Soustorm, Storm, Tim Smith, Tim, Corey, Soustorm, Storm, Tim Smith, Tim, Corey, Soustorm, Tim Smith. If you have those, we did it Tim Smith. If you have those, we did it Tim Smith. If you have those, we did it twice. So, there's six records total. twice. So, there's six records total. twice. So, there's six records total. There we go. That just read all the There we go. That just read all the There we go. That just read all the people from the list. But you may say, people from the list. But you may say, people from the list. But you may say, well, yeah, that's great, Tim, but we well, yeah, that's great, Tim, but we well, yeah, that's great, Tim, but we don't typically just query every record don't typically just query every record don't typically just query every record in a um a collection. [clears throat] in a um a collection. [clears throat] in a um a collection. [clears throat] That's correct. So, let's make this a That's correct. So, let's make this a That's correct. So, let's make this a bit more realistic. So, let's put this bit more realistic. So, let's put this bit more realistic. So, let's put this on a new line and we're going to say, on a new line and we're going to say, on a new line and we're going to say, you know what, before this, we're going you know what, before this, we're going you know what, before this, we're going to use link syntax and say where and to use link syntax and say where and to use link syntax and say where and we'll say um x arrow x dot uh first name we'll say um x arrow x dot uh first name we'll say um x arrow x dot uh first name equals Tim. equals Tim. equals Tim. So, let's just run this. And there we So, let's just run this. And there we So, let's just run this. And there we go. Tim Corey, Tim Smith, Tim Corey, Tim go. Tim Corey, Tim Smith, Tim Corey, Tim go. Tim Corey, Tim Smith, Tim Corey, Tim Smith. So, we've now done a query based Smith. So, we've now done a query based Smith. So, we've now done a query based upon link syntax, which link syntax upon link syntax, which link syntax upon link syntax, which link syntax works just great. Um, you can also use works just great. Um, you can also use works just great. Um, you can also use their own uh language, but this is super their own uh language, but this is super their own uh language, but this is super simple to do. It's very um C friendly.
-
simple to do. It's very um C friendly. simple to do. It's very um C friendly. By the way, I haven't mentioned By the way, I haven't mentioned By the way, I haven't mentioned [clears throat] this, but Raven DB and [clears throat] this, but Raven DB and [clears throat] this, but Raven DB and the other tooling mostly all just C# the other tooling mostly all just C# the other tooling mostly all just C# code. Raven DB was built using C innet. code. Raven DB was built using C innet. code. Raven DB was built using C innet. So, it really is C friendly because the So, it really is C friendly because the So, it really is C friendly because the fact that that's where its roots are fact that that's where its roots are fact that that's where its roots are from. Okay. So notice I also didn't have from. Okay. So notice I also didn't have from. Okay. So notice I also didn't have to do a save changes async. I'm not to do a save changes async. I'm not to do a save changes async. I'm not doing any write commands. I'm not doing doing any write commands. I'm not doing doing any write commands. I'm not doing a read command. So this right here, this a read command. So this right here, this a read command. So this right here, this to list async is where the actual call to list async is where the actual call to list async is where the actual call gets made. Now you could lazy call this gets made. Now you could lazy call this gets made. Now you could lazy call this if you wanted to. Um that's a bit out of if you wanted to. Um that's a bit out of if you wanted to. Um that's a bit out of the scope for this video, but just note the scope for this video, but just note the scope for this video, but just note that you want to save the number of that you want to save the number of that you want to save the number of actions you do on a session, which we'll actions you do on a session, which we'll actions you do on a session, which we'll talk about in just a minute. But this talk about in just a minute. But this talk about in just a minute. But this just did a query and gave me back all just did a query and gave me back all just did a query and gave me back all the records that started or that had a the records that started or that had a the records that started or that had a first name of Tim. Now, I want you to first name of Tim. Now, I want you to first name of Tim. Now, I want you to pause for a minute and think about this. pause for a minute and think about this. pause for a minute and think about this. We did a query that filtered the We did a query that filtered the We did a query that filtered the records. How did it know how to filter? records. How did it know how to filter? records. How did it know how to filter? Well, we have auto indexing turned on.
-
Well, we have auto indexing turned on. Well, we have auto indexing turned on. Let's go back to our database. We come Let's go back to our database. We come Let's go back to our database. We come back over here to left. We have back over here to left. We have back over here to left. We have documents. We have indexes. documents. We have indexes. documents. We have indexes. There's an auto index called people by There's an auto index called people by There's an auto index called people by first name. This was created first name. This was created first name. This was created automatically for us to optimize how we automatically for us to optimize how we automatically for us to optimize how we get the data out. So we made the call. get the data out. So we made the call. get the data out. So we made the call. This index did not exist. But then it This index did not exist. But then it This index did not exist. But then it said, "Hey, I'm going to need an index said, "Hey, I'm going to need an index said, "Hey, I'm going to need an index for this. It created the index and then for this. It created the index and then for this. It created the index and then returned the data to us." Now if this returned the data to us." Now if this returned the data to us." Now if this was too much data to process then what was too much data to process then what was too much data to process then what would happen is it would give us back would happen is it would give us back would happen is it would give us back just a bit of the data that it had if it just a bit of the data that it had if it just a bit of the data that it had if it was going to time out. Okay. So that you was going to time out. Okay. So that you was going to time out. Okay. So that you can go more in depth than this but uh can go more in depth than this but uh can go more in depth than this but uh just note these auto indexes are very just note these auto indexes are very just note these auto indexes are very very quick. They're going to try and get very quick. They're going to try and get very quick. They're going to try and get your data as soon as possible. your data as soon as possible. your data as soon as possible. Even if I to say hey this is partial Even if I to say hey this is partial Even if I to say hey this is partial data. This is all I got. Um you want to data. This is all I got. Um you want to data. This is all I got. Um you want to run this again in a little bit once I'm run this again in a little bit once I'm run this again in a little bit once I'm done my index. um doesn't happen very done my index. um doesn't happen very done my index. um doesn't happen very often, especially not um when you don't often, especially not um when you don't often, especially not um when you don't have millions of records, but just know have millions of records, but just know have millions of records, but just know that it can happen. However, I would that it can happen. However, I would that it can happen. However, I would encourage you to use auto indexes in encourage you to use auto indexes in encourage you to use auto indexes in development and then use static indexes development and then use static indexes development and then use static indexes in production. The reason why is in in production. The reason why is in in production. The reason why is in development, you're figuring out what development, you're figuring out what development, you're figuring out what indexes do we need and too many indexes indexes do we need and too many indexes indexes do we need and too many indexes can cause performance problems. So, it's can cause performance problems. So, it's can cause performance problems. So, it's figure out which ones do we need. But figure out which ones do we need. But figure out which ones do we need. But once you understand what indexes are once you understand what indexes are once you understand what indexes are best, then you can come over here to best, then you can come over here to best, then you can come over here to advanced and say I want to convert to advanced and say I want to convert to advanced and say I want to convert to static. And this will convert to a new static. And this will convert to a new static. And this will convert to a new static instance. Here's a syntax for
-
static instance. Here's a syntax for static instance. Here's a syntax for it's already done for you. You could it's already done for you. You could it's already done for you. You could have configured it if you wanted to, but have configured it if you wanted to, but have configured it if you wanted to, but this is going to give us the information this is going to give us the information this is going to give us the information that we need. So that's an index, but that we need. So that's an index, but that we need. So that's an index, but notice there's only one. Let's go back notice there's only one. Let's go back notice there's only one. Let's go back to our code and change this to say last to our code and change this to say last to our code and change this to say last name name name equals let's go with uh Corey and run equals let's go with uh Corey and run equals let's go with uh Corey and run this again. this again. this again. And it gives us back Tim Corey twice And it gives us back Tim Corey twice And it gives us back Tim Corey twice because there two Tim Corey records. because there two Tim Corey records. because there two Tim Corey records. Let's go back to our database. We now Let's go back to our database. We now Let's go back to our database. We now have two indexes. The first one by first have two indexes. The first one by first have two indexes. The first one by first name. The second one is by first name name. The second one is by first name name. The second one is by first name and last name. Hold the phone. Why is it and last name. Hold the phone. Why is it and last name. Hold the phone. Why is it we have first name and last name for the we have first name and last name for the we have first name and last name for the second one? And by the way, the the second one? And by the way, the the second one? And by the way, the the other one just went away. I didn't do other one just went away. I didn't do other one just went away. I didn't do anything. It was not a camera trick. It anything. It was not a camera trick. It anything. It was not a camera trick. It just went away. Why? Well, because Raven just went away. Why? Well, because Raven just went away. Why? Well, because Raven DB said, "Wait a minute. I can optimize DB said, "Wait a minute. I can optimize DB said, "Wait a minute. I can optimize this." There was one query that asked this." There was one query that asked this." There was one query that asked for first name. There's a different for first name. There's a different for first name. There's a different query that asked for last name. What if query that asked for last name. What if query that asked for last name. What if I create a a index that index both first I create a a index that index both first I create a a index that index both first and last name? That way we have one and last name? That way we have one and last name? That way we have one index instead of two and we can ask for index instead of two and we can ask for index instead of two and we can ask for either one. So, it's really intelligent either one. So, it's really intelligent either one. So, it's really intelligent on how it creates these indexes. This is on how it creates these indexes. This is on how it creates these indexes. This is why you want to set up auto, leave auto why you want to set up auto, leave auto why you want to set up auto, leave auto on in development mode because it will on in development mode because it will on in development mode because it will figure out the best indexes for you and figure out the best indexes for you and figure out the best indexes for you and get rid of the rest. Then when you're get rid of the rest. Then when you're get rid of the rest. Then when you're done and you're ready to go production, done and you're ready to go production, done and you're ready to go production, you can just say, "Hey, mark all these you can just say, "Hey, mark all these you can just say, "Hey, mark all these as as um static indexes." Because that
-
as as um static indexes." Because that as as um static indexes." Because that way they're already set up. They're way they're already set up. They're way they're already set up. They're already indexed. So, the very first time already indexed. So, the very first time already indexed. So, the very first time a customer asks for that data, it's a customer asks for that data, it's a customer asks for that data, it's already indexed. is very very fast to already indexed. is very very fast to already indexed. is very very fast to get the data back. So, best of both get the data back. So, best of both get the data back. So, best of both worlds here. In development, auto index worlds here. In development, auto index worlds here. In development, auto index is on all the time. In production, I'd is on all the time. In production, I'd is on all the time. In production, I'd prefer you do static indexes um just prefer you do static indexes um just prefer you do static indexes um just because of the optimization of uh because of the optimization of uh because of the optimization of uh already having them indexed when the already having them indexed when the already having them indexed when the first customer asks for that data. So, first customer asks for that data. So, first customer asks for that data. So, that's auto indexes. Great stuff going that's auto indexes. Great stuff going that's auto indexes. Great stuff going on here. All right, back to our uh on here. All right, back to our uh on here. All right, back to our uh people list. We still have a six there. people list. We still have a six there. people list. We still have a six there. Okay, Okay, Okay, let's look at doing some more things let's look at doing some more things let's look at doing some more things here. Let's look at changing data. here. Let's look at changing data. here. Let's look at changing data. So, right now I have this for each and So, right now I have this for each and So, right now I have this for each and let's change it back to uh first name let's change it back to uh first name let's change it back to uh first name equals Tim. And I want to say, you know what? Yeah, And I want to say, you know what? Yeah, let's let's print it out just so we can let's let's print it out just so we can let's let's print it out just so we can see that we have a first name equals see that we have a first name equals see that we have a first name equals Tim. But I want to change the first name Tim. But I want to change the first name Tim. But I want to change the first name uh uh uh P.irstame. I'm going to change it to P.irstame. I'm going to change it to P.irstame. I'm going to change it to Timothy. So, I've loaded just the Tim Timothy. So, I've loaded just the Tim Timothy. So, I've loaded just the Tim records, but I want to change that first records, but I want to change that first records, but I want to change that first name to Timothy for all those people name to Timothy for all those people name to Timothy for all those people because that's the more formal full because that's the more formal full because that's the more formal full name. Now, this is just a demo name. Now, this is just a demo name. Now, this is just a demo obviously, but I'm going to say down obviously, but I'm going to say down obviously, but I'm going to say down here await session.save here await session.save here await session.save changes async.
-
changes async. changes async. Now, again, to be clear, all I've done Now, again, to be clear, all I've done Now, again, to be clear, all I've done is changed the loaded list of people. is changed the loaded list of people. is changed the loaded list of people. I've changed some of the data. I've changed some of the data. I've changed some of the data. Now that I've done that, I just say save Now that I've done that, I just say save Now that I've done that, I just say save changes. Why? Because since the session changes. Why? Because since the session changes. Why? Because since the session is still open, is still open, is still open, we're tracking the changes on this list we're tracking the changes on this list we're tracking the changes on this list of people. And so it says, hey, you know of people. And so it says, hey, you know of people. And so it says, hey, you know what? I saw that a couple of records, what? I saw that a couple of records, what? I saw that a couple of records, four of them exact. We changed the first four of them exact. We changed the first four of them exact. We changed the first name property. So, I'm going to send in name property. So, I'm going to send in name property. So, I'm going to send in the save changes async, not the whole the save changes async, not the whole the save changes async, not the whole record, but just these changes to just record, but just these changes to just record, but just these changes to just these four records. And we're going to these four records. And we're going to these four records. And we're going to do all of that in one query here. Okay. do all of that in one query here. Okay. do all of that in one query here. Okay. So, I run this, it's going to list. And So, I run this, it's going to list. And So, I run this, it's going to list. And notice that first it says Tim Corey, Tim notice that first it says Tim Corey, Tim notice that first it says Tim Corey, Tim Smith because we we did the console, Smith because we we did the console, Smith because we we did the console, right, right before I changed the value. right, right before I changed the value. right, right before I changed the value. I didn't do it after because yeah, of I didn't do it after because yeah, of I didn't do it after because yeah, of course, I'm going to change a list course, I'm going to change a list course, I'm going to change a list after, but let's go look at our data. after, but let's go look at our data. after, but let's go look at our data. And if we hit refresh here now notice And if we hit refresh here now notice And if we hit refresh here now notice they all say Timothy instead of Tim. All they all say Timothy instead of Tim. All they all say Timothy instead of Tim. All those changes were made all at once and those changes were made all at once and those changes were made all at once and it I didn't have to do anything special.
-
it I didn't have to do anything special. it I didn't have to do anything special. I didn't have to write an update query I didn't have to write an update query I didn't have to write an update query anything crazy because it's just done. anything crazy because it's just done. anything crazy because it's just done. Now I do want to point out one more Now I do want to point out one more Now I do want to point out one more thing. Um let's let's do this. Let's thing. Um let's let's do this. Let's thing. Um let's let's do this. Let's change this to say Timothy and change it change this to say Timothy and change it change this to say Timothy and change it back to Tim. They want to make this back to Tim. They want to make this back to Tim. They want to make this change again. But I want to come down change again. But I want to come down change again. But I want to come down here and I want to say console right here and I want to say console right here and I want to say console right line and we're gonna say uh line and we're gonna say uh line and we're gonna say uh session.advanced number of requests. number of requests. So after we save these changes, I want So after we save these changes, I want So after we save these changes, I want to capture how many requests did we do to capture how many requests did we do to capture how many requests did we do on this session object. So we've got on this session object. So we've got on this session object. So we've got this load person. We're changing four this load person. We're changing four this load person. We're changing four records. records. records. And how many requests do you think we're And how many requests do you think we're And how many requests do you think we're going to do? Okay, let's run this going to do? Okay, let's run this going to do? Okay, let's run this two. I've done two requests to the two. I've done two requests to the two. I've done two requests to the server. You might say that doesn't make server. You might say that doesn't make server. You might say that doesn't make sense because we loaded all the people. sense because we loaded all the people. sense because we loaded all the people. That's one request and we changed four That's one request and we changed four That's one request and we changed four records. Yeah, but that's not where that records. Yeah, but that's not where that records. Yeah, but that's not where that change happened. Remember the change change happened. Remember the change change happened. Remember the change happened right here. And so what happened right here. And so what happened right here. And so what happened is, yeah, it made those four happened is, yeah, it made those four happened is, yeah, it made those four changes, but bundled all up as one changes, but bundled all up as one changes, but bundled all up as one request and sent the whole thing over as request and sent the whole thing over as request and sent the whole thing over as one request. When you're working with one request. When you're working with one request. When you're working with sessions, you want to try and get the sessions, you want to try and get the sessions, you want to try and get the number of requests as close to one as number of requests as close to one as number of requests as close to one as possible. It can do about 30 uh changes possible. It can do about 30 uh changes possible. It can do about 30 uh changes or 30 actions or requests in a session.
-
or 30 actions or requests in a session. or 30 actions or requests in a session. And you can actually change that number And you can actually change that number And you can actually change that number to be even more if you were crazy. But to be even more if you were crazy. But to be even more if you were crazy. But you can do that. Um but you really want you can do that. Um but you really want you can do that. Um but you really want a session to be a very atomic action. a session to be a very atomic action. a session to be a very atomic action. You don't want it to be lots of actions. You don't want it to be lots of actions. You don't want it to be lots of actions. But notice this wasn't lots of actions. But notice this wasn't lots of actions. But notice this wasn't lots of actions. This is one action. So the number of This is one action. So the number of This is one action. So the number of requests you want them to be pretty requests you want them to be pretty requests you want them to be pretty small. Okay. But in this case doing small. Okay. But in this case doing small. Okay. But in this case doing these things only two. All right. Now these things only two. All right. Now these things only two. All right. Now let's think about other things that we let's think about other things that we let's think about other things that we might want to do. We've had the create, might want to do. We've had the create, might want to do. We've had the create, we've had the read, we've had the we've had the read, we've had the we've had the read, we've had the update. The last one we need to think update. The last one we need to think update. The last one we need to think about is well how do we delete? Well, about is well how do we delete? Well, about is well how do we delete? Well, let's do a delete. So, we're going to let's do a delete. So, we're going to let's do a delete. So, we're going to comment out all of this. And I'm gonna comment out all of this. And I'm gonna comment out all of this. And I'm gonna come down here and I'm going to say, you come down here and I'm going to say, you come down here and I'm going to say, you know what? Let's um let's say that know what? Let's um let's say that know what? Let's um let's say that uh people equals await session uh people equals await session uh people equals await session uh query uh query uh query and we're going to say person model and we're going to say person model and we're going to say person model and we're going to say to list async.
-
and we're going to say to list async. and we're going to say to list async. So, that gets the list of all the So, that gets the list of all the So, that gets the list of all the people. We're going to say uh for each people. We're going to say uh for each people. We're going to say uh for each we're going to say var in people we're going to say var in people we're going to say var in people and we'll say uh let's go with uh and we'll say uh let's go with uh and we'll say uh let's go with uh session session session delete p delete p delete p and then we'll say await and then we'll say await and then we'll say await sessions sessions sessions save changes async. Okay, so I've loaded save changes async. Okay, so I've loaded save changes async. Okay, so I've loaded the list of all the people and then I the list of all the people and then I the list of all the people and then I call session.delete for every person in call session.delete for every person in call session.delete for every person in the list and then I do save changes. How the list and then I do save changes. How the list and then I do save changes. How many how many uh requests do you think many how many uh requests do you think many how many uh requests do you think that's going to be? Let's actually that's going to be? Let's actually that's going to be? Let's actually uncomment this out. Two. Two. Why two? Well, we load all the people. Why two? Well, we load all the people. Why two? Well, we load all the people. We delete all the people. Two requests. We delete all the people. Two requests. We delete all the people. Two requests. have to go back to our our database and have to go back to our our database and have to go back to our our database and look at our collection for uh where's look at our collection for uh where's look at our collection for uh where's people it it's gone because there's no people it it's gone because there's no people it it's gone because there's no there's no object in the collection. If there's no object in the collection. If there's no object in the collection. If there's no objects in the collection, there's no objects in the collection, there's no objects in the collection, it's just gone. So, it's just gone. So, it's just gone. So, we're done. Okay. Um our index, well, we're done. Okay. Um our index, well, we're done. Okay. Um our index, well, that index will go away soon because that index will go away soon because that index will go away soon because there's no entities to index anymore there's no entities to index anymore there's no entities to index anymore because they're all gone. Okay. Um let's because they're all gone. Okay. Um let's because they're all gone. Okay. Um let's let's do this. Let's just get rid of let's do this. Let's just get rid of let's do this. Let's just get rid of everything. Um, I'm gonna say delete.
-
everything. Um, I'm gonna say delete. everything. Um, I'm gonna say delete. Um, and hit delete. Um, and hit delete. Um, and hit delete. Oh, I that was my bad. Um, Oh, I that was my bad. Um, Oh, I that was my bad. Um, I I should not have tried to delete the I I should not have tried to delete the I I should not have tried to delete the hyo um entries. That's That's my bad. hyo um entries. That's That's my bad. hyo um entries. That's That's my bad. Um, but otherwise, we have our system Um, but otherwise, we have our system Um, but otherwise, we have our system collection for Hyo. Otherwise, we have collection for Hyo. Otherwise, we have collection for Hyo. Otherwise, we have no collections anymore. That just kind no collections anymore. That just kind no collections anymore. That just kind of cleaned things up for us. Ignore all of cleaned things up for us. Ignore all of cleaned things up for us. Ignore all the rest. Okay. So now we've done the the rest. Okay. So now we've done the the rest. Okay. So now we've done the full CRUD actions and I think at this full CRUD actions and I think at this full CRUD actions and I think at this point you have enough to get started but point you have enough to get started but point you have enough to get started but I'm going to come back and make this I'm going to come back and make this I'm going to come back and make this better. But first I want to talk really better. But first I want to talk really better. But first I want to talk really briefly of a couple other things you can briefly of a couple other things you can briefly of a couple other things you can do. So we're not done the code yet. I do. So we're not done the code yet. I do. So we're not done the code yet. I want to come back and make this a better want to come back and make this a better want to come back and make this a better version of our code. But I want to get version of our code. But I want to get version of our code. But I want to get to some other things you can do with to some other things you can do with to some other things you can do with Raven DB. Let's bring back up Raven DB's Raven DB. Let's bring back up Raven DB's Raven DB. Let's bring back up Raven DB's documentation. There's lots of stuff in documentation. There's lots of stuff in documentation. There's lots of stuff in here we can talk about, but I want to here we can talk about, but I want to here we can talk about, but I want to talk about a few things. The first talk about a few things. The first talk about a few things. The first important one is you have search and important one is you have search and important one is you have search and let's search for Aspire.
-
let's search for Aspire. let's search for Aspire. And this guide right here, this is a And this guide right here, this is a And this guide right here, this is a great guide. Okay, it's going to tell great guide. Okay, it's going to tell great guide. Okay, it's going to tell you step by step how to work with you step by step how to work with you step by step how to work with Aspire. I don't have time in this video Aspire. I don't have time in this video Aspire. I don't have time in this video to get to it, but um if we look down to get to it, but um if we look down to get to it, but um if we look down here, it's installing the packages. It here, it's installing the packages. It here, it's installing the packages. It shows us step by step how to do that. shows us step by step how to do that. shows us step by step how to do that. The only one real kind of quirk is that The only one real kind of quirk is that The only one real kind of quirk is that you have the explanation and then the you have the explanation and then the you have the explanation and then the picture. So if you don't scroll down far picture. So if you don't scroll down far picture. So if you don't scroll down far enough, you might miss the fact that the enough, you might miss the fact that the enough, you might miss the fact that the picture kind of points out what's going picture kind of points out what's going picture kind of points out what's going on. So um here's a code for Aspire. This on. So um here's a code for Aspire. This on. So um here's a code for Aspire. This right here, add Raven DB. That's what right here, add Raven DB. That's what right here, add Raven DB. That's what you need to do. And then reference it you need to do. And then reference it you need to do. And then reference it somewhere um for referencing it in your somewhere um for referencing it in your somewhere um for referencing it in your project. And then um down here, here's project. And then um down here, here's project. And then um down here, here's actually setting up a connection to a actually setting up a connection to a actually setting up a connection to a database. database. database. And then down here, this code looks And then down here, this code looks And then down here, this code looks exactly the same as what I've been exactly the same as what I've been exactly the same as what I've been doing, right? It's just creating new new doing, right? It's just creating new new doing, right? It's just creating new new objects and doing store async and save objects and doing store async and save objects and doing store async and save changes async, etc. So, setting up an changes async, etc. So, setting up an changes async, etc. So, setting up an Aspire super easy to do. Um, and then Aspire super easy to do. Um, and then Aspire super easy to do. Um, and then over here, I do want to point out that over here, I do want to point out that over here, I do want to point out that there's a lot of information in here, there's a lot of information in here, there's a lot of information in here, but if you do a search, you can look for but if you do a search, you can look for but if you do a search, you can look for things like time series. Super fun to things like time series. Super fun to things like time series. Super fun to do. Um, attachments. You can attach do. Um, attachments. You can attach do. Um, attachments. You can attach documents to your collection. Um, really documents to your collection. Um, really documents to your collection. Um, really great. There's also two different ways great. There's also two different ways great. There's also two different ways of tracking changes. So, there's a of tracking changes. So, there's a of tracking changes. So, there's a changes API, which again, if we search changes API, which again, if we search changes API, which again, if we search for this, uh, changes API.
-
for this, uh, changes API. for this, uh, changes API. The changes API is for um and here's you The changes API is for um and here's you The changes API is for um and here's you know code for how to do it and how to know code for how to do it and how to know code for how to do it and how to unsubscribe. Um the changes API is for unsubscribe. Um the changes API is for unsubscribe. Um the changes API is for tracking changes to your data where it tracking changes to your data where it tracking changes to your data where it will say hey data in this document or will say hey data in this document or will say hey data in this document or whatever else you're tracking um has whatever else you're tracking um has whatever else you're tracking um has changed. And this is for like if you changed. And this is for like if you changed. And this is for like if you want to have your your UI refresh every want to have your your UI refresh every want to have your your UI refresh every time there's new data in the database time there's new data in the database time there's new data in the database without having to constantly pull the without having to constantly pull the without having to constantly pull the database. database. database. This will do it. That's what the changes This will do it. That's what the changes This will do it. That's what the changes API is for. It's kind of for UI API is for. It's kind of for UI API is for. It's kind of for UI refreshes, etc. There's a different one refreshes, etc. There's a different one refreshes, etc. There's a different one though, and I believe it's it's there's though, and I believe it's it's there's though, and I believe it's it's there's a link in here um at some point for um a link in here um at some point for um a link in here um at some point for um the other one right here. Um data the other one right here. Um data the other one right here. Um data subscription. This is something subscription. This is something subscription. This is something different. It's like the changes API, different. It's like the changes API, different. It's like the changes API, but this is another way to monitor for but this is another way to monitor for but this is another way to monitor for changes on objects or on collections, changes on objects or on collections, changes on objects or on collections, etc. But what this does is it's more etc. But what this does is it's more etc. But what this does is it's more like a Q where let's say you every time like a Q where let's say you every time like a Q where let's say you every time you get a new record in a collection you you get a new record in a collection you you get a new record in a collection you want to maybe it's a record for hey I want to maybe it's a record for hey I want to maybe it's a record for hey I want to make this purchase and so you want to make this purchase and so you want to make this purchase and so you you want to do some processing like send you want to do some processing like send you want to do some processing like send a message to the warehouse. Well, you a message to the warehouse. Well, you a message to the warehouse. Well, you could have a data subscription that says could have a data subscription that says could have a data subscription that says every time new record comes in, I want every time new record comes in, I want every time new record comes in, I want to do this work. And this will make sure to do this work. And this will make sure to do this work. And this will make sure that one and only one uh system that one and only one uh system that one and only one uh system processes every record that comes in or processes every record that comes in or processes every record that comes in or whatever your setup is. So, this is this
-
whatever your setup is. So, this is this whatever your setup is. So, this is this is more like a Q process. There's also u is more like a Q process. There's also u is more like a Q process. There's also u clustering built in. There's more clustering built in. There's more clustering built in. There's more information on Gen AI that you can go information on Gen AI that you can go information on Gen AI that you can go into and how to use Genai to do things into and how to use Genai to do things into and how to use Genai to do things like translate your documents or when I like translate your documents or when I like translate your documents or when I come in or taking the attachments and come in or taking the attachments and come in or taking the attachments and then breaking it down into information then breaking it down into information then breaking it down into information that can be put into your document and that can be put into your document and that can be put into your document and so many other things. So, lots of stuff so many other things. So, lots of stuff so many other things. So, lots of stuff in here that you can do that I can't get in here that you can do that I can't get in here that you can do that I can't get into in this video. I mean, I want to into in this video. I mean, I want to into in this video. I mean, I want to cover so much of this, but I want to cover so much of this, but I want to cover so much of this, but I want to give you a good intro. That's why I give you a good intro. That's why I give you a good intro. That's why I wanted to at least get through this much wanted to at least get through this much wanted to at least get through this much of it with you. Um, so lots more here. of it with you. Um, so lots more here. of it with you. Um, so lots more here. Definitely go and check it out. Um, but Definitely go and check it out. Um, but Definitely go and check it out. Um, but let's get back to our code. And if if let's get back to our code. And if if let's get back to our code. And if if you want me done right now, cool. you want me done right now, cool. you want me done right now, cool. Download the source code. There'll be Download the source code. There'll be Download the source code. There'll be more source code that you've seen so more source code that you've seen so more source code that you've seen so far. We're going to rework this into a far. We're going to rework this into a far. We're going to rework this into a more uh a better usable in at least in more uh a better usable in at least in more uh a better usable in at least in development, if not production code base development, if not production code base development, if not production code base um for a console app. um it's going the um for a console app. um it's going the um for a console app. um it's going the same code or close to the same code but same code or close to the same code but same code or close to the same code but um I want to show you how to basically um I want to show you how to basically um I want to show you how to basically do this better than this demo. Okay, so do this better than this demo. Okay, so do this better than this demo. Okay, so let's create a new project.
-
let's create a new project. let's create a new project. We're call this uh a new console project We're call this uh a new console project We're call this uh a new console project and we call this better Raven DB demo and we call this better Raven DB demo and we call this better Raven DB demo and yes net 10. And we need to bring in and yes net 10. And we need to bring in and yes net 10. And we need to bring in that same dependency. By the way, you that same dependency. By the way, you that same dependency. By the way, you can look at the dependency right here in can look at the dependency right here in can look at the dependency right here in your project. We could just copy this if your project. We could just copy this if your project. We could just copy this if we wanted to come over here to our other we wanted to come over here to our other we wanted to come over here to our other project and paste it in. We'll do a lot project and paste it in. We'll do a lot project and paste it in. We'll do a lot of copy and pasting in this because of copy and pasting in this because of copy and pasting in this because we're we're trying to um just rework how we're we're trying to um just rework how we're we're trying to um just rework how we've done things. we've done things. we've done things. So, [snorts] let's next create a new So, [snorts] let's next create a new So, [snorts] let's next create a new model. We're going to call this employee model. We're going to call this employee model. We're going to call this employee model. model. model. I just want to create a different name. I just want to create a different name. I just want to create a different name. Um that way we don't have um the same Um that way we don't have um the same Um that way we don't have um the same name kind of step on toes of the two name kind of step on toes of the two name kind of step on toes of the two demos. I'm public and I'm going to copy demos. I'm public and I'm going to copy demos. I'm public and I'm going to copy and paste the person model. It's the and paste the person model. It's the and paste the person model. It's the same data. Okay, it's just a different same data. Okay, it's just a different same data. Okay, it's just a different name. Um, that way we again don't step name. Um, that way we again don't step name. Um, that way we again don't step on each other's [clears throat] toes. on each other's [clears throat] toes. on each other's [clears throat] toes. Um, so there we go. We've got our Um, so there we go. We've got our Um, so there we go. We've got our employee model. And now what I'm going employee model. And now what I'm going employee model. And now what I'm going to do is in a better Raven DB demo, I'm to do is in a better Raven DB demo, I'm to do is in a better Raven DB demo, I'm going to create a new object called data going to create a new object called data going to create a new object called data access.
-
access. access. And we'll get rid of the using uh And we'll get rid of the using uh And we'll get rid of the using uh directives here and mark it as public. directives here and mark it as public. directives here and mark it as public. And what we're going to do is I'm going And what we're going to do is I'm going And what we're going to do is I'm going to actually bring in um those two to actually bring in um those two to actually bring in um those two these two right here, these two using. these two right here, these two using. these two right here, these two using. And put those at the top just so we have And put those at the top just so we have And put those at the top just so we have them. Again, makes life a little easier. them. Again, makes life a little easier. them. Again, makes life a little easier. And now I'm going to create a um let's And now I'm going to create a um let's And now I'm going to create a um let's do constructor. I'm going to mark this do constructor. I'm going to mark this do constructor. I'm going to mark this as uh private. as uh private. as uh private. So we're going to create a a singleton So we're going to create a a singleton So we're going to create a a singleton of this class. That way we only ever of this class. That way we only ever of this class. That way we only ever create one document store. create one document store. create one document store. So we're going to say right here private So we're going to say right here private So we're going to say right here private I document store and we'll call it store. and we'll call it store. And then we're also going to have a And then we're also going to have a And then we're also going to have a property called a a static property.
-
property called a a static property. property called a a static property. a static data access a static data access a static data access and we'll call this instance and we'll call this instance and we'll call this instance and we'll not have a setter. We'll only and we'll not have a setter. We'll only and we'll not have a setter. We'll only have a getter but we'll have a default have a getter but we'll have a default have a getter but we'll have a default value of value of value of uh new. What that does is the very first uh new. What that does is the very first uh new. What that does is the very first time you call instance it's going to time you call instance it's going to time you call instance it's going to instantiate the data access as private. instantiate the data access as private. instantiate the data access as private. It can still call the constructor. Um It can still call the constructor. Um It can still call the constructor. Um but after that we call instance and it but after that we call instance and it but after that we call instance and it just gets the um the value. So that way just gets the um the value. So that way just gets the um the value. So that way we only have one instance. This is a we only have one instance. This is a we only have one instance. This is a singleton pattern in inn net. Now let's singleton pattern in inn net. Now let's singleton pattern in inn net. Now let's uh go back to our program.cs and we're uh go back to our program.cs and we're uh go back to our program.cs and we're going to grab from store not the using going to grab from store not the using going to grab from store not the using document store but from store down to document store but from store down to document store but from store down to here. We'll grab this whole thing here. We'll grab this whole thing here. We'll grab this whole thing and we're going to put that in the data and we're going to put that in the data and we're going to put that in the data access. And we do need to also stay um access. And we do need to also stay um access. And we do need to also stay um let's tab to adapt code. Um it should be let's tab to adapt code. Um it should be let's tab to adapt code. Um it should be formatting our code properly but um formatting our code properly but um formatting our code properly but um looks like it's not going to without looks like it's not going to without looks like it's not going to without some work. So let's just hit tab here some work. So let's just hit tab here some work. So let's just hit tab here and bring that in. Okay, we we do need and bring that in. Okay, we we do need and bring that in. Okay, we we do need to have our our store.initialize.
-
Okay, so this is create a new instance Okay, so this is create a new instance of a document store and putting into our of a document store and putting into our of a document store and putting into our I document store. But one of the things I document store. But one of the things I document store. But one of the things you may have noticed, hopefully you did, you may have noticed, hopefully you did, you may have noticed, hopefully you did, is that down here we had this as a using is that down here we had this as a using is that down here we had this as a using statement. So it said using I document statement. So it said using I document statement. So it said using I document store, which means that automatically store, which means that automatically store, which means that automatically closed out the store when we were done closed out the store when we were done closed out the store when we were done with program.cs, when we're done with with program.cs, when we're done with with program.cs, when we're done with that scope. that scope. that scope. We're not doing that here because we We're not doing that here because we We're not doing that here because we can't we can't close it out at the end can't we can't close it out at the end can't we can't close it out at the end of this scope because that's the of this scope because that's the of this scope because that's the constructor. constructor. constructor. So, what we're going to do instead is So, what we're going to do instead is So, what we're going to do instead is we're going to mark our class as I we're going to mark our class as I we're going to mark our class as I disposable. disposable. disposable. And if you're not familiar with this And if you're not familiar with this And if you're not familiar with this pattern, what this pattern does is it pattern, what this pattern does is it pattern, what this pattern does is it allows us to make a using statement allows us to make a using statement allows us to make a using statement against this class itself. Now, let's against this class itself. Now, let's against this class itself. Now, let's collapse down our constructor and um collapse down our constructor and um collapse down our constructor and um we'll come down here and we're going to we'll come down here and we're going to we'll come down here and we're going to say public void dispose say public void dispose say public void dispose Now this is going to fulfill the Now this is going to fulfill the Now this is going to fulfill the contract of I disposable and inside contract of I disposable and inside contract of I disposable and inside dispose we're going to say store.dispose dispose we're going to say store.dispose dispose we're going to say store.dispose directly. So normally I would not directly. So normally I would not directly. So normally I would not recommend doing this. Don't call stored recommend doing this. Don't call stored recommend doing this. Don't call stored dispose itself. Just use the the using dispose itself. Just use the the using dispose itself. Just use the the using statement and that way it make sure it statement and that way it make sure it statement and that way it make sure it calls that dispose method properly at calls that dispose method properly at calls that dispose method properly at the end. However, we're doing our own I the end. However, we're doing our own I the end. However, we're doing our own I disposable. Therefore, we we call this
-
disposable. Therefore, we we call this disposable. Therefore, we we call this dispose in the dispose method. dispose in the dispose method. dispose in the dispose method. Okay. Now, we'll never call this method Okay. Now, we'll never call this method Okay. Now, we'll never call this method directly. Again, kind of like this, directly. Again, kind of like this, directly. Again, kind of like this, we're not calling it directly. Instead, we're not calling it directly. Instead, we're not calling it directly. Instead, what we'll do is in our program.cs, what we'll do is in our program.cs, what we'll do is in our program.cs, what we're going to do is we're going to what we're going to do is we're going to what we're going to do is we're going to um we're come over here and we'll say um we're come over here and we'll say um we're come over here and we'll say first of all add a using directive for first of all add a using directive for first of all add a using directive for um better Raven DB demo. And then we're um better Raven DB demo. And then we're um better Raven DB demo. And then we're going to say using data access, going to say using data access, going to say using data access, we're going to call it data access we're going to call it data access we're going to call it data access equals data access.instance. equals data access.instance. equals data access.instance. So this right here will make sure we So this right here will make sure we So this right here will make sure we close down or call the dispose method on close down or call the dispose method on close down or call the dispose method on data access when we're done our scope, data access when we're done our scope, data access when we're done our scope, which is back to being program.cs. Okay, which is back to being program.cs. Okay, which is back to being program.cs. Okay, so this is a better way of doing things so this is a better way of doing things so this is a better way of doing things to make sure you can do this wherever to make sure you can do this wherever to make sure you can do this wherever you're instantiate or setting up your you're instantiate or setting up your you're instantiate or setting up your scope. If you're doing dependency scope. If you're doing dependency scope. If you're doing dependency injection, we would do it at that point injection, we would do it at that point injection, we would do it at that point and let dependency injection handle the and let dependency injection handle the and let dependency injection handle the um the processing of the dispose method.
-
um the processing of the dispose method. um the processing of the dispose method. Okay, so now we can come back over here Okay, so now we can come back over here Okay, so now we can come back over here to our data access. We can start doing to our data access. We can start doing to our data access. We can start doing work. So we have the setup. We've done work. So we have the setup. We've done work. So we have the setup. We've done the private constructor that has our the private constructor that has our the private constructor that has our document store. We have our dispose to document store. We have our dispose to document store. We have our dispose to properly close the document store. So properly close the document store. So properly close the document store. So now let's come down here and we're going now let's come down here and we're going now let's come down here and we're going to um there we go. U we're going to set to um there we go. U we're going to set to um there we go. U we're going to set up some method calls. So public async up some method calls. So public async up some method calls. So public async task of type list of employee model task of type list of employee model task of type list of employee model and we're going to say load all and we're going to say load all and we're going to say load all employees employees employees and we're going to make sure we pass in and we're going to make sure we pass in and we're going to make sure we pass in cancellation token token equals default. Okay, we're going to use cancellation Okay, we're going to use cancellation tokens. That is the um the recommended tokens. That is the um the recommended tokens. That is the um the recommended best practice way of doing things when best practice way of doing things when best practice way of doing things when you're ever making an async call to pass you're ever making an async call to pass you're ever making an async call to pass in a cancellation token. That way the in a cancellation token. That way the in a cancellation token. That way the call can be cancelled properly. Um so call can be cancelled properly. Um so call can be cancelled properly. Um so we're going to say but this also sets it we're going to say but this also sets it we're going to say but this also sets it as a default value um if it's not being as a default value um if it's not being as a default value um if it's not being passed in. All right. So using I async passed in. All right. So using I async passed in. All right. So using I async document session we're going to call it session equals we're going to call it session equals store.open session async. Where am I store.open session async. Where am I store.open session async. Where am I getting this from? It's like we're doing
-
getting this from? It's like we're doing getting this from? It's like we're doing right down here. right down here. right down here. Okay. But we're doing it in this method. Okay. But we're doing it in this method. Okay. But we're doing it in this method. And in fact in all these methods we're And in fact in all these methods we're And in fact in all these methods we're going to open up a session. Again going to open up a session. Again going to open up a session. Again sessions should be atomic. They should sessions should be atomic. They should sessions should be atomic. They should be small. They should be doing probably be small. They should be doing probably be small. They should be doing probably one thing typically. one thing typically. one thing typically. And we're going to say return await And we're going to say return await And we're going to say return await session.query session.query session.query employee model to list async and pass in that token. to list async and pass in that token. Okay. So now what this load all Okay. So now what this load all Okay. So now what this load all employees does is it loads well all the employees does is it loads well all the employees does is it loads well all the employees. And notice this session is employees. And notice this session is employees. And notice this session is going to only live for the scope because going to only live for the scope because going to only live for the scope because it's using. So therefore it ends right it's using. So therefore it ends right it's using. So therefore it ends right here. here. here. Now let's follow the same pattern and Now let's follow the same pattern and Now let's follow the same pattern and say public async say public async say public async task of type employee model and look at task of type employee model and look at task of type employee model and look at nullable model this time. And we're nullable model this time. And we're nullable model this time. And we're going to say load employee by ID string going to say load employee by ID string going to say load employee by ID string ID and cancellation token token equals ID and cancellation token token equals ID and cancellation token token equals default. Now we haven't done this default. Now we haven't done this default. Now we haven't done this previously um load by ID but we're going previously um load by ID but we're going previously um load by ID but we're going to see how to do that. So we're going to to see how to do that. So we're going to to see how to do that. So we're going to open up our session and no do not open up our session and no do not open up our session and no do not abstract this away. This should be in abstract this away. This should be in abstract this away. This should be in every single one of these. Don't try and every single one of these. Don't try and every single one of these. Don't try and pass it off to a different method or pass it off to a different method or pass it off to a different method or something. do it right here.
-
something. do it right here. something. do it right here. Too many people think that dry, don't Too many people think that dry, don't Too many people think that dry, don't repeat yourself, means you should never repeat yourself, means you should never repeat yourself, means you should never have repeated lines. That's not what dry have repeated lines. That's not what dry have repeated lines. That's not what dry means. Put your your um using statement means. Put your your um using statement means. Put your your um using statement here for your session. Make sure that here for your session. Make sure that here for your session. Make sure that you are opening up a new session and you are opening up a new session and you are opening up a new session and having it close at the end of your having it close at the end of your having it close at the end of your scope. Don't don't make a mess of this. scope. Don't don't make a mess of this. scope. Don't don't make a mess of this. Just retype it or in this case, copy Just retype it or in this case, copy Just retype it or in this case, copy paste. Return. await session.load paste. Return. await session.load paste. Return. await session.load async employee model async employee model async employee model and pass the ID and the token. Now this and pass the ID and the token. Now this and pass the ID and the token. Now this load async is going to return an load async is going to return an load async is going to return an employee model. But just to be clear employee model. But just to be clear employee model. But just to be clear here, load async is not null aware. That here, load async is not null aware. That here, load async is not null aware. That means it could return null. So even means it could return null. So even means it could return null. So even though it doesn't say load or employee though it doesn't say load or employee though it doesn't say load or employee model question mark is the return type, model question mark is the return type, model question mark is the return type, that is the return type because it's not that is the return type because it's not that is the return type because it's not nullable aware means it hasn't been set nullable aware means it hasn't been set nullable aware means it hasn't been set up yet with the nullable markings like up yet with the nullable markings like up yet with the nullable markings like we have here. But it can return a null.
-
we have here. But it can return a null. we have here. But it can return a null. Therefore, we should have it be a Therefore, we should have it be a Therefore, we should have it be a nullable aware employee model that we're nullable aware employee model that we're nullable aware employee model that we're returning. returning. returning. Okay, so there's the the load one. We're Okay, so there's the the load one. We're Okay, so there's the the load one. We're going to call all these in a little bit, going to call all these in a little bit, going to call all these in a little bit, but I just want to make sure that you um but I just want to make sure that you um but I just want to make sure that you um saw how to do all these at once. So then saw how to do all these at once. So then saw how to do all these at once. So then we have public async task called insert we have public async task called insert we have public async task called insert employee and we're going to say employee employee and we're going to say employee employee and we're going to say employee model employee and then the cancellation model employee and then the cancellation model employee and then the cancellation token called token equals default. token called token equals default. token called token equals default. And we're going to have that same And we're going to have that same And we're going to have that same session connection. And we're going to session connection. And we're going to session connection. And we're going to say await say await say await session. Store async employee and that session. Store async employee and that session. Store async employee and that token. But remember that's not actually token. But remember that's not actually token. But remember that's not actually going to the database. That's just going to the database. That's just going to the database. That's just basically put in the queue until we say basically put in the queue until we say basically put in the queue until we say await session.save await session.save await session.save changes async and pass in the token.
-
changes async and pass in the token. changes async and pass in the token. This is where the the store async This is where the the store async This is where the the store async actually gets completed. actually gets completed. actually gets completed. One note here, this is going to insert One note here, this is going to insert One note here, this is going to insert one employee. There is a way to do bulk one employee. There is a way to do bulk one employee. There is a way to do bulk inserts. It's in the documentation. It inserts. It's in the documentation. It inserts. It's in the documentation. It will show you how to do bulk inserts will show you how to do bulk inserts will show you how to do bulk inserts just in case you want to insert uh just in case you want to insert uh just in case you want to insert uh millions of records or whatever when millions of records or whatever when millions of records or whatever when you're first starting off or something you're first starting off or something you're first starting off or something else. Um, I'd love to do a separate else. Um, I'd love to do a separate else. Um, I'd love to do a separate video on that because bulk inserts is u video on that because bulk inserts is u video on that because bulk inserts is u a little bit different and there can be a little bit different and there can be a little bit different and there can be some tricky things when it comes to some tricky things when it comes to some tricky things when it comes to resuming broken down broken you know resuming broken down broken you know resuming broken down broken you know when you start doing the upload but then when you start doing the upload but then when you start doing the upload but then something happens it breaks resuming is something happens it breaks resuming is something happens it breaks resuming is a bit different because of of how it a bit different because of of how it a bit different because of of how it does the bulk upload but that's a topic does the bulk upload but that's a topic does the bulk upload but that's a topic for another day. So we have insert for another day. So we have insert for another day. So we have insert employee. Now let's do uh public async employee. Now let's do uh public async employee. Now let's do uh public async uh task of type update employee. uh task of type update employee. uh task of type update employee. And we're going to say employee model And we're going to say employee model And we're going to say employee model employee employee employee and cancellation token token equals and cancellation token token equals and cancellation token token equals default.
-
default. default. And the first thing we do is have our And the first thing we do is have our And the first thing we do is have our session opened up. And this is where session opened up. And this is where session opened up. And this is where things are a bit tricky. So let's do our things are a bit tricky. So let's do our things are a bit tricky. So let's do our await um session.save await um session.save await um session.save changes async at the end with a token. changes async at the end with a token. changes async at the end with a token. Uh but in here in between here, what do Uh but in here in between here, what do Uh but in here in between here, what do you do to update a record? Well, I will you do to update a record? Well, I will you do to update a record? Well, I will tell you what you can do if you wanted tell you what you can do if you wanted tell you what you can do if you wanted to. Await session to. Await session to. Await session store async employee and token, which store async employee and token, which store async employee and token, which you might say, wait, that's the exact you might say, wait, that's the exact you might say, wait, that's the exact same code as insert employee. You're same code as insert employee. You're same code as insert employee. You're right. But if you had loaded the right. But if you had loaded the right. But if you had loaded the employee and it had the ID in there and employee and it had the ID in there and employee and it had the ID in there and then you store it async and it says, then you store it async and it says, then you store it async and it says, "Hey, we got a matching uh ID." Then "Hey, we got a matching uh ID." Then "Hey, we got a matching uh ID." Then what's going to do is going to um try to what's going to do is going to um try to what's going to do is going to um try to to overwrite that. But don't do that. to overwrite that. But don't do that. to overwrite that. But don't do that. And here's why. And here's why. And here's why. Because if you do that, your model might Because if you do that, your model might Because if you do that, your model might not have all the properties of the not have all the properties of the not have all the properties of the document in the database. So you might document in the database. So you might document in the database. So you might have first name, last name, and ID like have first name, last name, and ID like have first name, last name, and ID like you do here, but the database might you do here, but the database might you do here, but the database might object might also have email address.
-
object might also have email address. object might also have email address. But if you were to download just the the But if you were to download just the the But if you were to download just the the model that you have and then upload it model that you have and then upload it model that you have and then upload it again, you would overwrite the entire again, you would overwrite the entire again, you would overwrite the entire document and then what would happen is document and then what would happen is document and then what would happen is the email address will be deleted. the email address will be deleted. the email address will be deleted. That's not a great idea. So here's what That's not a great idea. So here's what That's not a great idea. So here's what I recommend instead. This is going to I recommend instead. This is going to I recommend instead. This is going to feel weird. feel weird. feel weird. But it's not var dbre record But it's not var dbre record But it's not var dbre record equals await session.load async equals await session.load async equals await session.load async employee model employee model employee model employee id and token. Now I could have just id and token. Now I could have just called the uh load employee by ID but I called the uh load employee by ID but I called the uh load employee by ID but I wanted to actually have the the code in wanted to actually have the the code in wanted to actually have the the code in line and not be confusing. So this is line and not be confusing. So this is line and not be confusing. So this is kind of duplicate code and I would kind of duplicate code and I would kind of duplicate code and I would replace this with um just calling this replace this with um just calling this replace this with um just calling this load employee by ID. Um but again I want load employee by ID. Um but again I want load employee by ID. Um but again I want to make sure it was clear uh what we're to make sure it was clear uh what we're to make sure it was clear uh what we're doing here. Now if doing here. Now if doing here. Now if uh DB record is null uh DB record is null uh DB record is null then I want you to throw new exception then I want you to throw new exception then I want you to throw new exception and just a generic exception that says and just a generic exception that says and just a generic exception that says the record uh was not found to update.
-
the record uh was not found to update. the record uh was not found to update. [snorts] [snorts] [snorts] Now this load async can load a null Now this load async can load a null Now this load async can load a null object. Notice it's nullable which means object. Notice it's nullable which means object. Notice it's nullable which means if it's null then it didn't find the if it's null then it didn't find the if it's null then it didn't find the object to update. So therefore, somehow object to update. So therefore, somehow object to update. So therefore, somehow it's gone. Um, so we're just going to it's gone. Um, so we're just going to it's gone. Um, so we're just going to say, "Hey, that's a problem." But if say, "Hey, that's a problem." But if say, "Hey, that's a problem." But if it's not gone, I'm going to say it's not gone, I'm going to say it's not gone, I'm going to say DBrecord.name DBrecord.name DBrecord.name equals employee.irstame. equals employee.irstame. equals employee.irstame. dbrecord.astame dbrecord.astame dbrecord.astame equals employee.ast name. equals employee.ast name. equals employee.ast name. Now, you might look at that and go, "Oh, Now, you might look at that and go, "Oh, Now, you might look at that and go, "Oh, no, Tim. Please don't do this. This is no, Tim. Please don't do this. This is no, Tim. Please don't do this. This is this is mapping. We don't have to." this is mapping. We don't have to." this is mapping. We don't have to." Here's why. because we're taking the Here's why. because we're taking the Here's why. because we're taking the data that may have changed and putting data that may have changed and putting data that may have changed and putting it into the record that is now tracked. it into the record that is now tracked. it into the record that is now tracked. This record right here, even though we This record right here, even though we This record right here, even though we got from the database, it's no longer got from the database, it's no longer got from the database, it's no longer tracked because the session closed. tracked because the session closed. tracked because the session closed. Okay? So, if we load it from the list of Okay? So, if we load it from the list of Okay? So, if we load it from the list of all employees, that session closed right all employees, that session closed right all employees, that session closed right here after it returns the data. So, it's here after it returns the data. So, it's here after it returns the data. So, it's no longer being tracked. So, we had to no longer being tracked. So, we had to no longer being tracked. So, we had to get a new record based upon that ID.
-
get a new record based upon that ID. get a new record based upon that ID. That's the tracked record. Now we can That's the tracked record. Now we can That's the tracked record. Now we can update that tracked record with the data update that tracked record with the data update that tracked record with the data that we have changed. And now that we have changed. And now that we have changed. And now since this is a tracked record, all we since this is a tracked record, all we since this is a tracked record, all we have to do is just say save changes. We have to do is just say save changes. We have to do is just say save changes. We don't have to do any kind of updates or don't have to do any kind of updates or don't have to do any kind of updates or anything else. Just save changes. We're anything else. Just save changes. We're anything else. Just save changes. We're done. So now this record will be updated done. So now this record will be updated done. So now this record will be updated with the new information. Yes, this is a with the new information. Yes, this is a with the new information. Yes, this is a mapping process and so you have to mapping process and so you have to mapping process and so you have to update this with your mapping and this update this with your mapping and this update this with your mapping and this is where some people start reaching for is where some people start reaching for is where some people start reaching for automapper. Please don't do that. Please automapper. Please don't do that. Please automapper. Please don't do that. Please don't do that. But um you can just don't do that. But um you can just don't do that. But um you can just manually map this over. You could also manually map this over. You could also manually map this over. You could also put in your model a way to map from one put in your model a way to map from one put in your model a way to map from one model to the other. That would be a way model to the other. That would be a way model to the other. That would be a way to do it in the model itself. That's to do it in the model itself. That's to do it in the model itself. That's probably the most advisable way of doing probably the most advisable way of doing probably the most advisable way of doing that. That way you always make sure that that. That way you always make sure that that. That way you always make sure that if you change properties, you have right if you change properties, you have right if you change properties, you have right the mapping that will say, "Hey, you the mapping that will say, "Hey, you the mapping that will say, "Hey, you need to make sure you change this, too." need to make sure you change this, too." need to make sure you change this, too." So this is how I recommend doing So this is how I recommend doing So this is how I recommend doing updates. updates. updates. It feels a little weird to load the It feels a little weird to load the It feels a little weird to load the record and then update the record. You record and then update the record. You record and then update the record. You could do some patching if you knew could do some patching if you knew could do some patching if you knew there's only this property or this there's only this property or this there's only this property or this property is going to change. You could property is going to change. You could property is going to change. You could patch it um and save it without having patch it um and save it without having patch it um and save it without having to do this load first, but I don't think to do this load first, but I don't think to do this load first, but I don't think it's worth it in most cases. So this it's worth it in most cases. So this it's worth it in most cases. So this will do again remember the the session will do again remember the the session will do again remember the the session or the um the record count the um right or the um the record count the um right or the um the record count the um right here the number of requests the number here the number of requests the number here the number of requests the number of requests here is going to be two one of requests here is going to be two one of requests here is going to be two one to load the record one to save the to load the record one to save the to load the record one to save the changes so that is two as opposed to one
-
changes so that is two as opposed to one changes so that is two as opposed to one you want to get to close to one as you want to get to close to one as you want to get to close to one as possible I think in this case one or two possible I think in this case one or two possible I think in this case one or two is fine so that's how you do an update is fine so that's how you do an update is fine so that's how you do an update record again if you just overwrite the record again if you just overwrite the record again if you just overwrite the record that can cause some real record that can cause some real record that can cause some real problems. I'd recommend not doing that. problems. I'd recommend not doing that. problems. I'd recommend not doing that. All right. Finally, we're going to uh All right. Finally, we're going to uh All right. Finally, we're going to uh delete the employee. We're going to say delete the employee. We're going to say delete the employee. We're going to say public async uh task public async uh task public async uh task delete employee delete employee delete employee string just the ID of the employee and string just the ID of the employee and string just the ID of the employee and then of course the cancellation token then of course the cancellation token then of course the cancellation token token equals default. token equals default. token equals default. And then is that still on the clipboard? And then is that still on the clipboard? And then is that still on the clipboard? Yes, it is. Um Yes, it is. Um Yes, it is. Um good to go. So now we have our session good to go. So now we have our session good to go. So now we have our session open. We're going to say session.delete open. We're going to say session.delete open. We're going to say session.delete the ID the ID the ID and then await session.save changes and then await session.save changes and then await session.save changes async and pass in that token. So as async and pass in that token. So as async and pass in that token. So as delete pass in the ID to delete. You're delete pass in the ID to delete. You're delete pass in the ID to delete. You're good to go. It's all it takes to delete good to go. It's all it takes to delete good to go. It's all it takes to delete a record. Again, this does not we're not a record. Again, this does not we're not a record. Again, this does not we're not awaiting it. This is not doing any awaiting it. This is not doing any awaiting it. This is not doing any action. It's just queuing up things to action. It's just queuing up things to action. It's just queuing up things to do. This is where the actual call gets do. This is where the actual call gets do. This is where the actual call gets made. Therefore, again, the number of made. Therefore, again, the number of made. Therefore, again, the number of calls here is just one.
-
calls here is just one. calls here is just one. Okay, that's a lot of changes. Let's go Okay, that's a lot of changes. Let's go Okay, that's a lot of changes. Let's go over and in our program.cs, we now have over and in our program.cs, we now have over and in our program.cs, we now have the ability to make a call to this data the ability to make a call to this data the ability to make a call to this data access. So, let's say await data access. So, let's say await data access. So, let's say await data accessinsert accessinsert accessinsert employee. And we're going to say uh new employee. And we're going to say uh new employee. And we're going to say uh new and we'll say first name equals Tim and and we'll say first name equals Tim and and we'll say first name equals Tim and last name equals Corey. Cool. All right. last name equals Corey. Cool. All right. last name equals Corey. Cool. All right. And that's all we need to do. So let's And that's all we need to do. So let's And that's all we need to do. So let's make sure we have this as the startup make sure we have this as the startup make sure we have this as the startup project. project. project. And we'll run this. And we're done. And if you come back now And we're done. And if you come back now to here, we can come back to our to here, we can come back to our to here, we can come back to our database. We can see employees. Notice database. We can see employees. Notice database. We can see employees. Notice it plural employees. And we have Tim is it plural employees. And we have Tim is it plural employees. And we have Tim is 1. A cool. Now let's modify Tim. So what 1. A cool. Now let's modify Tim. So what 1. A cool. Now let's modify Tim. So what I'm going to do is I'm going to say um I'm going to do is I'm going to say um I'm going to do is I'm going to say um we we know the let's let's say we know we we know the let's let's say we know we we know the let's let's say we know what the um the value is for Tim, right?
-
what the um the value is for Tim, right? what the um the value is for Tim, right? So actually, you know what? No, let's So actually, you know what? No, let's So actually, you know what? No, let's let's put uh let's do a load for Tim. let's put uh let's do a load for Tim. let's put uh let's do a load for Tim. So, var employee So, var employee So, var employee equals um await equals um await equals um await data access dot uh load data access dot uh load data access dot uh load load employee by ID. And I think uh I load employee by ID. And I think uh I load employee by ID. And I think uh I don't want to guess. I'm going to don't want to guess. I'm going to don't want to guess. I'm going to actually pull it up. I am employees-1A. actually pull it up. I am employees-1A. actually pull it up. I am employees-1A. Let's just copy that. which mean I Let's just copy that. which mean I Let's just copy that. which mean I messed up my clipboard. That's okay. Um, messed up my clipboard. That's okay. Um, messed up my clipboard. That's okay. Um, there's my ID. So, we know the ID. We're there's my ID. So, we know the ID. We're there's my ID. So, we know the ID. We're going to look up the employee. Now, going to look up the employee. Now, going to look up the employee. Now, we're going to say employee we're going to say employee we're going to say employee first name equals Timothy. first name equals Timothy. first name equals Timothy. And now we're going to say await data And now we're going to say await data And now we're going to say await data access.update access.update access.update employee. And we're going to pass in employee. And we're going to pass in employee. And we're going to pass in employee. Remember, this is no longer employee. Remember, this is no longer employee. Remember, this is no longer tracked. So, we're not tracking this. tracked. So, we're not tracking this. tracked. So, we're not tracking this. Um, we're we're just saying, hey, and I Um, we're we're just saying, hey, and I Um, we're we're just saying, hey, and I know this could be null, but it's not know this could be null, but it's not know this could be null, but it's not going to be. Um, we're not tracking going to be. Um, we're not tracking going to be. Um, we're not tracking this. Therefore, this update employee is this. Therefore, this update employee is this. Therefore, this update employee is going to open a new session. Let's run going to open a new session. Let's run going to open a new session. Let's run this. And it should be just done. And if this. And it should be just done. And if this. And it should be just done. And if we come back over here, we'll see that we come back over here, we'll see that we come back over here, we'll see that um this is Let's refresh it. Now says um this is Let's refresh it. Now says um this is Let's refresh it. Now says Timothy. But notice how do I know like Timothy. But notice how do I know like Timothy. But notice how do I know like that a change has been made? Like what that a change has been made? Like what that a change has been made? Like what changes made over here? Here we can see changes made over here? Here we can see changes made over here? Here we can see revisions, but there's no revisions.
-
revisions, but there's no revisions. revisions, but there's no revisions. Well, that's because we haven't turned Well, that's because we haven't turned Well, that's because we haven't turned revisions on or revision tracking on. We revisions on or revision tracking on. We revisions on or revision tracking on. We need to do that. To do that, we're going need to do that. To do that, we're going need to do that. To do that, we're going to go to settings. We're in the to go to settings. We're in the to go to settings. We're in the database. We go to settings and down database. We go to settings and down database. We go to settings and down here there is document revisions. here there is document revisions. here there is document revisions. And I want to say, you know what? I want And I want to say, you know what? I want And I want to say, you know what? I want to add a collection to track revisions to add a collection to track revisions to add a collection to track revisions on. So, I'm going to choose the on. So, I'm going to choose the on. So, I'm going to choose the collection employees. collection employees. collection employees. And the maximum number of vision to keep And the maximum number of vision to keep And the maximum number of vision to keep a thousand's a lot. Um so maybe I do a thousand's a lot. Um so maybe I do a thousand's a lot. Um so maybe I do less than that. Let's just keep it down less than that. Let's just keep it down less than that. Let's just keep it down at 10. Um it's up to you though. The at 10. Um it's up to you though. The at 10. Um it's up to you though. The more you keep of course the more data more you keep of course the more data more you keep of course the more data you have. Although there is um you have. Although there is um you have. Although there is um compression on this to make sure it compression on this to make sure it compression on this to make sure it there's not like a crazy amount of extra there's not like a crazy amount of extra there's not like a crazy amount of extra data. But um we're going to hit new data. But um we're going to hit new data. But um we're going to hit new config. And now we have employees. We're config. And now we have employees. We're config. And now we have employees. We're going to keep 10 revisions. going to keep 10 revisions. going to keep 10 revisions. Let's go back to our Whoops. Sal page. Let's go back to our Whoops. Sal page. Let's go back to our Whoops. Sal page. Don't forget to hit save. I do that all Don't forget to hit save. I do that all Don't forget to hit save. I do that all the time. Hit save on this. Okay, now the time. Hit save on this. Okay, now the time. Hit save on this. Okay, now that's been saved. Now we can come back that's been saved. Now we can come back that's been saved. Now we can come back over to documents. Go to employees. And over to documents. Go to employees. And over to documents. Go to employees. And there's still no revisions, but let's there's still no revisions, but let's there's still no revisions, but let's let's change that. So, let's go back to let's change that. So, let's go back to let's change that. So, let's go back to our code. Let's minimize this. And you our code. Let's minimize this. And you our code. Let's minimize this. And you know what? We're going to say let's know what? We're going to say let's know what? We're going to say let's change it back to Tim.
-
change it back to Tim. change it back to Tim. Okay. And run this code again. Okay. And run this code again. Okay. And run this code again. The code didn't change, right? it. All The code didn't change, right? it. All The code didn't change, right? it. All it was was I changed Tim to Timothy or it was was I changed Tim to Timothy or it was was I changed Tim to Timothy or Timothy back to Tim. And now if we hit Timothy back to Tim. And now if we hit Timothy back to Tim. And now if we hit refresh on this, we see it's Tim Corey refresh on this, we see it's Tim Corey refresh on this, we see it's Tim Corey again. Cool. Um, so our document has again. Cool. Um, so our document has again. Cool. Um, so our document has been changed. And notice this this been changed. And notice this this been changed. And notice this this orange icon now for revisions. So we orange icon now for revisions. So we orange icon now for revisions. So we click on this and go to revisions. click on this and go to revisions. click on this and go to revisions. There's two. If we click this one, it There's two. If we click this one, it There's two. If we click this one, it says Tim Corey. If we click this other says Tim Corey. If we click this other says Tim Corey. If we click this other one, it says Timothy Corey. This is the one, it says Timothy Corey. This is the one, it says Timothy Corey. This is the previous revision. So this is an old previous revision. So this is an old previous revision. So this is an old revision. This is the new revision. And revision. This is the new revision. And revision. This is the new revision. And of course, you want to go back to the of course, you want to go back to the of course, you want to go back to the current document, you click here, and current document, you click here, and current document, you click here, and that's the current document. The current that's the current document. The current that's the current document. The current document is always the last revision. document is always the last revision. document is always the last revision. So now we have change tracking on our So now we have change tracking on our So now we have change tracking on our important records. Now, you don't want important records. Now, you don't want important records. Now, you don't want to do this in every record. Some records to do this in every record. Some records to do this in every record. Some records just don't matter. But you might want to just don't matter. But you might want to just don't matter. But you might want to change have change tracking on to see, change have change tracking on to see, change have change tracking on to see, hey, this record changed and this is the hey, this record changed and this is the hey, this record changed and this is the old values. You can kind of roll back old values. You can kind of roll back old values. You can kind of roll back changes if you find that necessary for changes if you find that necessary for changes if you find that necessary for certain records. So, that's how you do certain records. So, that's how you do certain records. So, that's how you do change tracking. Let's keep going here.
-
change tracking. Let's keep going here. change tracking. Let's keep going here. Um, let's You know what? We've got the Um, let's You know what? We've got the Um, let's You know what? We've got the the the person in the database, but you the the person in the database, but you the the person in the database, but you know what? I want to get rid of him. know what? I want to get rid of him. know what? I want to get rid of him. [snorts] So, let's do await data access data access employee. And we're going to delete uh employee. And we're going to delete uh employee. And we're going to delete uh employee. Actually, I think I have a employee. Actually, I think I have a employee. Actually, I think I have a paste pasted or in the clipboard. There paste pasted or in the clipboard. There paste pasted or in the clipboard. There you go. And we don't have to pass a you go. And we don't have to pass a you go. And we don't have to pass a token because we can just say ignore token because we can just say ignore token because we can just say ignore that. um it'll use a default token. So that. um it'll use a default token. So that. um it'll use a default token. So run this again. run this again. run this again. Done. So now if we come back over our Done. So now if we come back over our Done. So now if we come back over our collection, we don't have a collection collection, we don't have a collection collection, we don't have a collection anymore. Um all of our documents, anymore. Um all of our documents, anymore. Um all of our documents, they're all gone because um we don't they're all gone because um we don't they're all gone because um we don't have we've deleted that document. So have we've deleted that document. So have we've deleted that document. So that document's entirely gone. Okay. So that document's entirely gone. Okay. So that document's entirely gone. Okay. So that's how to use this kind of better that's how to use this kind of better that's how to use this kind of better way of doing things. This this is a way of doing things. This this is a way of doing things. This this is a better demo. Um, but it it was hard to better demo. Um, but it it was hard to better demo. Um, but it it was hard to build up over time as as much as I did build up over time as as much as I did build up over time as as much as I did in the original demo. So, this is more in the original demo. So, this is more in the original demo. So, this is more the kind of code I'd like to see in app the kind of code I'd like to see in app the kind of code I'd like to see in app real applications where it's doing the real applications where it's doing the real applications where it's doing the um I disposable and it's making sure um I disposable and it's making sure um I disposable and it's making sure that we have short sessions that only do that we have short sessions that only do that we have short sessions that only do one thing if possible. Um, and then we one thing if possible. Um, and then we one thing if possible. Um, and then we make sure that we're calling the using make sure that we're calling the using make sure that we're calling the using so it closes down at the end of the so it closes down at the end of the so it closes down at the end of the scope and we have easy oneliners for scope and we have easy oneliners for scope and we have easy oneliners for accessing our data in different ways.
-
accessing our data in different ways. accessing our data in different ways. There is so much more to cover with There is so much more to cover with There is so much more to cover with Raven DB, but we're going to end the Raven DB, but we're going to end the Raven DB, but we're going to end the video here. Don't forget you can get the video here. Don't forget you can get the video here. Don't forget you can get the $200 in cloud credits using the promo $200 in cloud credits using the promo $200 in cloud credits using the promo code I am Tim Corey. The details are code I am Tim Corey. The details are code I am Tim Corey. The details are down in the description along with a down in the description along with a down in the description along with a source code download link. Again, the source code download link. Again, the source code download link. Again, the email with the source code will also email with the source code will also email with the source code will also give you the info on that cloud credit. give you the info on that cloud credit. give you the info on that cloud credit. That way, you can just have it email it That way, you can just have it email it That way, you can just have it email it to you. Thanks to Raven DB for to you. Thanks to Raven DB for to you. Thanks to Raven DB for sponsoring this video and supporting sponsoring this video and supporting sponsoring this video and supporting thenet community. And as always, I am thenet community. And as always, I am thenet community. And as always, I am Tim Corey. [music]
Summary
This transcript explores Raven DB, a multimodal NoSQL database, highlighting its performance, ACID compliance, and auto-indexing capabilities. The practical takeaway is that Raven DB offers a powerful and free solution for developers, with excellent documentation and integration with .NET, and a sponsored offer for cloud credit is available.