-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rust Support #949
Comments
We have little experience in Rust, but welcome contributions of course. Indeed a possibility is to add to sqlx. |
I'm interested too but I see that rust can't call c++. Does duckdb have a C interface ? |
Yes, the C interface is here. |
Nice, so it should be possible to create a rust binding. I will give a try this next days. Do you have a slack/gitter/IRC channel for my future stupid questions ? |
We do not have these channels, but feel free to ask any questions you have in the issue here. That way other people can also see the discussions (and potentially respond). |
Hi @hannesmuehleisen @Mytherin , currently for the C API, there is no step api for prepared statement, could you please help look into this? it will be very useful for writing iterator style api |
What do you mean by step API? Are you using the sqlite api wrapper? The C API does have support for prepared statements... |
@hannesmuehleisen Oh I'm using duckdb.h , see from here it has prepared statements. Do you suggest me to use the sqlite api wrapper? I think about this before, but I think maybe in the future we will have many custom api so I use the original c api. But seems the c api is quite simple, and it's hard even impossible to use c++ api from rust |
It might be a good choice to use the sqlite api wrapper, as in that case we can reuse most code from rusqlite |
Do we have released version of binary library and header files for sqlite api wrapper? It will be helpful if we decided to use it in rust client |
A potential problem with the SQLite API wrapper is that it is a C API that duplicates the sqlite3 API. This should work fine if we use Another problem with the SQLite API wrappers is that type information is lost in those wrappers, as SQLite is not a strongly typed system and has very few internal types. This might be undesirable, as the types that you could expose using those wrappers are very limited.
I believe we don't have this right now. |
I think the better solution would be the Arrow CDataInterface. |
./duckdb
v0.2.7-dev775 7e1dd71df
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
D CREATE TABLE bar(x INTEGER UNIQUE);
D INSERT INTO bar (x) VALUES (2) ON CONFLICT DO NOTHING;
D INSERT INTO bar (x) VALUES (2) ON CONFLICT DO NOTHING;
Error: Constraint Error: duplicate key value violates primary key or unique constraint |
Indeed its likely that the |
Hi @Mytherin , thanks for your feedback.
Overall I think we should have our own c api which adapt to our design, but at the same time the sqlite api had evolved for such a long time and widely used, it's a great advantage duckdb can have compatible api with it. For the rust wrapper, for now I'll use the sqlite3 wrapper and we can migrate to the duckdb.h after it's get more feature. It's quite usable now I think, what I know is it seems doesn't have transaction and iterator style api like sqlite3_step. |
Hi all, I had adapt rusqlite to work with duckdb, here are the minimum code changes. And we need to merge #1849 before these changes work. If there are no other concerns, I will try to clean to the code and docs and release the package as duckdb-rs. After that we can based on this to add more duckdb specific features. |
I would prefer not to extend the sqlite api wrappers, but instead extend the C API itself. The main purpose of the sqlite API is to enable DuckDB to be used with programs that were written against the SQLite API itself. If additional functionality is required beyond the SQLite API it is better to use our own API rather than having a mix of the SQLite API and some additional API calls.
Yes, I am fine with that. We could add an |
Agree, actually the sqlite api itself is extensible enough to let us inject / hook features we want, as long as we can support the extension related api. But I think we can add some constants to indicate the type as duckdb is static typing, as currently there are too few types in the sqlite api. It should only change the return value of this function with no other side effect. |
Indeed a lot of type information is lost, but this is by design since the API tries to be compatible with SQLite itself (which does not have this type information). I think once you go down the road of customizing the API it is better to rewrite against the C/C++ API. The SQLite API is slow and not really intended for bulk data consumption/transfer. It would be cleaner and faster to use the C API and extend that as required. |
Agree. The C API design is a thing that I don't think I have the ability to do. Do you have any plans about it? Maybe you guys can define the API / requirements, I can help on the implementation. |
@wangfenjin did you use bindgen to wrap the C api? |
@sdmcallister yes, you can refer to here https://github.com/wangfenjin/duckdb-rs/tree/main/libduckdb-sys I haven't publish it, still working on it |
Initial version should be ready next week |
In case anyone interested, I had push my draft version to the master, still a lot of todos |
I'm trying to compile my app, in Windows, with crate
Using |
If you don't want to provide your own copy of the DuckDB compiled library (duckdb.dll in your case), you can use the "bundled" feature. In the future though, please direct rust related questions to https://github.com/duckdb/duckdb-rs |
DuckDB looks like it is solving many issues with embedded databases for me but I work in Rust (and have little C++ experience). Are there plans to release a Rust crate around duckdb?
My ideal solution would be for DuckDB support to be added to the sqlx crate.
The text was updated successfully, but these errors were encountered: