Giter Club home page Giter Club logo

Comments (11)

neverchanje avatar neverchanje commented on June 6, 2024 3

Hope this feature can be supported. If you don't have time, I can write a PR for that.

from duckdb-rs.

wangfenjin avatar wangfenjin commented on June 6, 2024 2

And please add some tests to the new features, feel free to support one type a time

from duckdb-rs.

Swoorup avatar Swoorup commented on June 6, 2024 2

I think struct/enums/unions would likely need some kind of derivation support via proc macros. This is an interesting example for clickhouse client where the author modified serde to enable support for struct <-> row mapping. See klickhouse_derive
https://github.com/Protryon/klickhouse

from duckdb-rs.

Swoorup avatar Swoorup commented on June 6, 2024 1

Would be great if we could also be able to retrieve SRUCT, MAP, ENUMs and UNION along with being able to insert them. I think the insert just needs string representation vs the retrieval needs to be convert from arrow format?

Am I correct @wangfenjin ?

from duckdb-rs.

wangfenjin avatar wangfenjin commented on June 6, 2024 1

Correct.

  1. If you want to support bind struct or other type as params, you may need to update bind_params
  2. If you want to support parse sql result as rust native datatypes like map, you may need to update get
  3. If it's a new native datatypes, you need to impl the FromSql and ToSql trait, example serde_json
  4. You may also want to add new type to enum Value when necessary, if you do that compiler will teach you multiple related places that also need to updated

@Swoorup

from duckdb-rs.

v1gnesh avatar v1gnesh commented on June 6, 2024 1

Correct.

1. If you want to support bind struct or other type as params, you may need to update [bind_params](https://github.com/wangfenjin/duckdb-rs/blob/d2f611f922792ec6943a4f65301c81e247864fc0/src/statement.rs#L414)
2. If you want to support parse sql result as rust native datatypes like map, you may need to update [get](https://github.com/wangfenjin/duckdb-rs/blob/d2f611f922792ec6943a4f65301c81e247864fc0/src/row.rs#L544)
3. If it's a new native datatypes, you need to impl the FromSql and ToSql trait, example [serde_json](https://github.com/wangfenjin/duckdb-rs/blob/d2f611f922792ec6943a4f65301c81e247864fc0/src/types/serde_json.rs#L8-L27)
4. You may also want to add new type to enum [Value](https://github.com/wangfenjin/duckdb-rs/blob/d2f611f922792ec6943a4f65301c81e247864fc0/src/types/value.rs#L10) when necessary, if you do that compiler will teach you multiple related places that also need to updated

@wangfenjin If I try like in point 3, it says (edited out the error; I just had to add the relevant features).

Could you show an example, please, of how I can insert a String (valid JSON String) or a Vec<u8> containing a valid JSON String?
If I try, I only see the new row as bytes (hex bytes shown in decimal for each character, and not a string).
I created the table beforehand with create table tab (col1 STRING). Even tried the type TEXT and JSON.
All just get inserted as bytes.
Even with the serde_json example, I still see only bytes in decimal inserted into the table.

Will duckdb-rs add native support for Rust data types (struct/enum at least)?

from duckdb-rs.

wangfenjin avatar wangfenjin commented on June 6, 2024

Havenโ€™t been supported in rust yet

from duckdb-rs.

digizeph avatar digizeph commented on June 6, 2024

@wangfenjin appreciate your work! Just want to insert here that missing insert of lists is a deal breaker for my projects. Hope to see that implemented soon. Cheers!

from duckdb-rs.

Swoorup avatar Swoorup commented on June 6, 2024

Recent support for Union types too. ๐Ÿ‘๐Ÿผ Natural fits with Rust's enum.

from duckdb-rs.

wangfenjin avatar wangfenjin commented on June 6, 2024

@neverchanje it'll be great if you can help. Thanks

from duckdb-rs.

wangfenjin avatar wangfenjin commented on June 6, 2024

The overall idea is in order to make it easier for users, we need to implement the convert logic of from/to sql. After doing this, you will be more familiar with the rust API and also the C API

from duckdb-rs.

Related Issues (20)

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.