MUST know Rust database libraries

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 พ.ย. 2024

ความคิดเห็น • 62

  • @letsgetrusty
    @letsgetrusty  2 ปีที่แล้ว +6

    📝Get your *FREE Rust cheat sheet* :
    www.letsgetrusty.com/cheatsheet

  • @d.sherman8563
    @d.sherman8563 ปีที่แล้ว +22

    It's difficult to overstate how awesome sqlx is. I find it really reduces the need for an ORM, since one of the main reasons for an ORM is the ease of mapping queries to static types. Sqlx will at compile time check that the actual result from the underlying database matches the rust type you are trying to select into. This means that you immediately get type errors on save if the struct you are selecting into does not match the datatypes actually returned from the database, with extremely clear errors as to what is wrong.
    For example if your struct has a property with a String type, but the backing database field is Nullable, it will, on save, right after you wrote the line, tell you that you should change it to an Option field. Same for if you try and select fields or relations, do joins etc on fields / tables that don't exist, instant clear and helpful error messages. You're queries are not altered in any way or checked by the library, it actually executes the query your wrote against the underlying database and uses what the database returns to show the error message. This only happens at compile time, and it also lets you reference a .sql file instead of writing the query inline with the same functionality.
    Locally you run it against your dev database, and it provides an option to generate metadata in the project to use in environments where you don't have a real db connection, say for CI environments. On top of that it also has migration management options. The syntax is along the lines of let user = sqlx::query_as!(User, "SELECT id, name, age FROM users WHERE id = $1", id).await?; Where the first argument is a rust struct and the return value is a User struct.

  • @codelearner4449
    @codelearner4449 2 ปีที่แล้ว +32

    So happy to see you back, with your original persona and voice.

    • @ngxtmvre.9261
      @ngxtmvre.9261 2 ปีที่แล้ว +1

      yo I kinda missed that video, could anyone tell me what was in there? got sorta curious at this point

    • @codelearner4449
      @codelearner4449 2 ปีที่แล้ว +1

      There was a voiceover from some voiceover artist. Almost same video.

  • @KurtSchwind
    @KurtSchwind ปีที่แล้ว +7

    Most of the places I consult with consider ORMs to be an anti-pattern. Everyone that works with databases needs to know SQL anyway (or should), so adding an ORM layer can obscure work. Also, you have to manage an ORM translation layer. It's a lot of extra tech and while some people swear by the boost in productivity other places are just saying it's an anti-pattern and telling folks to work in SQL directly.

    • @ollydix
      @ollydix ปีที่แล้ว

      ORM really helps type checking though, for example if you have struct modifications you will get errors using vanilla SQL. Also helps you prevent injection attacks amongst other things. Also you get enforced validators on object for complex types. I know using Zod in combination with Sequlize was really good in TS.

    • @georgehelyar
      @georgehelyar ปีที่แล้ว

      There are pros and cons. I kind of think of ORMs a bit like high level languages.
      ORMs are fine to develop quickly, particularly if you are just writing CRUD APIs etc, and they can also help write database migrations for when you need to change the schema, but sometimes you need fine grained control of the SQL you are executing to tweak performance, and ORMs tend to make that harder.
      I don't tend to use ORMs because SQL isn't that hard in the first place, it tends to be written once and then mostly left alone while consumers can use the functions without having to know how they work, and sooner or later you will probably need the control that direct SQL gives in order to scale, but I can see why some people like ORMs.
      To avoid SQL injection you just need parameterized commands, and to check your code does what you think it does, just write tests.

    • @d.sherman8563
      @d.sherman8563 ปีที่แล้ว +3

      @@ollydix Sqlx type checks your queries against the actual underlying database at compile time. It will execute the query you wrote and use the information returned from the database to give you extremely clear error messages. This is done via a macro and it runs every time you save so you get instant feedback if anything is wrong with your query.

  • @murilosalomao
    @murilosalomao 2 ปีที่แล้ว +14

    Is this a Déjà vu?

    • @letsgetrusty
      @letsgetrusty  2 ปีที่แล้ว +8

      It's a glitch in the matrix

  • @polar_dev
    @polar_dev 2 ปีที่แล้ว +5

    Check out Prisma Client Rust as a Rust ORM!

  • @cedricschacht9445
    @cedricschacht9445 2 ปีที่แล้ว +12

    Do you have any plans about a surreal db tutorial playlist?

  • @PhosphorusMoscu-code
    @PhosphorusMoscu-code 2 ปีที่แล้ว +2

    I met rbdc today, a Chinese ORM? I'm not sure, but it's fast, easy and flexible.
    Problems? Well, the biggest problem is the little documentation and the Github issues are in Chinese and not in English.
    I suggest checking it, for me it is a great solution for database connections, maybe I will help it to write documentation.

  • @m12652
    @m12652 หลายเดือนก่อน

    I've been coding nearly 40 years, SQL and SQL databases are one of the simplest things to learn, you just have to put in the time. I don't get why anyone bothers with an ORM these days, most of them write really bad sql in respect to processor and memory usage etc. so ultimately result in much higher running costs, particularly if you're paying by resource usage.

  • @juancarloselorriaga6171
    @juancarloselorriaga6171 ปีที่แล้ว +1

    Would you recommend sled for a Tauri desktop app? The app will be mostly saving data to the disk, some files and database backup or sync in the cloud.

  • @emvdl
    @emvdl 2 ปีที่แล้ว +4

    Thanks man! You look a bit tired, take care 💪

  • @implrust
    @implrust 2 ปีที่แล้ว +2

    consider tiberius for ms sql server, and MongoDB has direct driver for rust. why you left it

  • @ksediting6883
    @ksediting6883 6 หลายเดือนก่อน

    please make full video on diesel and sql so we can understand setup and grow

  • @vitasartemiev
    @vitasartemiev ปีที่แล้ว

    actually, diesel has an async extension. diesel-async on cargo, from the same team.

  • @honglouis
    @honglouis ปีที่แล้ว +1

    well done! went above and beyond.

  • @realsong-fake
    @realsong-fake 2 ปีที่แล้ว

    diesel is not inferior by lack of async. In fact it can perform much better than those so called "async" ORM with a much easier to reason with api.

  • @marcomarek7734
    @marcomarek7734 2 ปีที่แล้ว +1

    Great content as always. Love u Bogdan!

  • @vitorssmontes
    @vitorssmontes 2 ปีที่แล้ว

    Is there one with JDBC support?

  • @guidyouguy7306
    @guidyouguy7306 2 ปีที่แล้ว

    can you write the pool as all your live code ?

  • @MrZiyak99
    @MrZiyak99 2 ปีที่แล้ว +1

    is there anythig for rust like SQLC for GO?

    • @TRK--xk7bb
      @TRK--xk7bb 2 ปีที่แล้ว

      YES please! Something like sqlc would be ideal

  • @dluxdoggdlux
    @dluxdoggdlux 2 ปีที่แล้ว

    Already liked before the video started playing!

  • @Elduque40
    @Elduque40 2 ปีที่แล้ว

    Didn't you publish this some days ago?

  • @francescopigozzi7601
    @francescopigozzi7601 2 ปีที่แล้ว +6

    Hey there! 👋 I think you missed a couple of honourable mentions: Prisma is a pretty cool ORM for JS but has its engine entirely written in Rust, maybe they’ve released it in a public crate.
    Also, worth to note that the devs from Prisma have released a very powerful fork of mobc, an alternative to r2d2.
    Please, take a look at those 🙌

  • @itachi2011100
    @itachi2011100 ปีที่แล้ว +1

    BTree and Binary Tree are two very very very different data structures.
    Could you please pin a comment with the correction or re-upload?
    BTrees are hierarchical data structure designed for near constant time lookups as well as range lookups. Binary Tree are binary trees.

    • @chair547
      @chair547 ปีที่แล้ว

      They aren't as different as you seem to think they are.. A b tree is a hybrid between a linear array and a binary search tree that has the advantages of both and the drawbacks of neither

  • @arcstur
    @arcstur 2 ปีที่แล้ว

    Awesome video! A question: what was that "NoTls" in the Postgres database connections?

    • @ejon
      @ejon 2 ปีที่แล้ว

      Unencrypted connection

    • @pvinnie3827
      @pvinnie3827 2 ปีที่แล้ว

      Its possible to connect with encryption also with some additional crate

    • @realsong-fake
      @realsong-fake 2 ปีที่แล้ว +1

      Tls requires a different Rust type of socket than plain TCP. And in order to generic over different types "NoTls" serves as the placeholder type that is used for plain TCP.

  • @hamzasouidi7161
    @hamzasouidi7161 2 ปีที่แล้ว +2

    amazing content 💯🙏

  • @0xccd
    @0xccd 2 ปีที่แล้ว +1

    now one for NoSQL dbs

  • @aghileslounis
    @aghileslounis 2 ปีที่แล้ว +1

    for a web server we absolutely need the "connection pool" no ? but i'm surprised the ORM does not handle this already little bit strange that every time i do User.insert() a new connection need to be made first, because we should connect to the database once, when we start the app, this is what we do in nodejs for example and any other programming language i used, but i guess Rust is very low level that's why (i'm trying to learn rust and i'm a typescript fullstack developer)

    • @realsong-fake
      @realsong-fake 2 ปีที่แล้ว

      no. you dont always need a connection pool. if your db interface support pipelining and multiplexing. think of it like the difference between http1 and http2/3

  • @hamu_sando
    @hamu_sando ปีที่แล้ว

    Don't forget RocksDB Rust bindings.

  • @vietle1479
    @vietle1479 2 ปีที่แล้ว +1

    I hope it has lib support for H2SQL

  • @Merovingio
    @Merovingio 2 ปีที่แล้ว

    Bro, amazing channel. Would you talk about briefly about Cryptocurrency and Rust?

  • @theondono
    @theondono 2 ปีที่แล้ว +2

    My only pain is that none of those support mssql databases😢

    • @implrust
      @implrust 2 ปีที่แล้ว

      tiberius supports mssql, try this.

  • @brendon205
    @brendon205 2 ปีที่แล้ว +4

    Reupload?

    • @letsgetrusty
      @letsgetrusty  2 ปีที่แล้ว +10

      Yea. Updated the video based on feedback and re-uploaded.

    • @thingsiplay
      @thingsiplay 2 ปีที่แล้ว

      @@letsgetrusty But in the other video a different guy was speaking.

  • @yokebabjr3866
    @yokebabjr3866 2 ปีที่แล้ว +1

    I think in your exemples you should you use "?" instead of unwrap for showing good practicies

    • @enticey
      @enticey 2 ปีที่แล้ว

      You'll see .unwrap() or .expect() used in examples more often because it allows whoever is teaching to focus on what's important itself and reduces cognitive load on the listeners.

    • @RenderingUser
      @RenderingUser ปีที่แล้ว +1

      I once wrote a piece of code with 3 chained unwrap methods

    • @svelterust
      @svelterust ปีที่แล้ว

      @@RenderingUser Perhaps you needed to use the .and_then() method 😄

    • @RenderingUser
      @RenderingUser ปีที่แล้ว +1

      @@svelterust dw. I fixed that piece of code by properly structuring my project.

    • @svelterust
      @svelterust ปีที่แล้ว

      @@RenderingUser Sweet 👍

  • @naddar
    @naddar ปีที่แล้ว +2

    Why is it that there is barely any support for the most important and wide-spread database - the microsoft sql server ?

  • @EngineerNick
    @EngineerNick 2 ปีที่แล้ว

    Always awesome :)

  • @ykonghao318
    @ykonghao318 2 ปีที่แล้ว

    rbatis?

  • @SpeckyYT
    @SpeckyYT 2 ปีที่แล้ว

    I'm having a dejavù

  • @quantumcube3629
    @quantumcube3629 2 ปีที่แล้ว +1

    First comment 🎉

  • @ygjt76v0-----
    @ygjt76v0----- 2 ปีที่แล้ว

    Rust to complicated compare golang

  • @31redorange08
    @31redorange08 2 ปีที่แล้ว +6

    Why are particularly these MUST know? Some of them seem irrelevant. Clickbait?