Questions tagged [rust-diesel]

This tag should be used for questions related to the diesel Rust ORM.

Diesel is an object relational mapper written in Rust. Diesel makes it easy to interact with SQL databases such as PostgreSQL and SQLite in a type-safe way.

Producing a Minimal, Reproducible Example (MRE) for Diesel

All of the general rules for a MRE apply, as do those for creating a Rust-specific MRE (see "Producing a Minimal, Reproducible Example (MRE) for Rust code").

You should include information like:

  • What database system you are using (e.g. Postgres, MySQL, SQLite, etc.)
  • Your schema definition(s)
  • Your model definition(s)

You can combine all of your code into a single file, like this:

#[macro_use]
extern crate diesel;

mod schema {
    table! {
        users (user_id) {
            user_id -> Int4,
            email -> Text,
        }
    }

    #[derive(Debug, Identifiable)]
    #[primary_key(email)]
    pub struct User {
        pub user_id: i32,
        pub email: String,
    }
}

fn main() {}
392 questions
-1
votes
1 answer

Trait ManageConnection not implemented for DieselConnectionManager in Rust

I am having a problem with the DieselConnectionManager type from the bb8-diesel crate in my Rust project. Specifically, the error message says: the trait ManageConnection is not implemented for…
Mr Coder
  • 13
  • 1
  • 9
-1
votes
1 answer

Left join in rust diesel

I have book data in my PostgreSQL database. I need to get the last chapter for every book. I need information about Null values in book chapters. That's why I use left join. #[derive(Associations, Identifiable, Queryable, PartialEq, Debug,…
-1
votes
1 answer

How to get average of a column using rust diesel?

I am trying to get the average value of a column using rust diesel but am stuck with the type error. Error: the trait bound `f64: FromSql` is not satisfied the following other types implement trait `FromSql`:
Nane
  • 2,370
  • 6
  • 34
  • 74
-1
votes
1 answer

Diesel migration force String instead of Uuid in schema.rs

I have a problem with the diesel migration. I need to implement Uuid as primary key for a model. I got a lot of issues with the Uuid integration (feature uuidv07, uuid crate,..) but when I specify the type uuid in the migration, diesel generate a…
jenoh
  • 165
  • 3
  • 17
-1
votes
1 answer

How to use rust diesel with yew or any frontend?

I build a rust database with diesel just like the docs and it worked fine in the terminal commands fn main() { use database::schema::posts::dsl::*; let connection = establish_connection(); let results =…
Ali Husham
  • 816
  • 10
  • 31
-1
votes
2 answers

diesel mysql how to set time_zone

I am using diesel 1.4.8, with mysql database, I want to set SET time_zone = '+8:00'; for each link, but diesel sets default config after each connection, but these config Not what I want, how can I modify the default configuration of diesel…
januw a
  • 2,056
  • 5
  • 18
  • 39
-1
votes
1 answer

use the path separator to refer to an item

I want do using rust diesel filter method to add a filter condition like this: #[macro_use] extern crate diesel; use crate::schema::dict::id; mod schema; mod models; fn main() { use crate::diesel::prelude::*; use crate::schema::dict; …
spark
  • 663
  • 1
  • 5
  • 18
-1
votes
1 answer

rust postgresql sql_query syntax error at end of input

When using diesel with my rust code, every time I use the sql_query with bind arguments, which means we use question mark for argument placement I got this error, "syntax error at end of input", no matter I use client_name (varchar) or id (int) for…
Michaelzh
  • 441
  • 5
  • 14
-1
votes
1 answer

Is it possible to add derive annotations when generating Diesel models via diesel_cli_ext?

I am using diesel_cli_ext to generate Rust model code: diesel_ext --schema-file src/model/diesel/dolphin/dolphin_schema.rs --model > src/model/diesel/dolphin/dolphin_models.rs The generated model looks like this: #[derive(Queryable, Debug)] pub…
Dolphin
  • 29,069
  • 61
  • 260
  • 539
-1
votes
1 answer

Trait diesel::Expression not implemented for NaiveDate, but it is for NaiveDateTime

I am trying to use chrono::NaiveDate as a database model field. Here is the model: use chrono::{NaiveDate, NaiveDateTime}; use diesel::{Insertable, Queryable}; use serde::{Deserialize, Serialize}; use crate::schema::users; #[derive(Debug,…
tedtanner
  • 577
  • 6
  • 19
-1
votes
1 answer

How to install diesel-cli with sqlite support under NixOS and cargo?

When i try to install the diesel-cli with cargo install diesel_cli --no-default-features --features sqlite under NixOS, i get error: linking with `cc` failed: exit status: 1 ... = note:…
manews
  • 340
  • 2
  • 12
-1
votes
1 answer

Crate with diesel and mysql dependencies no longer compiles against mariadb after upgrading NixOS to 20.03

My crate, which depends on diesel with the mysql feature enabled, no longer compiles after upgrading my system from NixOS 19.09 to 20.03. It seems the only significant change is an update of the mariadb-server package from 10.2.17 to 10.3.18. There…
palik
  • 2,425
  • 23
  • 31
-1
votes
1 answer

Diesel fetch single parent and many children - Rocket

I've been able to get all parents along with all children Anyone has an idea how to get a single parent with all children? pub struct CityAndNeighbourhoods(CustomerCity, Vec>); pub fn…
moh_abk
  • 2,064
  • 7
  • 36
  • 65
-2
votes
1 answer

the trait `LoadConnection` is not implemented for `deadpool::managed::Object>`

Context I'm currently trying to implement deadpool_diesel and diesel to my api made with Axum but I'm getting an error that I'm not sure to understand. My guess is that I'm maybe doing something wrong with the usage of State but I'm still…
MidKnight
  • 75
  • 7
-2
votes
2 answers

error: Column `article_content` cannot be named the same as its table

I am using this command to generate model using diesel_ext: diesel_ext --schema-file src/model/diesel/dolphin/dolphin_schema.rs --model When I using cargo build to compile the project. It shows an error like this: error: Column `article_content`…
Dolphin
  • 29,069
  • 61
  • 260
  • 539
1 2 3
26
27