Giter VIP home page Giter VIP logo

Comments (3)

PPakalns avatar PPakalns commented on July 20, 2024

Hi! Thanks for checking out this library.

For now planned scope is to only provide wrapper type that hides implementation details and provides very simple interface for object serialization to, de-serialization from database json, jsonb values.

For now, to use such query in diesel you can use sql_query. There could be other ways too like extending diesel with adding your own expressions.

For implementing type safe "->" json operator, it would require some kind of similar "dsl" schema definition approach for jsonb structure fields as is done now for database schema in diesel. Of course the schema could be generated by procedural macro from type, but for now it is out of the scope of planned features for this library.

Will give notification if something changes :)

from diesel_json.

PPakalns avatar PPakalns commented on July 20, 2024

Small note, operator "->" is partially supported. The returned data can still be parsed with diesel_json::Json.

If you have query like this: '{"a": {"b":"foo"}}'::jsonb->'a'

And you only need support for retrieving and parsing the returned data. You can do something like this.

    #[derive(Serialize, Deserialize, Debug)]
    struct MyStruct {
        b: String
    }
    #[derive(QueryableByName, Debug)]
    struct SelectLayout {
        #[sql_type = "diesel::sql_types::Jsonb"]
        data: diesel_json::Json<MyStruct>
    }

    let result: Vec<SelectLayout> = sql_query(r#"SELECT '{"a": {"b":"foo"}}'::jsonb->'a' as data"#).load(&connection).unwrap();

from diesel_json.

Nutomic avatar Nutomic commented on July 20, 2024

Actually the snippet above was just an example from the postgres docs. My actual query is more complicated, and I noticed while testing that it also needs the ->> operator. So the raw query you suggested is probably the best option, thanks a lot for that!

from diesel_json.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.