Brendonovich / prisma-client-rust

Type-safe database access for Rust
https://prisma.brendonovich.dev
Apache License 2.0
1.83k stars 108 forks source link

Tauri example has compilation errors #343

Closed niek-peters closed 1 year ago

niek-peters commented 1 year ago

When I tried running the Tauri example in this repo's /examples/tauri directory, I get two compilation errors. Both errors happen in the src-tauri/src/main.rs file.

Installation process

I cloned the repository and moved the /examples/tauri directory to its own folder. I then followed the steps in this projects README.md file. Those steps alone were not enough to run the project. Before being able to run it, I had to change the prisma-client-rust dependency in the Cargo.toml file to match what is shown in the prisma-client-rust documentation:

prisma-client-rust = { git = "https://github.com/Brendonovich/prisma-client-rust", tag = "0.6.8" }
prisma-client-rust-cli = { git = "https://github.com/Brendonovich/prisma-client-rust", tag = "0.6.8" }

I also changed the contents of the src-tauri/.cargo/config.toml file to match what was shown in the documentation and created the CLI Binary as described:

[alias]
prisma = "run --bin prisma --"

And I needed to run pnmp install in the root directory.

These steps would be nice to include in the README.md file for this project.

I added all these files with the changes I made to this GitHub repo so you can check them out: repo link

The errors

The first error happens on line 44, where the collect_types! macro from tauri_specta is used. This line results in the following error:

the trait bound `impl Future<Output = Result<std::vec::Vec<db::post::Data>, QueryError>>: SpectaFunctionResult<_>` is not satisfied
the trait `SpectaFunctionResult<SpectaFunctionResultResult<TMarker>>` is implemented for `Result<T, E>`
required for `fn(tauri::State<'_, Arc<db::_prisma::PrismaClient>>) -> impl Future<Output = Result<std::vec::Vec<db::post::Data>, QueryError>>` to implement `SpectaFunction<(_, TauriMarker)>`

The second one happens on line 47, where the _db_push() function on the PrismaClient is called:

no method named `_db_push` found for struct `db::_prisma::PrismaClient` in the current scope
method not found in `db::_prisma::PrismaClient`

After commenting out both lines, the compilation step completed succesfully, but now I'm missing the tauri_specta functionality, which is a feature I would really like to have.

Brendonovich commented 1 year ago

The examples aren't really supposed to be used outside of the repo, they're just demonstrations that are tied to the main branch. They're more intended to be used as inspiration rather than being separated. With that said, I'll try to address some of the errors you mentioned:

I needed to run pnmp install in the root directory

Good point, I need to mention that

The first error happens on line 44, where the collect_types! macro from tauri_specta is used

You probably need to enable the specta feature in prisma-client-rust-cli

The second one happens on line 47, where the _db_push() function on the PrismaClient is called

Same as previous but for the migrations feature

The prisma-cli folder of this repo is used for running cargo prisma generate for the examples and stuff. It automatically enables the migrations feature, and conditionally allows enabling specta, which is done in src-tauri/.cargo/config.toml with --features specta.