Git Product home page Git Product logo

tide-basic-crud's Introduction

tide-basic-crud

Basic CRUD api using rust and tide with postgresql.

The code of this repo is also commented/explained in this post posts, where you can read from the initial implementation (using in-memory HashMap as db) and follow the progress and refactors made in the code.

Stack

  • Tide
  • sqlx
  • Tera

CI/CD


TODO:

[ ] Schema validation
[ ] Move front-end to wasm (localghost/yew)
[ ] Add telemetry
[ ] Better error handling
[ ] Add other resources (entities) and refactor structure.
[ ] Add tutorial on how to run locally

tide-basic-crud's People

Contributors

pepoviola avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

tide-basic-crud's Issues

update sqlx from 0.3 to 0.5

When you update the SQLX version from 0.3 to 0.5

First I changed
Pool::new(&db_url).await.unwrap()

for

Pool::connect(&db_url).await.unwrap()

Then, this error occurs:

error: one of the features ['runtime-actix-native-tls', 'runtime-async-std-native-tls', 'runtime-tokio-native-tls', 'runtime-actix-rustls', 'runtime-async-std-rustls', 'runtime-tokio-rustls'] must be enabled
--> /home/jose/.cargo/registry/src/github.com-1ecc6299db9ec823/sqlx-rt-0.5.10/src/lib.rs:9:1
|
9 | / compile_error!(
10 | | "one of the features ['runtime-actix-native-tls', 'runtime-async-std-native-tls',
11 | | 'runtime-tokio-native-tls', 'runtime-actix-rustls', 'runtime-async-std-rustls',
12 | | 'runtime-tokio-rustls'] must be enabled"
13 | | );
| |_^

error: could not compile sqlx-rt due to previous error
warning: build failed, waiting for other jobs to finish...
error: build failed

I understand that I have to add runtime-async-std-rustls, as it explains here [1]. By adding it, the aforementioned error is solved, but others appear:

In all query_as!

let row = query_as!(
| __________^
...
| |
^ expected i32, found enum std::option::Option

let row = query_as!(
| __________^
...
57 | | )
| |
^ expected struct std::string::String, found enum std::option::Option
|
= note: expected struct std::string::String
found enum std::option::Option<std::string::String>
= note: this error originates in the macro $crate::sqlx_macros::expand_query (in Nightly builds, run with -Z macro-backtrace for more info)

Please, I could give me any help with this
Thanks

Jose

[1] https://javierviola.com/post/06-basic-crud-with-rust-using-tide-final-refactor-and-complete-ci-cd/

ERROR [cacher 5/5] RUN cargo chef cook --release --recipe-path recipe.json

#17 42.65 error[E0658]: use of unstable library feature 'renamed_spin_loop'
#17 42.65 --> /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/spinning_top-0.2.4/src/spinlock.rs:57:17
#17 42.65 |
#17 42.65 57 | hint::spin_loop();
#17 42.65 | ^^^^^^^^^^^^^^^
#17 42.65 |
#17 42.65 = note: see issue #55002 rust-lang/rust#55002 for more information
#17 42.65
#17 42.65 error: aborting due to previous error
#17 42.65
#17 42.65 For more information about this error, try rustc --explain E0658.
#17 42.66 error: could not compile spinning_top
#17 42.66
#17 42.66 To learn more, run the command again with --verbose.
#17 42.66 warning: build failed, waiting for other jobs to finish...
#17 43.54 error: build failed
#17 43.55 thread 'main' panicked at 'Exited with status code: 101', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/cargo-chef-0.1.20/src/recipe.rs:131:27
#17 43.55 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

Missing field id

Hi, I'm learning Tide Following your tutorial It is helping me a lot

Now, I'm in https://javierviola.com/post/03-basic-crud-with-rust-using-tide-move-to-db/

If you do not spend an id from the client, it returns an error that does not have a valid id

in:

 async fn create(mut req: Request<State>) -> tide::Result {
        let dino: Dino = req.body_json().await?;
        // dino.id = Uuid::new_v4();
        let db_pool = req.state().db_pool.clone();
        let row = query_as!(
            Dino,
            r#"
            INSERT INTO dinos (id, name, weight, diet) VALUES
            ($1, $2, $3, $4) returning id, name, weight, diet
            "#,
            dino.id,            
            dino.name,
            dino.weight,
            dino.diet
        )
        .fetch_one(&db_pool)
        .await?;

        let mut res = Response::new(201);
        res.set_body(Body::from_json(&row)?);
        Ok(res)
    }

I try

Uuid::new_v4()
instead

dino.id

but without success

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.