SQLx is my favorite PostgreSQL driver to use with Rust.

Поділитися
Вставка
  • Опубліковано 22 гру 2024

КОМЕНТАРІ • 104

  • @256k_
    @256k_ Рік тому +20

    this was such a good intro to DB handling in rust! definitely demystified a lot the process. i was still learning rust building up to using it for backend development by for some reason was really terrified of how it would be like but honestly its really a reasonable experience and im looking forward to getting to that point.

    • @dreamsofcode
      @dreamsofcode  Рік тому +1

      I'm really glad to hear that! Thank you for the feedback. I'm looking forward to doing some more microservice content in rust in the future as well.

  • @spr3ez
    @spr3ez Рік тому +11

    Really love your videos. Rust and Postres are just best. keep it up!

  • @UthpalaHeenatigala
    @UthpalaHeenatigala Рік тому +6

    These tutorials are brilliant. Keep going you have something here :)

  • @coderaiders-yt
    @coderaiders-yt Рік тому +1

    I was having a horrific day trying to connect to my AWS Postgres db in Rust, until this video. Thank you!!

  • @minzmango1915
    @minzmango1915 Рік тому +3

    Man, you're a blessing. I don't really care about Rust that much tbh, but I just love your videos

    • @dreamsofcode
      @dreamsofcode  Рік тому

      Oh thank you, I appreciate that a lot 🙏 Anything you wanna see? I'm still figuring out what I wanna niche down on!

    • @minzmango1915
      @minzmango1915 Рік тому +2

      @@dreamsofcode Since you seem to like it, I'd be interested in a Postgres deep dive (like interesting features it has that other DBMS don't or something like that). But honestly I'll consume whatever you upload

    • @dreamsofcode
      @dreamsofcode  Рік тому

      Ok awesome. I have a lot I can dig into with postgres!

  • @gustav_spin
    @gustav_spin Рік тому +1

    Thank you very much for the video, I was even looking for one that explained the use of sqlx.

  • @Floppix93
    @Floppix93 Рік тому +2

    Really love the content ! Funny, informative and on point. Keep up the great work

    • @dreamsofcode
      @dreamsofcode  Рік тому

      Thank you!

    • @alangamer50
      @alangamer50 Рік тому

      fr, some mfs would have taken an entire video just to explain the installation

  • @vlad7951
    @vlad7951 5 місяців тому

    Nice! Thanks for the video! It helped me a lot with a small project that I had to move from SQLite to Postgres coming from a JS background.

  • @ikay1234
    @ikay1234 Рік тому +5

    Came from diesel headache. Great content. Subscribed..

  • @jmon24ify
    @jmon24ify 5 місяців тому

    Nice video! How the code is written remind me a lot of how I did things in PHP back in the day so it was very easy to understand.

  • @chuckocheret4115
    @chuckocheret4115 4 місяці тому

    Thanks for this! Got me up to speed much more quickly than the docs.

  • @LinuxForLife
    @LinuxForLife Рік тому +1

    Really inspiring! Thank for the share. 👍🍬

  • @tumi_tigur
    @tumi_tigur Рік тому +1

    Very good video, cant believe im excited to test an sql package

  • @ruleofnine5905
    @ruleofnine5905 Рік тому +18

    if anyone else the " the trait `Executor

  • @杨阳-q9b
    @杨阳-q9b Рік тому +1

    very helpful, thank you!

  • @xit
    @xit Рік тому +2

    Learned a lot of new stuffs. Thanks! :D Subbed!

    • @dreamsofcode
      @dreamsofcode  Рік тому

      Oh awesome! I'm really glad you enjoyed it. Thank you!

  • @dmytrozelinskyi4824
    @dmytrozelinskyi4824 7 місяців тому

    Short and clear. Thank you !

  • @luiscarlosjayk
    @luiscarlosjayk 6 місяців тому +1

    Hey, think you missed to mention the cargo sqlx prepare command, and offline mode.

  • @jacoblaney3011
    @jacoblaney3011 Рік тому +2

    Really dig the video. Dig all of your vids actually. I just have one question: what next? I get this is more of a theory driven video, showing how interacting with a Postgres database can be done via Rust using a rust crate but how might one use something like this in a real application outside of just changing the params and CRUD code in your IDE? Maybe showing what it takes to have a JavaScript front end that invokes a Rust backend? Or even just a command line interaction?

    • @dreamsofcode
      @dreamsofcode  Рік тому +1

      Thank you for the feedback.
      That's a great question. I think a video that goes over the entire flow of creating a microservices in rust might be beneficial to help tie everything together!

  • @yapet
    @yapet Рік тому +10

    I don’t think you need turbofish for query_as. I find it much more convenient to just add type annotation to the variable declaration, ie`let book: Book = …`
    God I love ocaml-ish/haskell-ish type deduction of rust.

    • @ant1fact
      @ant1fact Рік тому +1

      I like to annotate my variables too. There are still some places like closures where you can't always avoid turbofish though

  • @sergp7480
    @sergp7480 Рік тому +2

    the density of knowledge is insane, keep it up!
    I really like your rust videos. Have you thought about creating rust + iced video or any other idiomatic rust gui lib?

    • @dreamsofcode
      @dreamsofcode  Рік тому

      Thank you! I appreciate that. I wonder if it's perhaps too dense and I should spread it out some what 😅.
      I haven't yet but I will look into it! I've wanted to do a gui library video for a while so perhaps now is a good excuse to do so!

  • @clusterdriven
    @clusterdriven 11 місяців тому +1

    Great video!

  • @peterboshe6217
    @peterboshe6217 11 місяців тому

    A thumbs up solely for the mean girl's reference. solid and informational material but yeah, mean girls.

  • @lautaroblasco
    @lautaroblasco Рік тому +1

    Good video bro

  • @TheBurntHoney
    @TheBurntHoney Рік тому +1

    Why do you have the query on two seperate lines? Eg q=“” query=sqlx::query(q)

  • @kappilino
    @kappilino Рік тому +1

    Is SQLx verifying the querys in term of securtiy aspekts as sql injections ? Because it is quite time consuming and error-prone to do it yourself. The posgres crate and rusqulite make this

    • @Mankepanke
      @Mankepanke 7 місяців тому +1

      Yes, since parameters are all bound parameters.

  • @narthanaj
    @narthanaj Рік тому +3

    Im gonna learn rust

  • @GlobalYoung7
    @GlobalYoung7 Рік тому +1

    thank you 😊

  • @vencler
    @vencler Рік тому +2

    Hey, unrelated question/suggestion: would you be willing to create a video covering your setup (tooling, apps, themes, best practices, anything usefuf/interesting in regards to software/hardware.)? If so, that would be dope. :)

    • @dreamsofcode
      @dreamsofcode  Рік тому +1

      I absolutely would love to! I have so many videos I could make on it haha

    • @vencler
      @vencler Рік тому

      @@dreamsofcode i turned on the notifications, looking forward to it!

  • @ProjectWeekend-h4z
    @ProjectWeekend-h4z Рік тому +1

    I don't care about Rust, the video is just enjoyable 😁

    • @dreamsofcode
      @dreamsofcode  Рік тому

      That means an awful lot to me! ❤️
      Is there anything you'd like to see that I can create for you?

  • @brencancer
    @brencancer Рік тому +1

    i like the code editor , is it sublime, atom or vscode? linux distro??

    • @theintjengineer
      @theintjengineer Рік тому +1

      It looks like a highly customised (Neo)Vim [an editor]; this isn't the best part though - it's this skills with it.
      It's probably what he talks about on one of the videos in the same playlist ["Perfect Neovim setup for Rust"]

    • @Mankepanke
      @Mankepanke 7 місяців тому +1

      It's NeoVim, inside of Tmux running the Catppuccin theme. Looks like.

  • @chuckocheret4115
    @chuckocheret4115 4 місяці тому

    The GitHub link provided doesn't appear to actually contain the Rust code from the video.

  • @АртемФедоров-ю7б
    @АртемФедоров-ю7б 9 місяців тому

    what about choosing database driver at runtime? for example if application needs to support at least 2 databases - sqlite for tests and postgres for production?

    • @dreamsofcode
      @dreamsofcode  9 місяців тому

      Id personally use PostgreSQL for testing via something like testcontainers. Otherwise you're not really testing your database interactions with PostgreSQL.
      I'll have a video coming out about that soon!

  • @uberloss
    @uberloss 9 місяців тому

    I'm a beginner and I find bugs in the tutorial hard to figure out like why the second argument to update() is never used. What is the point of it.

  • @sergp7480
    @sergp7480 Рік тому +1

    4:39 - typo &sqlx::PgPool not &sqlx:PgPool
    4:43 - typo $1 not %1

  • @danraine9009
    @danraine9009 Рік тому +1

    Awesome video, could you make a video on handling errors coming from poetgresql I have implemented the happy path nicely but am struggling to decode any errors for example if two email addresses match when trying to add a something to the db. Thanks again ❤️

    • @dreamsofcode
      @dreamsofcode  Рік тому +1

      Absolutely! This is a great idea

    • @danraine9009
      @danraine9009 Рік тому

      @@dreamsofcode awesome thank you for your work

  • @mrknopester
    @mrknopester Рік тому +1

    What are your thoughts on SeaORM?

    • @dreamsofcode
      @dreamsofcode  Рік тому

      I need to try it out, really! Although personally I tend to not use ORM's too often as I like to handcraft SQL sometimes. SeaORM does look really appealing though.

  • @bendo01
    @bendo01 Рік тому +1

    can you teach us using sqlxmq ?

  • @clusterdriven
    @clusterdriven 11 місяців тому

    Is there a way to have the migrations have some programmatic sauce in them? I see the migrations in the SQL format. I wonder if there is a way to write migrations in rust instead?

    • @dreamsofcode
      @dreamsofcode  11 місяців тому +1

      An ORM would be able to do migrations in Rust. SeaORM is one that's pretty popular

  • @jly_dev
    @jly_dev 4 місяці тому

    sea-query + sqlx = ❤

  • @johnnyblack4261
    @johnnyblack4261 Рік тому +1

    WHich one should I use sqlx or sea-orm?

    • @dreamsofcode
      @dreamsofcode  Рік тому +1

      It depends on what your personal preference is! I typically prefer raw SQL to ORMs as I feel it gives a greater level of understanding, but not everyone thinks the same way as I do

    • @johnnyblack4261
      @johnnyblack4261 Рік тому +1

      @@dreamsofcode I see mate, after taking a look between the two, I think I would prefer Sea_orm as you are not using strings to do select statements etc, easily using strings to do select statements can lead to bugs as you can compile it with a syntax error, at least with seaorm it will fail to compile, plus you get auto suggestions.

    • @dreamsofcode
      @dreamsofcode  Рік тому +1

      @@johnnyblack4261 I think if that works for you, you should go for it! I tend to make use of testing to be sure that the sql statements work, rather than fully trusting the compiler when it comes to databases!

    • @johnnyblack4261
      @johnnyblack4261 Рік тому +1

      @@dreamsofcode Ah right makes sense.
      I actually got another question, if I wanted to have a (small) database webserver and I wanted to use seaorm, would the seaorm code run on the client's software?

    • @dreamsofcode
      @dreamsofcode  Рік тому +1

      @@johnnyblack4261 for web applications, generally no. You should have an API that is called and the database connection live on the server.

  • @ahmedAltariqi
    @ahmedAltariqi 2 місяці тому

    Can I use this with Tauri?

  • @spr3ez
    @spr3ez Рік тому +2

    Whats you neovim theme?

    • @dreamsofcode
      @dreamsofcode  Рік тому +2

      Catppuccin! It's probably my favorite color scheme

    • @spr3ez
      @spr3ez Рік тому +1

      @@dreamsofcode yeah its really cool! thanks ima try it, I already use a very similar one, so probably gonna switch

  • @kairunhanjun
    @kairunhanjun 11 місяців тому

    What %1 and $1 is for? can i put custom column like UPDATE book SET `#1`=%1 WHERE ISBN = $3?

    • @michawhite7613
      @michawhite7613 2 місяці тому

      @@kairunhanjun Look into "prepared statements"

  • @SandwichMitGurke
    @SandwichMitGurke Рік тому

    and why do you prefer it over diesel?

    • @dreamsofcode
      @dreamsofcode  Рік тому +1

      Diesel isn't async, and it's an ORM. So those are the two considerations I have against it.

  • @CorneliusCornbread
    @CorneliusCornbread Рік тому

    Why use tokio over the standard async library?

    • @dreamsofcode
      @dreamsofcode  Рік тому

      You still need a runtime for async in Rust. I believe there's only async_std, tokio and smol. Tokio is the most popular of the three.

  • @coffee-is-power
    @coffee-is-power Рік тому +3

    You completely forgot the sqlx macros, they're really amazing, they run the queries at compile time on your local database to check if they're valid

  • @ruizdiazever
    @ruizdiazever Рік тому

    Is very fast and simple buy with Axum change everything! D:

  • @hussainsharza9319
    @hussainsharza9319 10 місяців тому

    Short and Simple

  • @kurt7020
    @kurt7020 Рік тому +2

    "I'd also consider using it for other databases such as mysql" - Face it, there's no way you're ever going back to mysql. XD

    • @dreamsofcode
      @dreamsofcode  Рік тому +1

      🤣🤣🤣 bruh how you know me so well

  • @sharkpyro93
    @sharkpyro93 Рік тому +2

    what about relationships? there is not 1 single example online on how to handle relationships with sqlx

    • @dreamsofcode
      @dreamsofcode  Рік тому

      Are you talking about joining data sets using a SQL JOIN and returning the data model?

    • @sharkpyro93
      @sharkpyro93 Рік тому

      @@dreamsofcode i was referring to provide the query_as() with a model that has some nested structs with different relationships mapping to them automatically, turns out is not doable, its either i go full on raw sql and setting the results manually, or using an orm but diesel orm stinks and seaorm is terrible too, guess i cannot use rust

    • @robert-m6u7d
      @robert-m6u7d Рік тому

      @@sharkpyro93 I came to the same conclusion. On top of that relationships in SeaORM, according to the docs, have to be done using the lazy concept when you have more than 2 relationships. Which is the same as using sqlx and then manually mapping the results. I invested a lot more than I was anticipating.

    • @sharkpyro93
      @sharkpyro93 Рік тому

      @@robert-m6u7d yea rust is not a good fit for apps that need intense db crud, takes forever to manually write everything, also its not a safe approach

    • @Mankepanke
      @Mankepanke 7 місяців тому

      I suppose you do it the same way as you always do when not working with an ORM. Is there something specific that you don't find to be working well?

  • @NotherPleb
    @NotherPleb Рік тому

    I need your theme

  • @FrederickRoundtree-b2o
    @FrederickRoundtree-b2o 2 місяці тому

    Marques Burgs

  • @HubertSobkow
    @HubertSobkow 4 місяці тому

    This is what I was looking for. Diesel and SeaSql are ORM's and for the love of god! PLEASE STOP USING ORM'S! They hurt you and your project. It seems this package is from the same group of people that build sqlx for golang! Even better! :D

  • @SarahJohnson-l3q
    @SarahJohnson-l3q 2 місяці тому

    Von Coves