diesel-rs / diesel_full_text_search

MIT License
72 stars 33 forks source link

Update / insert TsVector value? #19

Open kaj opened 4 years ago

kaj commented 4 years ago

Is it possible to update or insert a TsVector value? I would expect to be able to do something like:

    use crate::schema::mytable::dsl as my;
    insert_into(my::mytable)
       .values((
             my::some_text.eq(some_text),
             my::ts.eq(to_tsvector(some_text),
        ))
        .execute(db)?;

But I get the error that the method eq is not found in the column declaration. i'd say some trait is missing, but I don't (yet) know if my code is just missing some use statement or if TsVector is missing some impl statement. Maybe it needs to impl SingleValue?

weiznich commented 4 years ago

Yes the SingleValue impl is missing. For a more idiomatic implementation I would just replace this impsl with a SqlType derive on the corresponding type definitions, as such a derive provides all of the required impls out of the box.

dchenk commented 3 years ago

@weiznich is the SingleValue implementation missing on purpose, or can it simply be added to support inserting rows with a TsVector column?

A related issue: Insertable cannot be derived on a TsVector because the trait bound Expression is not satisfied.

weiznich commented 3 years ago

@dchenk Please don't ping me to just ask questions.

is the SingleValue implementation missing on purpose, or can it simply be added to support inserting rows with a TsVector column

As written above: That's something that could likely be improved. Its nothing that has priority for me as the main reason why this crate even exists is to showcase how to add support for postgres extensions as diesel extension crate. This implies that this crate is not primarily be designed to be used in production somewhere. Doing that is certainly possible, but don't expect much support here. This may change if diesels maintainer situation changes or if someone steps up to maintain this crate on their own.

A related issue: Insertable cannot be derived on a TsVector because the trait bound Expression is not satisfied.

Thats on purpose as TsVector is a zero sized type that cannot hold any value on rust side.