!lNGJpfiFVovXFJYmwx:matrix.org

Diesel

663 Members
A safe, extensible ORM and Query Builder for Rust9 Servers

Load older messages


Timestamp Message
5 Dec 2018
18:52:55@gitter_dowwie:matrix.orgDarin (Gitter) @sgrif You gave a good talk about crates.io. Performance tuning postgres for the win!
18:53:32@gitter_dowwie:matrix.orgDarin (Gitter) @sgrif and thank you for taking lead managing these issues
19:06:49@gitter_blankenshipz:matrix.orgZach Blankenship (Gitter) @tanriol I'm not sure what you mean - would that type properly implement std::convert::From<diesel::result::Error>? and would I be able to use it as a generic error with an associated description?
19:32:59@gitter_blankenshipz:matrix.orgZach Blankenship (Gitter)

I managed to work around this by implemeting an error type enum FooError with a variant like Foo(String) that I then implement From diesel::result::Error` for --

impl From<diesel::result::Error> for FooError {
    fn from(error: diesel::result::Error) -> Self {
        FooError::Foo(error.to_string())
    }
}

I then can use this error type as the error value in my transaction - Can anyone tell me why this From<diesel::result::Error> needs to be implemented for this transaction method error? I guess I need help better understand handling errors in general

19:36:56@gitter_blankenshipz:matrix.orgZach Blankenship (Gitter)Should I be defining an error type that has variants for every specific error I expect to see in my application?
23:37:20@gitter_bourgoismickael:matrix.orgMickael Bourgois (Gitter) joined the room.
23:37:20@gitter_bourgoismickael:matrix.orgMickael Bourgois (Gitter) Hello, I try to build a query with sql_query and bind however the bind doesn't work. The example on https://docs.diesel.rs/diesel/query_builder/struct.SqlQuery.html#example doesn't work. It seems that the ? in the query create a syntax error. If i remove the ? and try the query without bind it works fine. Any ideas or is it really a bug ?
23:37:46@gitter_bourgoismickael:matrix.orgMickael Bourgois (Gitter) (edited) ... create a syntax ... => ... create an sql syntax ...
6 Dec 2018
09:43:10@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) @blankenshipz From<diesel::result::Error> needs to be implemented because the the definition of Connection::transaction has this as trait constrain. That signature means that transaction takes a closure F that returns a Result<T, E>. The same type is returned from the transaction function. The error type E needs to implement From<diesel::result::Error>. That impl is required because we call internally into some code to start and end or rollback the transaction. Those functions return Result<_, diesel::result::Error> therefore we need some way to convert those error types in the custom user provided error type.
09:43:50@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) Using an enum error type or failure::Error are good strategies there.
09:46:59@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) @BourgoisMickael That sounds like you are using postgres, right. In that case the bind placeholder is not ?, but $1, $2, and so on. (sql_query literally passes the provided string directly to the database.)
18:56:29@gitter_bourgoismickael:matrix.orgMickael Bourgois (Gitter)Ok thanks, Maybe it should be written in the documentation ?
19:08:12@gitter_weiznich:matrix.orgGeorg Semmler (Gitter)Feel free to submit a PR :wink:
7 Dec 2018
01:07:32@gitter_aceeri:matrix.orgAceeri (Gitter) It seems using type as the column name panics because it doesnt think it is an ident
01:07:55@gitter_aceeri:matrix.orgAceeri (Gitter) I just changed my db and such to use kind 's the column name now though which works
01:08:13@gitter_aceeri:matrix.orgAceeri (Gitter) (edited) ... use kind 's the ... => ... use `kind`as the ...
09:32:53@gitter_weiznich:matrix.orgGeorg Semmler (Gitter)

@Aceeri This should do the trick without renaming the database column:

table! {
    posts {
        id -> Integer,
        /// This column is named `mytype` but references the table `type` column.
        #[sql_name = "type"]
        mytype -> Text,
    }
}

(Literally copied from the documentation of the table! macro)

19:17:57@gitter_rychipman:matrix.orgRyan Chipman (Gitter) joined the room.
19:17:57@gitter_rychipman:matrix.orgRyan Chipman (Gitter)

I'm trying to implement FromSql<Text, DB> for a custom type, but I'm having trouble resolving this compiler error:

error[E0271]: type mismatch resolving `<DB as diesel::backend::Backend>::RawValue == [u8]`
   --> src/game/mod.rs:289:17
    |
289 |         let s = <String as FromSql<Text, DB>>::from_sql(bytes)?;
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found slice
    |
    = note: expected type `<DB as diesel::backend::Backend>::RawValue`
               found type `[u8]`
    = note: required because of the requirements on the impl of `diesel::deserialize::FromSql<diesel::sql_types::Text, DB>` for `*const str`
    = note: required because of the requirements on the impl of `diesel::deserialize::FromSql<diesel::sql_types::Text, DB>` for `std::string::String`
    = note: required by `diesel::deserialize::FromSql::from_sql`

for reference, the full trait implementation:

impl<DB> FromSql<Text, DB> for Hand
where
    DB: Backend,
{
    fn from_sql(bytes: Option<&DB::RawValue>) -> deserialize::Result<Self> {
        let s = <String as FromSql<Text, DB>>::from_sql(bytes)?;
        let hand = Hand::parse(s);
        Ok(hand)
    }
}
19:18:34@gitter_rychipman:matrix.orgRyan Chipman (Gitter) afaict, this is how I'm supposed to implement FromSql, but I can't figure out what my mistake is
19:19:13@gitter_rychipman:matrix.orgRyan Chipman (Gitter) it seems like the problem is related to this impl: https://docs.diesel.rs/src/diesel/type_impls/primitives.rs.html#115-121
19:19:39@gitter_rychipman:matrix.orgRyan Chipman (Gitter) and its trait bound of [u8] for RawValue
19:19:47@gitter_rychipman:matrix.orgRyan Chipman (Gitter) but I'm not sure what I should use as an alternative
19:20:03@gitter_rychipman:matrix.orgRyan Chipman (Gitter)any help would be greatly appreciated!
19:34:26@gitter_weiznich:matrix.orgGeorg Semmler (Gitter) You need a additional trait bound: String: FromSql<Text, DB>
19:38:20@gitter_rychipman:matrix.orgRyan Chipman (Gitter)perfect -- thank you!
23:11:04@zinco:matrix.orgzinco joined the room.
10 Dec 2018
01:35:28@andrew_chou:matrix.organdrew_chou set a profile picture.
04:43:24@gitter_sackery:matrix.orgSackery (Gitter)How to implement Laravel belongsToMany::toggle?
04:43:55@gitter_sackery:matrix.orgSackery (Gitter)if the item existed than delete other insert

There are no newer messages yet.


Back to Room List