rust-diesel

the trait `diesel::Expression` is not implemented for `bigdecimal::BigDecimal`

回眸只為那壹抹淺笑 提交于 2020-05-29 03:53:46
问题 I am trying to create a struct that I can use in diesel for insertion. Specifically I am making the struct Insertable. On compile I get this error. I have a struct that I am trying to make Insertable via the derive attribute. I have a field called Bounty which is supposed to represent money, so I'm using BigDecimal as the type. Upon compilation, I get the error in the title. I've also tried using f64 but that gives the same error. #[macro_use] extern crate diesel; extern crate bigdecimal; mod

Rust/Diesel: How to query and insert into postgres tables which have uuid

心不动则不痛 提交于 2020-05-12 11:59:45
问题 I have the following schema generated by Diesel: table! { user (id) { id -> Uuid, name -> Text } and the associated model use diesel::{ self, Queryable, Insertable, }; use diesel::prelude::*; use diesel::sql_types::Uuid; use super::schema::user; #[derive(Queryable)] pub struct User { pub id: Uuid, pub name: String, } impl User { pub fn get(id: i32, connection: &PgConnection) -> Vec<User> { user::table.load::<User>(connection).unwrap() } } I get an error when I try to compile this which says:

Rust/Diesel: How to query and insert into postgres tables which have uuid

做~自己de王妃 提交于 2020-05-12 11:59:12
问题 I have the following schema generated by Diesel: table! { user (id) { id -> Uuid, name -> Text } and the associated model use diesel::{ self, Queryable, Insertable, }; use diesel::prelude::*; use diesel::sql_types::Uuid; use super::schema::user; #[derive(Queryable)] pub struct User { pub id: Uuid, pub name: String, } impl User { pub fn get(id: i32, connection: &PgConnection) -> Vec<User> { user::table.load::<User>(connection).unwrap() } } I get an error when I try to compile this which says:

Deleting from an associated table with a subquery using Diesel from a postgres database

做~自己de王妃 提交于 2020-04-14 08:59:09
问题 I have a query that I am trying to translate from SQL into rust/diesel but am running into issues with creating a subquery using diesel. I am using diesel = "1.4.2" along with the postgres feature. I have the following schema and models... #[macro_use] extern crate diesel; mod schema { table! { jobs (id) { id -> Int4, } appointments (id) { id -> Int4, } categories (id) { id -> Int4 } appointments_categories(appointment_id, category_id) { appointment_id -> Int4, category_id -> Int4 } } } mod

Querying a Diesel table with dynamic parameters

笑着哭i 提交于 2020-04-13 01:04:20
问题 I was starting to look into using Diesel for querying a database. I have a table that looks something like the struct below (this is just a toy project to help me understand how Diesel works). #[derive(Queryable, Insertable)] #[table_name="posts"] struct Post { id: String, title: String, body: String, published: bool } Doing queries that are fully determined at compile time is easy enough, for example posts.select(id, title).order(title.desc()); What is not clear to me is how to build a query

Creating Diesel.rs queries with a dynamic number of .and()'s

不问归期 提交于 2019-12-19 07:09:08
问题 While playing with Diesel, I got stuck writing a function which takes an vector of String s as input and does the following: Combine all String s to a large query run the query on the Connection process the result return a Vec If I construct the query in one step, it works just fine: fn get_books(authors: Vec<String>, connection: SqliteConnection) { use schema::ebook::dsl::*; let inner = author .like(format!("%{}%", authors[0])) .and(author.like(format!("%{}%", authors[1]))) .and(author.like

How do I get an Option<T> instead of an Option<Vec<T>> from a Diesel query which only returns 1 or 0 records?

£可爱£侵袭症+ 提交于 2019-12-10 16:21:27
问题 I'm querying for existing records in a table called messages ; this query is then used as part of a 'find or create' function: fn find_msg_by_uuid<'a>(conn: &PgConnection, msg_uuid: &Uuid) -> Option<Vec<Message>> { use schema::messages::dsl::*; use diesel::OptionalExtension; messages.filter(uuid.eq(msg_uuid)) .limit(1) .load::<Message>(conn) .optional().unwrap() } I've made this optional as both finding a record and finding none are both valid outcomes in this scenario, so as a result this