In this episode, we dive deeper into advanced Rust development, focusing on asynchronous programming, multithreading, and SQLite database integration. We continue the practical development of a Rust-based application, exploring how asynchronous operations and multithreaded execution can improve application responsiveness, performance, and efficiency when working with databases. The session provides practical insights into managing concurrent operations, structuring database interactions, and building applications capable of handling multiple tasks efficiently using Rust. Whether you are an intermediate Rust developer or an experienced software engineer looking to strengthen your understanding of concurrent and asynchronous systems, this episode offers valuable technical insights. What you'll learn:
Integrating SQLite with Rust applications.
Understanding asynchronous programming in Rust.
Exploring multithreading and concurrent execution.
Managing database operations efficiently.
Improving application performance and responsiveness.
Understanding concurrency patterns in backend development.
Building reliable database-driven applications
Audio and video play straight from the show's own hosting. PodSubs stores and serves no media.
Transcript
From the show. Tap a time to play from there.
Speaker 1Okay so we should be live right now i'm going to post it on my twitter post on my discord post and today here what we're going to do is another one of this ad hoc live stream and that is the second one of the day in a way i mean in a way not in a way and The things is the ad hoc live stream is code that I need to do anyway for myself. And so
Speaker 1I'm sharing it live with the things, public for live streaming, 12 hours, then early access for two days, then the live stream members for ever. And then live stream members also have other kind of production live stream schedule live streams about production things, Rust on the cloud and so on. But this one is the ad hoc live stream, and this is videos that I'm preparing, which is the Rust
Speaker 1with SQLite. So it's pretty cool. And so there's all the XP, the Rust SQLite XP, like I like to have, and this is a part five. So there's already quite a bit of things behind us, and I'm going to review it a little bit of the code. So like this, you can understand a little bit what we have. So that is a goal. And if we go, Look at the code. This is what we have done so far. We have the C1 example over there. So I'm going
Speaker 1to do just a quick overview, which is basically the connection. We open the memory. We have the connection to create a schema. Make sure that we create strict. We have the execute. Create the statement. And then we are doing a select. So this is what we're doing right now. And the cool thing here is in the chat, I've put the things that you can, the GitHub, so actually this is already pushed in the GitHub, and this is
Speaker 1the topic of the day. So today we are going to review the async multithread. So in the previous example in the GitHub, you have the C01 simple, the join, the values, the JSON, and then the JSONB. And again, I'm going to do a video of that I'm going to explain everything. It's going to be a relatively short video. So that is going to be the goal. So today, one of the last chapter I want to do in this learning is I want to do the multi-threaded. So
Speaker 1everything that we have used right now is a single thread. Yeah, or single process, single thread. And there's no async, there's no threading. And basically we create a connection and then we do everything within the stuff. With SQLite, there's a couple of interesting things about multistraded and async and so on, because you have SQLite that has its own thing, and then you have the Rust Qlite, which wraps SQLite, which
Speaker 1has its own recommendation. They're actually very good. So we're going to learn how to do that. And the best way, I think, We could do thread or we could do async. And usually when you do one or the other, it's kind of the same kind of thing. So we're going to do the async. And for that, we're going to copy this file. We're going to call it C06. And we do async. That is, in the world of Rust,
Speaker 1it says enough. So now we have the things is we think with VS Code where you create a file, you have to click again to not have it, to have the correct opacity. This one here, so there's a whole strategy that I have when I do this Rust XP SQLite, is this is what I'm using for myself. So even for myself, when I learn SQLite, I actually have a Rust XP SQLite JC where I do more stuff.
Speaker 1with ModQL and CQuery and so on. But that is a way that I learn, any new crates or whatever. So the way that I do is step by step. And the first one is very simple where I do everything in line. And then I have the crate, which is actually a lib. And that allows me to have some new tiers over there. So I have my DB prints, and then I have my seed, such as I don't have to repeat that all the time. and such as
Speaker 1a code there can be very tears into the what I'm trying to learn. So if you look at the other example, I took simple because we don't need just and be joined and everything, we just need to learn the multithreaded. But if you look at anything else, now I'm using the connection, which is fine. And then using this guy here, which is a create schema. So like this, he created schema. And if we look at it, he create org. and a person. And this one is just a silly one, but it was to show that I
Speaker 1have a money to one. That was a goal. So this is the thing here. Let me check something. Yep. And then we have that in us. I think now. So we're going to use that. So like this, we use the thing that. And we're going to insert I deleted too much here, I think. Oh, yeah, OK, no, sorry.
Speaker 1I'm getting confused here. So I'm going to have the create schema. So that would create the schema. And the way I'd work, I like to work. And so this will work below. I need to import that, obviously. So I import it from spsqlite and dbutils and everything. So I import that. One of the things that I like to do is, so for CargoTest, I use CargoTest to,
Speaker 1CargoWatchTest to test. Beacon works, but BeaconTest do some stuff with a no capture that sometimes makes it hard for me. So I still use CargoWatch. So I do a Cargo, CargoWatch dash Q dash clear dash execute. And then I do a run-q quiet example, C0106 async. So I like to do that, and that will print the stuff. Like that,
Speaker 1when I can change things here, if I change the number here and I say, Boom, I have the new one here. So I'm happy. I can learn very fast like that. So everything I do, when I learn, I do a cargo run examples. When I code in production or in the library or something, I do a cargo wash test. And all the time for me is to do this kind of debug print. This is the thing that, which by the way, I might change because that sign might be used for SQLite or even Postgres JSON B
Speaker 1kind of things. So I want to be able to search that and remove that when I do production coding. But that is a way that I like to do. By the way, if you have any questions, feel free to ask questions. I'm more than happy to take any questions. And then we have the select over there, and then we have the while here, row, and the next. That goes, and this is why we have these two guys, and then I use a little utility, print, table that I
Speaker 1have over there. So within the this kind of GitHub repo to learn, I have this little utilities, which is a print rows, which is the one at the bottom. And then the print select user print row, but does a select statement. And then this one do a print table. So like that, it allows me to do that. And here the print row is pretty cool is something I could review. Also, I think in the video, I will explain it. But In short, I do the statement, and
Speaker 1in SQLite, when you do the statement, you can get the column names, and that is what I use to format it. And then I put it in a row cells. That is not row like database row. It's a row from this guy, tabled, which allows you to do that layout. So it has nothing to do with SQL, yes? If you give him a set of rows and cells, it will lay them out like that. So it's nice, it's
Speaker 1nice to see. So that is the only kind of trick I have. And so that allows me to very quickly when I press save, I can see the result. So everything works fine. And actually we did a very cool stuff. We did the simple to join the value. So that is when you want to own the value and you want to have dynamic SQL. And then we have the JSONB and then the, json and now it's at json. So one thing that we're going to do
Speaker 1is we're going to take the values over there and this is a good one. So it's a hack it's not a thing but the goal here is I have this name value list so that is a name and that is a value. Eventually that will be part of other SQLite kind of things. You want to be able to have that from a struct. So I've developed a mod qr that allows you to extract that from a struct. There's also cQuery that allow you to have a SQL
Speaker 1builder with this kind of thing. So regardless of how you do it, At some point, you are going to have a list of column names or column identifier in C query and a list of value. That is not a JSON value. That is a Rust QLite value. So in Rust, every time we have a system talking to another system out of Rust, other types like JSON, like a database, like whatever, you often have the pattern of
Speaker 1a value which is the one in between that will you know translate the type of here sqlite from the type of rust and then you do all the from and into that goes well such as you can do that so for example in sqlite we do not have integer we don't have boolean sorry so what it does here to say hey if the value If it's a Boolean, then the value will be actually an integer, which will
Speaker 1be i, which is interesting. It's just use the Rust system here, which is right. And then it does that. And then boom, it has i64. So that is the way it does it. It's putting it. So we have that. And so the thing that I want to do when you test for async or multithread is about the same thing. because you need to make sure that you think and share. You need, one of the nice thing is to have this kind of things where we're going to have, let
Speaker 1me think about it. Do we need that? Yeah, we're going to need that. We're going to use it anyway. So, I'm just thinking, do I need that to add this complexity? So in my code, I will have that. But perhaps we don't have to have that now. So let's not have this now. So we're just going to have that.
Speaker 1And now what we want, we're going to do, let me think. So in the join here, we had this thing. these names, and we just enter the name, then the org was zero or whatever, it doesn't matter. So we're going to do that. We can remove the French team here.
Speaker 1And then we're going to do a for names, in names, name in names. And I'm going to do I'm going to do... So the thing here that we're going to add for the async, and I could have done that with threading. It's the same thing, more or less. So I'm going to have, I have a Rust Nx extension,
Speaker 1which has all my snippets like this. I don't have all the time because I write a lot of code and stuff. So I say group sync, and that will give me my Tokyo. So That, I get that. And once I can get that, I'm going to do here, Tokyo Main. Okay? So far, so good. And, sorry, I need to do an async. And you're going to see, right now, we're still happy, but we're not going to
Speaker 1be happy for long. So we do names, and we say, hey, we do the connection over there. the connection that we have shared and we are going to insert name and we're going to insert name and the year of birth is going to be everybody is 2000 we don't really care and then we have the select at the bottom and we print that's it yeah so we have when
Speaker 1we do the select we do everything and everything has new doesn't matter that just if we make that works i think then everything would work Typically, what I will do at this point, I will create another one, a JIT log to see what we have. And then, let me use annotation, okay. JIT C. And if you want to have in my chat here, you have this guy,
Speaker 1which is here. That is a GitHub. So if you want to see that and run the same thing I'm running, I'm going to push it right now. Prep C06 async. Prep before async. Okay? Until my notation is to say work in progress. So far so good. Push, boom, you'll have it on your side. So, ah, sorry. git add,
Speaker 1forget about that. git add. I'm going to do a git forceful amend. It's an alias, git gpo force. Not nice, but anyway, I don't think anybody kind of put it already. So now I have this one, and now we have this. But what we want, and here we do select, let's say that the insert, we want to have many things inserting at the same time. So, we are going to say, okay,
Speaker 1we can do that. We are going to do Tokyo task. Task. Spawn. No. Oh, this is funny. Spawn. And then we have this and we're not too late i think move okay so we did that this guy did that copilot press save and
Speaker 1complain here on the error one i'm going to log the error right now just going to do that okay so we do the print and we do here and we're going to do here while insert again the goal
Speaker 1here is just to learn yeah to see how we can do that so for every name we are spawning a new task now i'm forgetting something here which is the await okay and now he's complaining because he's telling me that the connection has been moved okay that's fair
Speaker 1because we moved it there so we're going to say okay and we're learning here huh interesting and think about this guy Okay, here's my problem. My problem here is I did the open in memory. The reason why I did the open in memory is because when we learn
Speaker 1everything else, it's very nice because the create schema doesn't have to worry about if the schema is always there. We start from scratch. Now, to learn the async await is tricky because If we, the right way of doing it is to open, and then this connection pulling us up. That will be later. But it will be to open another connection. But I don't think it's open, it's not possible to open another connection into the same, into the
Speaker 1same memory. That will be, that will be interesting. So if I do a connection, and I don't think that, Connection has clone. It doesn't have clone. So, the trick is, what I will need is to do open. But you are going to see here. And we are going to say, open my DB. db3 i'm going to press save now
Speaker 1i have a connection there so i'm going to say const db And that will be this guy. And that will be this guy. Hey, Roberto, how are you doing?
Speaker 1So question here in a project in which I was using ORM feature. Yeah, only way to do. Go async in the database connection is to use a pool manager. Yeah, Deadpool or stuff or there's R2D2 as well. And then there's a connection. Yeah, so in this today here, I want to go a little bit deeper than that. I want to do a bottom up. So first I don't use ORM in this kind of things. And I'm not
Speaker 1saying database pool is not needed in some cases. I'm saying that there's a progressive way. And in fact, if we go, hey, from the Philippines, if we go, there's couple of things here that are pretty cool. So let me show you. So if we do a SQLite multi-threaded,
Speaker 1don't worry, I will make it bigger. Using muting CSS, so this is, so every time you see the documentation of SQLite is gold. Those guys, they really know how to do their stuff. So, here's the things. You can read that, Google that, it's very simple, you can read that. And this is an important one. It took me a couple of times to read it, to understand. But in short is, you can compile SQLite to be single-threaded. And in this case here, everything is visible and you better,
Speaker 1access to data only with one thread. Good news is Rust allows us to make sure that we are thread safe. And in fact, the connection of Rust to Lite is not shared. So we have to put it behind a mutex if we wanted to reuse it. And I think that is a very smart decision. And we are going to look at, in fact, is the developer of Rust to Lite really know his stuff, and then he's going to give us very good advice. Then, My understanding, and
Speaker 1it's not something I've compiled, is that, yeah, yes, you will see, even if I go, the connection won't be available. I agree. But I'm explaining first. So first we have SQLite, which is in C, which is compiled and embedded into our Rust. So SQLite has some multithreaded capabilities. And so if you compare it with single thread, then there's no multi-thread,
Speaker 1you better, otherwise everything crash. Then you can compare it with a flag, which is SQLite thread safe. Okay. And I don't know what the equal one will be. But
Speaker 1in short, these two guys, the difference is when you are in a multithread, it's multithreaded, but the connection is only one thread. Otherwise it doesn't, it won't be nice. Yeah. And then if it's a mod serialized, then the connection Connection can be shared. Okay? This is what they're saying there.
Speaker 1Across threads. And then they implement their own mutex. But since we're in Rust, we already have the mutex from Rust. So in fact, if we go to Rust Qlite, which is what we're using, and we're going to go open flag. Hopefully that will be boom to the right doc. So here they say is when you open a database, you can give flags and flags is bits. Yes, you decide what you want. So you have all these kind of
Speaker 1flags over there. And this one, I'm not really sure, but I mean, we read the doc, we can understand it. It's pretty good there. And this is a default. And if we look there, This is what we need to take for granted. And I can see, so here's the thing is, by default, this is not the open full mutex. It's not the default that is opening. It's not opening
Speaker 1like that. And it's explaining here that this flag should probably never be used with ResQlite as we ensure that ThreadCity statically we implement send and not sync. So in a way, because we're in Rust, we can guard across all of this. And so we don't have to pay the taxes on the mutex on the SQLite side, because we can manage it the way we want on the Rust side. So that is what basically saying, and then
Speaker 1even it goes deeper saying that actually sometime it's not super reliable So the mode serializable is what we're calling full mutex kind of things. So in short, and this is why Roberto, you had to use DB pool and everything by default, because in short, the good way of using it, this guy, it's easier, you create a new connection. So it's compiled with multithreaded. I'm 99.999 sure here with
Speaker 1everything I'm reading. Because otherwise, if you compile with single-threaded, you cannot upgrade to this guy. So when you start the connection, you can decide which one you are, but then you cannot upgrade, you cannot switch it. That is what they are saying there. And so the point is that we are basically multi-threaded. This is what I'm understanding for everything by default, and we shouldn't goof around too much. with that. And then after we can optimize as we
Speaker 1learn more. But by default, we're going to have one thread, one connection. And then there's multiple ways of doing it. And so usually when you use DB pool connection, you will use their way of managing stuff, which they will have a way to enforce that one way or another. So that is a trick. So now if we go back to our code here, and I'm going to fix
Speaker 1the connection error. So now we have that, but I have another problem now. And my other problem is, so let's say that even if I didn't want, so I'm going to remove that for now. So I'm going to remove this guy. Hopefully you're going to know why. That should work. Compile now. And I'm happy. Compiles, create the
Speaker 1tool and everything. Okay, just to make sure that with file it works. But you are going to say, if I press save again, it's going to fail. Because the database already exists. So I do a create schema, but I didn't have the logic if not exist. So I don't know if there's something like that. Okay, so what I can do, and I'm going to show you how I work. I have my, and you can, So chapgpt, the chat, the copilot chat is very annoying because it
Speaker 1tried to be too smart and by too smart, he's too annoying. So I prefer a little bit dumber and less annoying than smart and very annoying, at least for machines. And so the thing I'm saying is to say that I'm going to take this guy and I've done my little Dev AI, I've done a video about it, but basically I have these things where I can do dvi run craft code okay so that's my way of running custom agent that is installed by default that are craft
Speaker 1code an agent is a markdown file with some lua and everything so it's pretty cool bottom line is it will create a file which is craft code which are already there i'm going to change the context i'm going to say i have this i have this in sql for sqlite how Can I say to create only if, and I know that Postgres is possible, I don't know in SQLite it's possible. So I have two choice, go
Speaker 1to the doc or go to AI. Those days, go to AI first, you don't trust it, you go to your doc and you trust it more. So the doc, I don't know how long it's going to last. But the doc right now, typically, sometimes they are out-of-date, but typically they are created by the author and at least there's less hallucination. It can be outdated, but at least it doesn't hallucinate. today, because tomorrow is all going to be created with AI. So how do I, how can
Speaker 1I say to create only the table if it is not there. And then I do that. And then boom, and here I'm using deep chat. And I'm lucky I have this guy. So that is pretty cool. So I'm going to take this word for granted. The cost of error is very low. So I am okay. I'm going to my seed. I'm going to add that. I'm going there.
Speaker 1I'm going to add that. So obviously if I change the schema, I will delete the database, which I have it here. Now, the way that I have in the githing all the time, yes, semi-PG is true. But I didn't know, and I wanted to show off my DVI. But I like, it's a joke, because I would have done that anyway. So, because in fact, I don't remember that by heart either. So, I do that, I come back here to this guy, and now I can go
Speaker 1back to... This guy, I don't need that. I don't need the JSON B. I don't need the cargo to ML. I don't need the value. And I'm going to keep that. I'm going to press save. That shouldn't work. If. Okay. Did I stuff? Correctable if. Oh, yeah. Then I fault.
Speaker 1I don't know if that. Dev AI is... I'm not taking the bait. Create table. Dev, I'm joking. If you get me started on Dev AI, I can do three hours on Dev AI. Okay, cool. So I did the wrong copy paste. So it's not AI's fault, it's my fault. So now I can do this. And why do I have all these guys? I don't understand why I have four. I'm sure there's a good reason for it. And go
Speaker 1back there. and why oh yeah i'm sorry because every time i uh i add the database so if i do it again it's going to create again and stuff so i don't want that correct so i'm going to back to my craft code wow okay okay this one i can be a little bit uh I'm going to
Speaker 1go there. And again, this seed stuff is just discrete schema is just for me to do this learning very fast. So this is not the way I will do it in production obviously. So I'm going to do a con, connection, execute. And I'm going to do, so this one hopefully delete from org. And then I press save. OK. That's fair enough.
Speaker 1And bing. What am I doing? Oh, yeah. OK. This guy take another argument, which is the params. And I can put that like that. Boom. So clean the orgs. And I'm going to clean the users, the persons. Boom. OK. Now we're back to start things. I make sure that I'm not going to, so I don't type that all the time. I'm not crazy. Attack CW, E. Oh, no, no,
Speaker 1bacon run, because here I like bacon. It has a little flash for the example. C01, simple, not simple, I'm not using create, join to make sure that I didn't break join. Fair enough. C02, boom, I didn't break it, so it's good. So I didn't break the create. So now I'm going to do C06. I sync. Boom. Then I have these things. It's great. Go back there. I
Speaker 1don't need to do that. If we are here, we are pro. We're doing the select. It's okay. In fact, you know what? I don't even need to do that. That was to learn how to select and then debug print. Okay. Boom. have this so we have the two table here which is the things so i'm going to go back log
Speaker 1and i'm sorry guys i'm going to do a git amend gpo false so i'm being mean here it's just that i don't want to have see this thing so if you do a git pull get a git pull force or whatever it is And then you don't do that obviously if you have production code because it gets annoying. So then I'm going to do this one, BIE, boom, I have my select, I'm happy. And now, so now it's cool, yes? Because we have our database business. We
Speaker 1are creating the connection, but if it's already created, it doesn't complain. If it's not there, if I delete that, press save, it will, boom, create it. Everything is fine. So it's beautiful. So now what we want is to say we want to do this guy. Correct? Oops, sorry. I don't know what I did. Oh yeah, okay, what I did is this. We want to do this guy. Now it's going to complain. because it's going to say
Speaker 1the connection staff. So it's fine. We can create a connection just before. So here I'm learning the bottom up. I'm learning how, what can I do with a connection? So now that we read in the doc that this is not, the connection is not shared, you shouldn't staff, and it's a rough business to make sure that one thread, one task, use it at a time. So we're back home in a way. So, now if I pray thanks,
Speaker 1this is going to complain. We solve this one sometime. I don't know, I think it's Russ as well. It doesn't show all the errors, so we think, oh cool, we're going to solve that and we're good. But no. Because in fact, the connection is move on the first loop, but then... is reuse again so if we didn't have a loop it would have been okay yes if we didn't have a loop like that i hope it was going to be okay not going to look smart but if i do a let name and we are going
Speaker 1to do a name one or name zero sorry i'm not in here names then that works i complain and say you know you're silly But it works, and then I see the stuff there, okay? And by the way, when I do code, oh yeah, okay, this is another type. Oh no, no, when I do stuff, I like to uncomment this one, such as I don't see this error. However,
Speaker 1before I commit, I like to turn it back on, because the Clippy and stuff is amazing. So I always like to have them. So then I have the insert person and stuff and everything is working because I don't do a for loop. The problem is as soon as I do a for loop, well, I move the thing to one loop and then after I have the second loop and then I move to the other loop and then it doesn't like it. And I think if I do that, it's not going to be over smart. It's going to, even if it's static, it's not going to
Speaker 1count the guy. So it's going to say, no, you cannot do it. So, and this one, we should remove that. So the trick here is we can say, okay, our fail. If we want to learn, we say, well, actually we're going to do so every time what they're saying actually. So this would be a file. And one way we can do it is every time we use it, we do like that. And on this guy, we're not going,
Speaker 1we're going to do, This one is a tricky one. If that is smart enough to move and to not move. That is pretty good. I don't like to put unwrap. So I never put unwrap anywhere. That's just my style. Because I don't want them to bleed into my whenever I copy paste. I understand what they have unwrap. It's
Speaker 1a little bit unfortunate that all the examples and everything are doing unwrap and expect because then after, if you leak an unwrap, in your production code, guess what? You're back to unreliable. So you are using a super reliable language, but then because you copy paste all these examples, then you are back to, I'm a little bit dramatic here. You're back to JavaScript. Where things crash, or back to whatever, or C, or whatever, where things crash. Not because it's not memory safe, it's just because we haven't wrapped. So
Speaker 1there's one thing here which... If I'm going to use res... I need to think about Merle. Yeah, yeah, it's a little bit of a thing, but you know, everything is always a net value. I'm not a game developer, but the few things that I played with, and I did a video a long time ago about Baby. Baby is
Speaker 1very cool. I mean, I'm not a game developer, but the way it works with the components and stuff. And in a way, Axiom is a little bit like Baby, but for web app. And so it's a very cool pattern. And I've done the JSON RPC crate, which follows the same injection. So a lot of stuff, injection stuff. So here, the thing I'm going to do is I'm going to do something like that. Okay, we're going to do that. Earth. I'm going to use the thing else. This is a
Speaker 1good one. This is a good user. So okay. And we're going to do a print. An error. And again, this is not production coding. Usually what you have is You don't run tasks like that. It's made into a framework. You take the result back and then you like do the thing. So yeah, I'm going to show you, but that is what typically you do, yeah. So you wouldn't
Speaker 1run it like that. So error while open connection. In fact, you know, yeah, because I need to get out. Then we don't know the error. So that's why, yeah. Yeah,
Speaker 1that's why it's some, this pattern is good, but here we don't know the error, but whatever. So now let's go, but everything works, you see? And so, yes, we open a new connection. We have things here. We can have... I'm just thinking. I'm just thinking for... We're going to
Speaker 1do another one here. For 110. we're going to go a little bit crazy for 110 and then we're going to say let name equal format And here I'm building
Speaker 1the example. So when I'm building the example, I'm trying to think about what I want to teach. And even for me, like in this mode, I will have enough for me, but then after I want to show what I want to teach without adding too much complexity for each item. So that is what I'm thinking. So I have the name of the guy and then I'm going to have the ID here. That is going to be the new name. So that should create quite a bit
Speaker 1of people now. Now, he created all in order. Why did he create it all in order? He created all in order because we always do another wait here. So every time we do this guy here, we are going to actually wait it until we do the things. So the right way of doing it is will be to add it the future. So one thing that I didn't like about this is, yeah, it's tricky because I need
Speaker 1to tell the error now. So I cannot return a box din. That's the trick of the, I'm thinking. I'm thinking, okay, here it is. We're going to do it like this. So this guy here, I wait over there, and we're going to want to have the response to be a result of, what does this guy return? Okay, useSize, which
Speaker 1is a number of items that has been updated. So useSize, that will be the guy, and string will be the error. So like this, I don't need to be too smart. So now I'm going to say, that I'm going to return the error. Well, actually now I can be much nicer. I can do the map error. So I will do a let con, and then I'm going to have copilot
Speaker 1trying to guess. Does it get it? No, because you cannot do that. You cannot do that because you wouldn't return. So this one here, Then map error. That will be the error, which is whatever it is. And then we
Speaker 1can do an error toString, because we know that the error always have toString. And then we do a question mark. That should work. And here I need to fix this one, which is a map error. I'm venturing a little bit here. I hope I'm not hallucinating. air and then i'm going to do an air to string i have a connection
Speaker 1oh yeah okay okay yeah that's fine uh which is um new okay new whatever your size okay No! I'm doing something silly here. Why I cannot have this? I'm
Speaker 1doing something silly. I'm not too far. I'm going to do that. This is silly. I think this is the one he wants. I'm not understanding it. I am not
Speaker 1understanding it. There's something I'm missing here. I'm messing up
Speaker 1something silly here. I think might be fixed using Copilot, but this is it's never working this never works it's fix a copilot okay so I'm going to do this
Speaker 1okay I'm going to go back to my guy to what I think my stuff and I'm going to copy paste I'm not going to be, I'm missing up something silly here. So I'm going to go to my craft code business. I'm going to do that. Well, I'm valuable
Speaker 1in experience. I would be happier if I would look smarter, but that's fine. I have this in Rust, but somehow the error return in the spawn doesn't match. Can you fix it? And now we're not going to goof around. we are going to use and it's super cheap we're
Speaker 1going to use dvi we're going to use the reasoner let's go crazy run oh sorry run there's something here silly that i That is sometimes a little bit. In this error stuff, that is where I get tricked sometimes
Speaker 1when you have this closure stuff and you have to return errors. And there's some neat trick here, but sometimes somehow my brain kind of gets the stuff. And I need to get better at it. And I think I will do an agent. I'm going to do an agent about that. Like this kind of thing. Because when I see it and I say, oh, I'm so done. But there's something here. There's some things where somehow it doesn't see all the errors. If all these guys, so I
Speaker 1don't know if I can do a cargo fish there, but then I will need to put the future stuff. So I don't know how the thing is going to go. So this is why I did the print before, but like, since this live stream is about, it's not about the final, I mean, I'm going to do the video where I'm not going to spend all this time, obviously, and explain, you know, how the thing works. But right now I
Speaker 1want to find a semi-elegant way to do that. And it's cool because when people see it, it's like, oh, okay. And even me, I say, okay, this is a way to do it. Yeah. So the thing I don't understand is that I don't understand why I have the num here, which is this guy. So I'm going to do unwrap. I don't like unwrap, but I'm going to do just the unwrap now, just to split the problem. And now
Speaker 1to see the type. I get error. Why do I get error? Okay, okay. I'm going to put... Then I'm going to do noon like that. Now that works, but the unwrap, I can't commit or show code with unwrap. This is not a thing I do. Let's see. I
Speaker 1think the guy is done now. So in my prompt, I say don't explain. I would have loved that it explained here. But let me see what it does. It is a connect. It is a staff. OK. I don't think it solved anything. Am I missing something? I forgot to do that. It's giving me the same code. Are you kidding me? Oh no, he's giving me that. Hmm? No,
Speaker 1I don't think that that is, that sounds off. So my stuff works here and he gave me that. Yeah, it doesn't work. It doesn't make sense. Yeah. So I'm going to go back to my guy. And then I have a result of fling. I'm going to do a flatten here, and I will go back to this guy.
Speaker 1I think I can, no, I cannot do flatten. This is annoying. I don't understand why I don't know. I understand. I understand. I'm sorry. It's my mistake. Okay. I'm silly.
Speaker 1I knew I was silly. And that is a problem with Rails sometimes. This is my error. But the Tokyo spawn here. Okay. This is a thing. Sorry about that, guys. This is my error. But then it returned a drone hang. But the output is an error, I think, regardless. So the output is an error. So in the case of output, and the type is hard to find, but the output
Speaker 1is an error. So the errors that I get here, this is, but if I go, sorry, if I go there, I cannot have it. Let me see. John error, okay? So this is the thing. So that is the thing. This is where I got confused. It has two errors. It's normal. So I was not drunk. So I can do...
Speaker 1Can I do a question mark here? Yeah. Yeah, that works. That's cool. Okay. And sometimes when you spend time like this, understanding silly stuff is a good time. I mean, a good time. I enjoy it, actually. So this is a reason I was expecting this to somehow return my error, but it doesn't. It's normal to be a... This is a result of the spawn, which is a join, which
Speaker 1has a staff, and that is mine, which is fine. And then I will have two kind of question marks over there. So I will have one, which is this one, and then one towards the staff. And then I have my user side. So I'm happy with that. Boom, I get that. That works nicely. I don't know why sometimes I'm silly. So staff, so this one works, and then this guy works nicely. And then the guy will say, hey, why do you do that? You're right. And then that's it. Okay.
Speaker 1Back in business, sorry, I made my life too hard. So this is why we have two question mark. One to remove the join, the error for this guy, and one to have my wrap error or my result. It just happened that what I return is an error, and because I made sure that everything is a string, then I am a happy kid. Yeah. So that is what I need to do because otherwise this is where the question mark kind of stopped working or you need to do cargo fish and it gets tricky. Okay, so now
Speaker 1we are this and now everything works. So if we go back there, so the reasoner is not reasoning so well. So now I have this run, I have all these guys. Sorry about the chat here. Ping me when I have the chat that is, I like the chat. But sometime I need to move it there. That's perfect. And stuff.
Speaker 1So that's one way of doing it. And that is actually, hear me out, that is actually what's happening when you use ORM stuff. The only difference is that they have a connection pool and they keep the stuff. So that is one way to do the async. of the multithreaded, is you create a new connection, or you can do a mutex, basically. Or you can do a dbpool. So
Speaker 1that is the three options. If you look at the dog, which I like a lot, And this is, I mean, this guy really knows what he's doing. That is another thing with Rust ecosystem. It's, I don't know. I feel that the developer, many developers are top-notch. And so explain here that, you know, don't assume connection is thread-safe because
Speaker 1if you read the literature, it will say, well, this is thread-safe and stuff, but it's not. And he actually make, connection in the rush side, he made the connection not thread safe. Not thread safe, sorry. It's thread safe because it doesn't allow multiple things. So it does the right thing. So to accept the database, you should create a multiple connection, which is what we did, or for a thread, which is what we did. We did for his task, which
Speaker 1might not be a thread, but there's no way for, the Rust to know, so it's treated basically as a separate thread, even if it's in the same thread. And if you have many stuff, here's the thing, wrapping the Rust-QLite connection in a mutex is completely reasonable. So I've done kind of an application stuff, and my go-to way
Speaker 1to do this And I might create two guys here. I think, or perhaps I will call them threads, I don't know. But I don't want to call them threads because people are going to say it's not threads. So there's this way here, which is fine. And so we can connect it like that. And we can say, what can we say? JIT add. JIT log. I'm not going
Speaker 1to do a JIT plus def. I'm going to do, So behind the scene, it's SQLite that makes sure that when you create a connection with the staff, he keeps
Speaker 1track of everything. So that is what is working. There's a multi-process staff, which is another thing, which is if you have two processes, no way for them to communicate. I mean, that would be overkill and people don't do that for the database staff. And so if you have two processes updating the same file, there's some support in SQLite, but then you get into a danger zone in a way. which is tricky sometimes because sometimes, you know, you want to use one for all, but they have a kind of a lock and all these kind of things. For write,
Speaker 1they have a write ahead log, but that is not making the multiprocess fail-proof either. So there's a whole thing there. So that's one way. The way that I will do it, yeah, I will, the way that I do it is, so first of all, my style is I don't use ORM
Speaker 1because I don't want my types to be the exhaustive representation of my database. Database is king, and my code is not peasants, but, you know, in between, the noble, as we would say, call them in French. but it's not the king. The king is the database. And so I manage the database with a database language. And when I talk, I want to talk SQL to my database. That is how I update my database. I migrate my
Speaker 1database and everything. That's just my way. So for me, I don't want to have my types and then having some super cool libraries that say, hey, you know, because you annotated this one like this, we're going to update the type of the database and stuff. That is not the business of my code. What my code is, is a view on the database. and a partial view. I don't need to be an exhaustive view. So this is what the approach often I'm taking with these things. I'm
Speaker 1not saying if ORM works for you, it's great, but this is what has been working very well for us. So typically what I do is I might use a database pool, but my first step is to do a C0, seven so i don't know if i'm going to have that for the the db but i will do a actually i'm going to do something like that and i'm going to do a c07 and then i'm going to
Speaker 1do db manager yeah okay or whatever it's called and i'll go back to this guy we'll see if i can find a cooler name later but c7 db manager okay now okay it works because i didn't do anything
Speaker 1new now the thing i'm going to do on this one is i'm going to go there and this is where i will i will create it this way okay I will flatten it out for now, for this use case. Actually, I'm not going to call it here. Because in a way, this one is my DB utils, dirty stuff that I
Speaker 1don't need. And I will create a PubModDB. And that is the thing that I will use in a... That will be the beginning of what I will use in my production client app or whatever. And I don't use that in the cloud. If I use SQLite in the cloud, it's for the edge. So if I have one process and I want to store data and I want this process to go and look quickly on the database or even in memory perhaps or whatever, I will use SQLite. Otherwise,
Speaker 1I use Postgres all the time. But in Postgres, I have a similar kind of things where Regardless, whatever I use, if I use RRA, I always have an abstraction layer. One is a model layer, which we don't do here because we go directly. And the other one is what I call the store layer, which has a database. So in fact, I could create store and everything, but whatever. So I have the database there. And then over there, what I would create is a pub struct DB. Okay. Okay.
Speaker 1I will create it as with path. And I will do an option of path birth of string. And then I will say, well, this guy is an option because if none, then in memory. So I will do my little abstraction like that. And actually, I will do it. So now that I understand the raw things, I know that I have a couple of options. One is to
Speaker 1create a new connection all the time. That's not really cool because my code shouldn't worry about that. I want the abstraction layer anyway. So I'm going to create a DB tool, which is mine. It's not someone else. It's not our 2D tool or connection pool. I'm creating mine, which will wrap someone else. And it's fine. I don't want the library of someone bleeding into my application code. So this guy, that's my way of architecting. This guy, the path here, I say the path of the file,
Speaker 1and if it's known, it's in memory, and otherwise, path of the file, g, it's always good to have this, and they say mydb.db3. In fact, I'm going to do something like that. where I'm showing that the path is a file path. There's something implicit about this example. That is what I will do. And then I will do copilot,
Speaker 1cram that. That sounds good. That sounds good. does that sounds good yeah the thing i don't like is i have to do a to string and everything i don't like that so i will do a new i will
Speaker 1do a from path no i will do i will do that new which is going to be usually my things and what i like to do here is not that oh go away um i'm going to do pass implementation into That is what I will do. So here in this example here, for the one that I'll just join,
Speaker 1I'm preparing my video, which is going to be a video about ROS and SQLite. I'm showing a little bit all of the steps, such as we can learn step by step. So we learn simple, join, values, dynamic values, the JSON, JSONB, async. So the raw async of what is the limitation of the connection without anything else. And now I'm doing a kind of a pattern and to say it's a pattern that I like is a DB manager. And then inside my DB manager, I will have an attraction that might or might not use connection pools or
Speaker 1such a thing. So right now it's to say, I will say from, I will do a new stuff into string, which is fine. So like this, if it's a reference, I create a string. If it's give me a string, then I don't have new allocation and I'm going to This one would be a sum, would be a path, sum, path, into, okay? And now if I want to be fancy, I can have a fn, new, oh, yeah. What was the name
Speaker 1when we open it? I can try to, Yeah, it's not open. I don't want to open it at this point. So I will say new. And the reason why I didn't take option, because I like to be able to just give whatever that look like a string. So new memory. Memory db, okay? Okay, sorry. Usually I will do like that.
Speaker 1That is weird with the memory world, but that is what I will use because that's the pattern that I use for the builder. So I will do these kind of things here where now I have self and then we'll return self. And then I will let this guy go pilot. All this stuff is not too bad. Now, this is the things, the one that we'll do. I wouldn't do that the way I like to do it, I think I say constructors. I love the fact that
Speaker 1I can have my blocks like that. And this is awesome. Such as I can have different blocks and I scope them by whatever I want them to do. Yeah. And then here's a trick. The trick is, I don't want to have my app code saying open or not, it's not this business in a way. This business should be to say, I want to execute something or I want to do something. So, and then the, the constructor here
Speaker 1will be the one that will create the connection or not. So that is a way that I like to have it. So I will put it, which is, I say the executors, the big executors, and I will do an implementation of db, and then I will do, so I will put them as sync, okay, pub, and I will do an async, execute,
Speaker 1for example, self, And then I will return the result. So that will be the correct result, which is today boxed in, which is good for my literal stuff, but then after it will get better over time. And then
Speaker 1use size. Okay. And that is where I will do that part. Okay. So this is the thing. DB Manager works because I didn't do, I didn't break anything. So I will do that. There's another one that I like to do is, you know, when you execute with returning. So I don't know how many of you here have been in the previous live streams. If you are a member,
Speaker 1you probably see them here in your early access. So I think there's some here that... there's some streams that are there. And they're pretty long, yeah, so stuff. But again, the video is coming where everything is going to be concise. But there's a pretty cool way where we, you know, this is a way you execute with a returning ID. And so that is pretty cool. And this one here, that is what I want to allow. I want to
Speaker 1allow to return the ID kind of thing. So what I would do is, I don't know what this one was, not save. I will do kind of a pub, a sync, and I will do a fn, exact, with returning num. The reason why I say num is because I don't know if it's ID, but here I'm going to say assume,
Speaker 1the SQLite will return, the SQL will have a returning, will end with returning some num colon. OK. So, and
Speaker 1in fact, when I say num, I can be more precise, perhaps. So I'm going to do the join as 64. I could use that, and this is fine. And so returning ID, we qualify on it. Now the question is, what do
Speaker 1I take as a params? So that we're going to solve that. And then I'm going to return a result of I64. So that is something I will do. Now, the fact that I use a connection pool, a mutex,
Speaker 1or whatever, it doesn't matter. And in fact, what I'm going to do is I'm going to start by implementing a mutex first, and then I do stuff. Then there's a next develop when I want to do transactions, so I need to expose a transaction object and all these kind of things. But again, I want to try to abstract some of those kind of constructs, such as my application code doesn't have to know it. The next one here that I want to do is I want to be able to, this kind of stuff that we did over there. I don't want to do a whole SQL
Speaker 1builder in certain stuff, so I want to say, hey, you give me your statement, your prepare statement, which is always a reference of a string, because it should be static. We're not going to enforce static because you want to allow people to dynamic it, but again, it should be a prepersetment. And then after we have these query rows, or query, I think, where do I have my select? Query. So I think the query will be good. So like this,
Speaker 1we're not stuck. So query, the only difference is that our query will take the string and will take the params, and this one is a tricky part here. And then it will return, and for now it's fine, it will return the rows of the database. Later we can do more stuff. So I'm going to have the execute, so this one, I need to have a symmetry here, I'm going to have the exec. Not very proud of this,
Speaker 1but whatever. Well, this is not really Rust. Rust people who say don't save. then I do that and I will do pub async fn query and I will do the SQL which is the str and then I will do the params which is something so we're going to
Speaker 1put it void right now which I don't know what you know to do and then it's going to return and we're going to return for now we're not going to be too smart we're going to return this guy so what is this guy is a reference uh game over game over because I need to work on this one.
Speaker 1So every time you return something with a reference, it's a trick. So here it's tricky because it's cute because we have the statement and stuff. But I don't want to return all the statements. Because the rows, and this is what we're using in the print, the rows have the pointer on the statement. And this is why it's nice because you can see what the rows has. I'm
Speaker 1going to have to think about this one. This one is not done. I mean, if I solve it, it's pretty cool. So I need to do a result. That is not the same lifetime. There's something there. Okay. So right now I'm going, I'm not happy with that, but I'm going to say pub field. Okay. And I'm going
Speaker 1to say structure. field and then say name string and then i say value value of the database not silly this guy okay so that is what i have and that is what i will return a field I'm not
Speaker 1happy for multiple reasons because it will duplicate all of the names here. So if you have a lot of, it's a lot of duplicated data and stuff, but it's a start. At least we'll see if we can do that. Okay. Then I say, because I put to do, so there's nothing. And now the param guys, I'm just going to implement these four guys here. these three guys, I think is, then after we can do the rest later. Now, and
Speaker 1I have 45 minutes, so hopefully I can do that in 45 minutes. Now I'm going to, so first here, what I'm going to do is, this one. And here the thing is, I'm going to put it in a
Speaker 1mutex right now. So I'm keeping both the path and the things. There's an argument to say you don't need to keep the path anymore. But I'm going to create the connection and open the connection at first. Eventually that could become a connection pool. And you do want kind of a connection pool because if the database is not, I mean, in this case, it's a file and things, but When you have a remote database, you want to say if your database is not there, you don't want your application to crash in a way. So the request can crash, but at least not the application. So you
Speaker 1want to have a kind of, if you have a pool, when it's well done, the pool kind of retries itself. So a connection and a request will fail. It won't retry the query, but at least when the database comes back, it will come back. So using a connection pool is not bad. not a bad strategy it's a good one but right now we're going to do our own thing which is going to be an arc a mutext and then we're going to have the connection there boom okay
Speaker 1mutext interesting so this one there's always a question about which one to use i'm going to use This one because we are not going to lock across a weight. If you lock across a weight, then you should use to queue. This is my understanding. This one here we do is path, so we're going to do a let. So let path, okay. Path into. And then we'll say
Speaker 1let connection. So con equal tag. That's fine enough. I do not want expect. So I'm going to wrap that into a result. I'm going to do a question mark over there. I have the things. And then a path. I say, hey, co-pilot, do your stuff. Come on, wake up. This one shouldn't be hard. Oh yeah, okay. Pass. Connection.
Speaker 1And that would be an okay. So that should work. Okay, my mistake then. Ah! sorry can i do an into
Speaker 1here and it will go oh no sorry can i do a con into no that would have been too nice so i can do a arc new new text New, I think it is. And then con. Yep. Okay, that's good.
Speaker 1And then we're going to see if Copilot is good on this one. Use AI, use Copilot, there's nothing wrong. Make us laugh sometime. This guy couldn't even do that. What is going on? Don't we pass none? And then the connection. I hope you can do it. Okay. Now, the cool thing about this is, I'm not saying something. Here,
Speaker 1the feature won't be supported. But the cool thing is when I have a new and I have a path, I can reconstruct the things if the connection goes off or whatever. Usually, you will use a connection pool here. I'm just using a connection. I put it in mutex, but it's completely valid to use a connection. So this pattern here doesn't say, oh, don't use connection pooling or whatever, or even ORM. It's to say, just abstract it. Just own your abstraction database. Here's a little hack for memory
Speaker 1because I have to think, but there's an argument to say, you cannot do it for memory. The problem of memory, if it crashes, its connection doesn't work anymore, whatever, then the whole thing is lost, yeah. Yeah, exactly. It's a connection. But it's not... Okay, let me explain. I'm not trying to be on the defensive here. It's not a connection pool that I'm implementing. What I'm implementing is my abstraction
Speaker 1for my app of how I want to call the database. So I want not only to own this, but here I might have R2D2 or whatever, or like Deadpool or whatever. But what is important is not really this. This is like, I do a mutex because it's the cheapest way for me to get the functionality and to get my app going. But what is important for me is that signature. These guys here. This is what is gold. Because that will
Speaker 1allow me to do the things here, to... simplify my application, such as every time I do an execute and returning ID, I don't have, it's very consistent, boom, boom, boom. And then i can and then on top of that then i have my model layer which is i call my model controller and then all the app code can go to the model controller and then they just get the models they don't have to worry about the database so this is a little bit kind of the strategies that i have so for example if i go Let me try to show a little bit something. I think I
Speaker 1can try to show some. Give me a sec. Are you kidding me? I don't have it. yeah kind of
Speaker 1yeah so that is one thing i've done is for my back end for my client is always the same thing i have the model here and then i have i have the model here and then i have the the store so the store that would be where i have my dub and stuff and then all my application that is a desktop application or web application it goes to the model they don't go to the store they go to the model And so they get clean model stuff. And then the model, when they go to the store, they go to the store layer. I'm sorry, I'm looking there.
Speaker 1Goes to the store layer and then the store layer has a database kind of thing. So that is a way that architect. The fact here that is a DB pool connection and stuff is fine. It's my DB abstraction layer. So that is where I split the beast. Let me go back there. Now we have that. So that being said, this little stuff on the Stream Deck is added a
Speaker 1live stream on it. It's pretty cool. Now, but you're right. Yeah, it looks like a thing. So I'm going to do the easiest one, which is execute sql str. that I think is the easiest guide to do and so I will say let con and then we say please and
Speaker 1we don't do unwrap I would do that I don't there's a thing here that okay If I remember, there's this thing that this guy doesn't like it. I need to do a mapper. And that thing about the talk to one is that it doesn't have that. There's something
Speaker 1here that... Yeah, okay. So you need to do that. It's not boxed in friendly somehow. But that is just very little issues. So I do that. I have the connection now and I should be able to run. So if I go to my simple guy over there, connection execute, that's it. Then void. Connection execute. And then I do
Speaker 1my SQL. And I do void. Then that should be let num, which is the number of things that are changed, and that question mark. Get the number, and I do the OK. And then I don't have any param on this guy. Now you could say, well, it's silly to
Speaker 1not have param, which is fair. So I'm going to go back here, git log, git add. Let's see, so here again, I'm learning, it's a Rust XP SQLite. I'm running SQLite, we have done all of these chapters. I'm going to make a video of 20 to 40 minutes here, which is going to be very, very dense. but I'm doing the making of now with everybody online. I'm doing
Speaker 1this experiment if people like it or not. And then we are the last chapter. I said this one was going to be the last, but this one is the last. And I don't know if I will do it in the video or not because I'm trying to scope my video at 20 to 40 minutes max. Otherwise people get overwhelmed and it might be too long. And this one people can say is a little bit subjective in a way, which is true. It's a perspective. And so I need
Speaker 1a param. So I'm going to git c, and this is work in progress, c07db. I don't want to write that. And then I say first interface definition. which is what we did. Go back to my beacon, everything runs, doesn't really matter. And then what we're going to do, I
Speaker 1think I can simplify like that, don't need the cargo. We don't need the craft seed, I don't want to touch it because I don't want to touch the stuff above. DButil, leave, we don't care. Simple perhaps. So now let me see. Here, can we use our execute somewhere? We could use it here,
Speaker 1but in this param. That's fair. So, well actually, do you know what? We could use it here. So in my DB manager, I could do it something like that. Sorry, I'm being slow here. So right now I'm creating the schema,
Speaker 1but I will do, and I don't want to change the create schema because I don't want to inject DB manager everywhere. So this one would still be like that. Yeah. But then after, so this, I'm sorry. So this one would still be like that. and then after I can do a let db and this is where I have my db new and this is why I have this like that boom and then I should be able to
Speaker 1insert it boom and now go back there and what I should be able to do is No, because I don't return the rows. I don't know if I can do a... No, I need the params. Okay, so let's try to do the params. The params. That I cannot
Speaker 1pronounce it. And so on this guy here, I have params p. p is params. So I think... And this one is... is a magical one somewhere there's like somewhere there's like a lot of from into this guy this guy is where quite a bit of magic happen so what we're going to hope is we can do this
Speaker 1time or we can do the other time so go back to my db guy and i'm going to add there params It's the same thing, yeah? Params. And then press save. Yeah. And press things. Yeah. And then results and size. That is pretty cool. So then that's it.
Speaker 1So now we can even do So can we change something here? Yeah, here we didn't care about keeping the ID, so we can do that. We're going to go to our DB. Yeah, yeah, these macros define all the stuff and things. But it's get finicky. I mean, I did
Speaker 1it for my ModQL for the thing. It can get finicky to get it right. And then I do, so I have the debug. I don't need debug. But I think I need clone here. And this one might be... This one is not good. Might be arc or something.
Speaker 1Because it's immutable, but... So I don't need a mutex, but it might not. Yeah, that's fine. So this one, I will do an option of ArcSTR probably. It's a cool video from Logan Smith about the ArcSTR. But for now, let's keep it this way. And I'm trying to think in my head. Sorry, I'm slow. Now I should be
Speaker 1able to do a DB, new path, and rather to open a new connection, I should be able to, no, no, I don't want to do that. I want to do for every guy, I'm going to do a let DB, I think, can I do clone? Okay. And then I
Speaker 1move this guy over there. That's the whole point. And then I can do a DB. And something like that. So try to save. Almost, almost, almost. Oh, yeah, that's fair enough. Remember, we decided to put it await. Honestly, it doesn't have to be await. Because is sync anyway. So here I'm adding a weight, but honestly it doesn't
Speaker 1have to be a weight. So that is one thing where I do something and my brain says, well, that's silly, why are you doing that? And then the other one says, well, you know, because it's cool to be a weight. Because when I talk to PostgreSQL, I am a weight. So I like this symmetry, but it might not make sense to bring it back to SQLite because it's not a weight. But anyway, I have the executor weight over there. And it's not yielding over there. Now, the cool thing about
Speaker 1stuff is I could have, like in a weight, when you have a weight, you can do a Tokyo year now, which gives time to breathe for other people. So if I have a lot of processing on rows, it might be good. I don't know. So that's pretty cool. It's actually running very well. That is actually very cool. so that's it this is actually this guy running so I have the things I have the db clone so every
Speaker 1time I clone the thing if I don't db clone it will be moved once but then I cannot move the other guy I db clone that now the thing I'm saying is to say where are that you don't want to clone the string so what you will do is you will put it in arc and you will do arc str which is a very cool Logan Smith has a very cool video on that and something is going to complain over there and it would be funnier
Speaker 1to say grab something like that and then that is think something yeah need to deref it and re-ref it okay when you say as deref we should be the
Speaker 1same and i want to check that okay what is something that i Yeah, that works. So the thing I'm saying is open this stuff and it works. Everything works
Speaker 1very well there. So now I will do this guy. Remember this guy here, which is always a pain. I'm sorry, I'm going back to my... not that guy I'm going to go to this guy and so this is nice thanks this one is a two string here I need to think about it but it's a better way here
Speaker 1to do that but thanks and then the box din sometimes it doesn't like it when you have async stuff and the next one Yeah, Ricardo, that is a good question. What is the limitation of SQLite in production? I'm using it to prototype. So production is already used and it's
Speaker 1probably the biggest database that is used in production of the whole planet. And the reason why is on your phone, I mean, a client app, a Chrome application is a production application. Microsoft Office on the desktop is production. Photoshop is a production app. And so production app could be on the client, could be on the cloud. It's something that if it's broken and stuff, you get sued, you have to give money back. So that's the pressure of a production application for me. So SQLite, for everything which
Speaker 1is on device, is already probably the biggest production database ever made, I think. On your phone, you probably have, I don't know, I'm going to say a silly number, but I have, I don't know, probably, I don't have that many apps, but I have like, let's say 20 apps. I'm sure I have 15 SQLite, at least because the operating system is maybe using many instance of them. And on the desktop, I wouldn't even count them. So SQLite
Speaker 1on the devices is full production ready. SQLite on the edge, which means that in the cloud you have, I wouldn't say a lambda, but you have some sort of pods or something that runs and you want to query things and cache things. I'm going to use it for SQL, for Dev AI to cache, to index, markdown content and all of that. So for that, it's fully production ready
Speaker 1because it's already there. Where it's not production, really, and where you're right, it's more like prototyping, is let's say that you say, well, I want to do a cloud application, and I don't want to use Postgres, I want to use SQLite. Well, SQLite is not designed for that. It's not designed for high concurrency. Just not. So can it work? Yes. Thanks to Rust, because you can do your connection pool and stuff you can actually have request so that is
Speaker 1where i'm going to put a caveat in what i'm saying is i think you can go a long way with sqlite and building a very cool application for yourself because since you have rust rescue light or whatever you use a pool system or whatever you have pretty good concurrency and so you can scale to Not to a thousand per second users or 10,000 per minute or whatever we want to say it, but you can write something that will work pretty well. However, my recommendation is if
Speaker 1you do a cloud app, you have to plan to move to Postgres. Postgres is gold. There's no reason to not move there. Now, SQLite is good as well for desktop apps, for command line, for things on the edge. The more I've been using it in 2024, the more I'm saying, oh my God, it's heaven. And the whole JSON and JSONB is amazing. And it's good because it's focused. It's narrow to what is not trying to be the
Speaker 1database for everybody. When you have a database that say, hey, we are all the use case, embedded, cloud, vector, sky, space, or whatever. real-time and time series and everything, all of these requirements are so disparate that, yes, you can do, but at the end of the day, you are going to have the universal hammer or the kitchen sink syndrome. I mean, the consequences are, you know. So that is
Speaker 1a trick. And the thing I love about SQLite is, no, no, no, they are very focused on this, like, I wouldn't say single user, but know this more embedded database that can scale very well and that can surprisingly scale so that is what i love about it it doesn't try to be the database for everything and the same thing postgres doesn't try to be the embedded below two meg of database yeah so if we look at for example here's
Speaker 1one thing here this is actually pretty cool to look at if we look we're going to do a cargo build dash dash release dash dash example and we are going to take the scissor ones is simple Yeah, because that is obviously the simplest. This is actually a pretty cool thing to do. Compile the stuff. So that is,
Speaker 1it looks boring like that, but it's pretty amazing. The guy for Resculite and everything, it's a guy also that did the Lib3 and everything. compiles the whole stuff and see inside our binary, which is awesome. So now if I do a LSH and I do a target, I think they're not down release. And they're on the example, sorry.
Speaker 1And 2.5 meg. So, you know, the rest, if I do a hello world, I don't know how much I am, but I have a whole database at 2.5 meg. So it cannot be postgres. We cannot have it everywhere. Nobody has found the magical algorithm or whatever, but it does so much for that size. So that is what I'm saying. So...
Speaker 1And the trick also is what you don't want to do, I mean, you're cool, and some people are forking SQLite and are trying to make it as a Postgres. But again, SQLite is not to make a server API, is not to make a SQL API, remote API. Yeah, so that's the thing. Hopefully, that. So it's really embedded when you have a process. So if you have one web app server and it's enough for you, that's great. But sometimes you need more. And so if you need more, then you cannot have more reading and writing into the same
Speaker 1SQLite file. Practically on the cloud, that cannot work because the file will be distributed. It doesn't work and it's all buggy. And then, I mean, that's why you have Postgres. So this is pretty cool. We did this guy. And I think the other guy, the other one that I want to do. Oh, but I don't even use it there. This one was this guy. This is the second one
Speaker 1I will do, which is always annoying. To do this, yeah? So that is... That is the constructor, so I'm happy with that. And that is this guy. So I will do the same thing over there. And then I will have connection over there. Okay. Then I will have the
Speaker 1prepare statement of my SQL, which will have the stuff. And then I will have the params. Yes, that's cool.
Speaker 1And now the error system is simpler. And then that will be the org ID, i64, and I will do a OK. There's a bug here now. OK. So that will be good. And I'm not going I could update it here, but I'm not going to do it, but
Speaker 1I could do this guy. And then I would do... This is what I had before. Yeah, but then... Oh yeah, I'm sorry. ID. No, no, it's good. Good. Returning ID.
Speaker 1That will return the ID now. I64 is not your size anymore. It's beautiful. And then if I wanted, I could have a pub. Pub. Let. IDs. Pact. New. And do a mute. Usually I like, I don't have to do it because I'm going to have, but I don't like the things where I have to fish down there, the type, just personal things. And then I will do
Speaker 1that and then say, hey, copilot. Copilot. That's it. So that is what I would do. And if I print that, if I do a bacon, that would run. And before I do this, If I do a print and I'm going to use IDs, then I have one, two, three, four, five. And if I didn't have this, I will have one, one, one, one, one, because it's the size that has been updated. Yep, so
Speaker 1that is working pretty nicely. So that is pretty cool. And then that's it. And then I will do this guy here. Right now I have to do it, I guess. So this is the thing here. okay so rose this
Speaker 1is a trick i have rose now but remember yeah this kind of this grows here point to this guy and this guy has i don't know why he has ah wait wait wait no no no because it would be too good to be true No, I don't think I can. We can try it, you know, but good luck. Okay,
Speaker 1we're going to try it. Okay, so here's the things that it should be. It should be this lifetime, I think. The one of self. The reason why I'm not sure is because... Why I'm not sure? Why incomprehensible? Oh. I
Speaker 1don't know. I don't return it yet. Yeah. and the reason why is because we believe it is but the connection of self even if it owns this guy this is created after and stuff so it cannot trace it back It would be a crazy way here. How long
Speaker 1do we have? We still have 14 people. Here's the thing I'm thinking. The thing I'm thinking is about... Okay, so this is not... Even if it's connection and things are more or less... It's not the connection these two are here are untangled yeah if we want to be
Speaker 1fancy and this one here i cannot do that that would be too much for him because he will say hey this is not this lifetime because it's that lifetime so one thing i can do is something like that
Speaker 1I'd like to return ImplementSciAllies. To return into ImplementSciAllies. Yeah, no, yeah, but SQLite, no, SQLX, Yeah, I like Roskulag. But SQLX has a nice thing because they take care of these things. So they have a whole API where you get the thing back. So I've been very deep in it because I've created a SQL builder, SQLB, on top of SQLX.
Speaker 1And so they have a nice thing. The problem of SQLX is they're trying to do a lot because they're trying to be the SQL driver. They're implementing their own. They are using the lib, the code, the Libsys 3 built by Rusculite, but they're not using Rusculite. They're not using Postgres or Tokyo Postgres. It's cool. It's very impressive. I got some issues with SQLite sometime on my Postgres and stuff. So I'm still using it in my Rusweb app, but for that needs, I like to go there. But
Speaker 1I agree that they have solved some of this problem. But it's an interesting one to resolve anyway. One way that they have because I remember I have these things and it gets a little bit hard to explain all stuff. One thing that they have is they have the things where if I put if I put I might be
Speaker 1able to have... That should compile. Is that useful? That is something else. Okay, so now... I don't like the
Speaker 1word result because it's like it's in a... That's much better, but... Sorry, guys. Ah, darn it. I need to think about this guy. So
Speaker 1I could serialize it here. One thing I could do is the thing I had before with my field. But I'm not happy. I'm trying to find a smarter way. I was hoping... Spinning, they have the thing here, they
Speaker 1have a problem to see. There's something. I will look
Speaker 1at that somewhere. There might be something smart to do here. But no, I don't think there's something smart. Because I think everything goes back to the connection. And the connection gets dropped there. I don't know. So if I do a thing like this. Oh, I'm sorry, sorry. That was silly.
Speaker 1That was silly. yeah so i think perhaps having the
Speaker 1query there's something here that i need i need to think about otherwise you serialize it and then you have the name and the thing i was saying you have the the name of the column, so you serialize it like this. This is relatively simple. You do a field, and then inside the field, you can do field or whatever. Or you can do own. What am I saying? there
Speaker 1a rule will become a little field abstract and then you will have the name string and then the the value and that will be a value of of of rule which is what this guy should be of rescue like So then the goal is, will be your stuff,
Speaker 1you iterate that and you build this guy. And then perhaps here, so this is what I did. So I did something pretty cool here. If you go to the dbutl, if you look at this, this is what we did. We did a row as ref, okay? And so that gives me all the names. So I have all the names. So in fact, what I could use is I can do almost arcster for each one perhaps. And then I have the vector of all the names and then I
Speaker 1print all the values. So here I print them, but I can keep them there. I can keep the value. Now the thing, the reason why I don't want that is because I don't want to repeat all the name all the time. This is not a nice way. So that's why it was nice for them to have that there. So this is a thing. So perhaps what I could do For the stream. I do it for the stream.
Speaker 1That is a good question. Do you usually code with that font size or just for the stream? Is that big enough for you guys? Because if you want to see what I code like, I mean, you don't want to see, believe me. What do I do? That is what I call luck. Much nicer. But that being said,
Speaker 1I need to think about it. Wait one sec. Okay,
Speaker 1can you hear me now? So I'm back. Yes, it's big enough. It was perfect for me, according to the point where my font size has gotten bigger over the years and stuff. Yeah, I'm getting old too and stuff, but somehow it's like small, but yeah. So anyway, I need to think about this. But so the brute force way here, which is not going to be elegant, I don't like it, okay? But I will do a let... Yeah, okay,
Speaker 1I will do a rows. I will do a rows, and then this will be a Vect of Vect, because it's also rows, and that will be a field, something like that, okay? and that i will have effect new
Speaker 1and then i will do the four rows something like that mute and then i will do a four oh in rows and then i will create the row and then i will add the row to the on oh yes i will have let on that would be a
Speaker 1vector of this guy is mute i might have a no stuff and then i will iterate so that i will try that and then this one will be I wouldn't be happy with that, but I'm going to try to see later to see if I can, I think
Speaker 1it's next or something. I have it on the dbprint. So dbprint here, I have a pretty good, yeah, you have to do that. One next stuff. This is a way to do that. The cool thing here is I have the logic here to go there. So anyway, so I wouldn't do that right now. I will say iterate I will say okay build so I'm not going to
Speaker 1implement that right now and then this one was a hack okay so I'm going to do quit so I don't know if I'm going to do that if I have a nice way elegant way of doing it I will put my DB manager on to the staff and Otherwise, I won't. Now, in my case, if you look at ModQL, which is a crate that I've done and I've published, I have some cool kind of things where I take this and put it into a struct. But in this example, I don't want to introduce ModQL. Moreover, ModQL depends also
Speaker 1on CQuery, and now that RustQLite is 0.33, there's a whole little dependency dance here that I need to do. Yeah, I can Put a function stuff there, but it's not... Yeah, there's many ways to skin the cat. Yeah, so you're right, Akul. And it's a little bit what they did, yeah? So Akul asked them to say, hey, give me your function. Yeah, you're right. This is a good point here. Why not pass a... I can put a function here, like rowFn,
Speaker 1a little bit like they had, and then they give me the rowFn, and then I call it or something like that. So there's many, or I can have an iterator, or where iterator? No, because I will have the same problem. But I would like to try to solve this problem here. These things of, I think there's something smart, because in fact, if I have a smart way of getting the names and being able to reuse the name for the rows, and then create an iterator for it, without duplicating the
Speaker 1name for the row, that would be cool. But otherwise, there's many ways to defend the skin of the cat here. So git log, and I say, git c, I'm going to say, c07db, first pass, but query. Okay. And that
Speaker 1will be it. So hopefully you enjoyed the things. At the end here, this last one, you can play with it actually. It's a very good exercise. I might play with it as well. And then I'm going to work on that video here, such as I can package it in 40 minutes, like I did many other videos on my channel. Feedback, welcome. One of the things here is that will be available for public for 12 hours. So if you didn't watch at the beginning, you can watch it. And then after two days on the early access and
Speaker 1definitely in the live stream, we'll have a production live stream, sometimes scheduled this week, probably about Rust web app. It's mostly about cloud production and stuff. And a poll for the topics and we'll do stuff. Those are more like ad hoc live stream. So that is the things. And hopefully you liked it. And if you have any questions, feel free to ask. I think I'm going to end pretty soon. And give a try to DVI because DVI is awesome. I have a cool video about it. And
Building production-ready web applications requires efficient database interaction, flexible query construction, and well-structured data access layers. We examine how these technologies work together to simplify...
In this episode, we continue our exploration of nine essential Rust programming best practices, focusing on utilities, practical examples, and software testing. Building reliable Rust applications requires more than...
In this comprehensive tutorial, we explore how to build database-driven applications using Rust and SQLite, covering essential database concepts and practical implementation techniques. We take a hands-on approach to...
Join Jeremy Chone for a live-stream session dedicated to Rust programming, software development, and practical engineering discussions. This session provides an opportunity to explore Rust development through a live...