Comments (3)
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.
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.
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)
- Update to diesel 2.0 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from diesel_json.