Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upGeneric SQL bindings #798
Comments
steveklabnik
added
the
A-wishlist
label
Feb 2, 2015
This comment has been minimized.
This comment has been minimized.
dckc
commented
Feb 4, 2015
|
The sqlite bindings I maintain, rust-sqlite3, are heavily influenced by rust-postgres, but the ownership patterns are very different. Any API that abstracts across them is going to have to do a bunch of copying/cloning, I'm afraid. I'm not very familiar with Rc nor RefCell, on the other hand. Perhaps they would reduce the friction? |
This comment has been minimized.
This comment has been minimized.
s-panferov
commented
Feb 4, 2015
|
I have an experiment in https://github.com/deuterium-orm and there is some success. The projects lagged behind Rust's nightlies, but I'm going to refactor them in the next couple of days. (Note that only rust-postgres is supported as a backend now). |
This comment has been minimized.
This comment has been minimized.
koeninger
commented
Feb 14, 2015
|
I personally would prefer not to be forced into compile time checking of sql. Every system I've used that attempted such ended up causing problems getting my job done in some important corner case. |
steveklabnik
added
A-community-library
and removed
A-wishlist
labels
Feb 14, 2015
This comment has been minimized.
This comment has been minimized.
ivanceras
commented
Jul 22, 2015
|
Plugging in my ORM that I have been working on. Supported Database
And the code generator build on top of the ORM Contributions and feedbacks are much welcome. |
This comment has been minimized.
This comment has been minimized.
dckc
commented
Aug 20, 2015
|
There's "lots of demand for this recently" according to the Production user research summary. |
This comment has been minimized.
This comment has been minimized.
oberien
commented
Sep 1, 2015
|
I actually like the approach of C# (linq) and would love to see this kind of syntactic sugar in rust, including the support to both use it for queries on lists/enumerables and directly transform it into DB-Queries. |
This comment has been minimized.
This comment has been minimized.
|
FWIW the state of the art on the Haskell side seems to be Opaleye and Relational Record - just for reference. EDIT: See also! |
This comment has been minimized.
This comment has been minimized.
rumatoest
commented
Nov 10, 2015
|
I think that you should not focus on implementations at all. Think that main approach should be taken from Go https://golang.org/pkg/database/sql/ And I think that Rust can do more in this area:
|
This comment has been minimized.
This comment has been minimized.
GildedHonour
commented
Jan 8, 2016
|
Is anybody working already? Is this https://github.com/deuterium-orm/deuterium it? |
This comment has been minimized.
This comment has been minimized.
Ygg01
commented
Feb 2, 2016
|
@GildedHonour No? And deuterium probably isn't that. Deuterium is a project built on top of r2d2 and connection pool it provides. |
This comment has been minimized.
This comment has been minimized.
rickprice
commented
Oct 16, 2017
|
What is happening with this RFC? Is there a concrete implementation proposal? |
This comment has been minimized.
This comment has been minimized.
rumatoest
commented
Oct 16, 2017
|
I hope that after @sfackler stabilize postgresql library then this work will be used as a basis for future RFC. |
This comment has been minimized.
This comment has been minimized.
|
@rickprice this isn't a full RFC, only an issue. This means that there hasn't been a concrete proposal yet. |
petrochenkov
added
the
T-libs
label
Jan 30, 2018
This comment has been minimized.
This comment has been minimized.
|
There are now quite a few crates in this area now such as: also, this isn't our business, so I'm closing this issue. |
Centril
closed this
Feb 24, 2018
This comment has been minimized.
This comment has been minimized.
rinconjc
commented
Feb 18, 2019
|
Very sad and disappointing that Rust doesn't have something equivalent to Java JDBC or Golang SQL. |
This comment has been minimized.
This comment has been minimized.
rumatoest
commented
Feb 19, 2019
|
Disel is Alive, but it is ORM and ORMs are evil :( @Centril You are absolutely wrong. It is Rust business to provide basic API to work with at least with relational DB. There are many places where you can get basic ideas. Even JDBC like API is a good choice as a draft. |
This comment has been minimized.
This comment has been minimized.
burdges
commented
Feb 19, 2019
|
It's not the core language team's job to design an SQL interface. We all happily use the |
This comment has been minimized.
This comment has been minimized.
rumatoest
commented
Feb 19, 2019
|
I think, that such standardization is required to make Rust platform more attractive for corporate apps development. And from this side ugly Golang way more interesting. P.S. Look at Java world. There are tons of different frameworks that are based on the same DB driver API. The only one issues with JDBC it that it does not support async calls. There are some alternatives DB async drivers incompatible with JDBC, but they are not used by the most popular frameworks, because it is not JDBC. |
This comment has been minimized.
This comment has been minimized.
Ygg01
commented
Feb 19, 2019
•
I disagree that ORMs are evil. But I'd prefer a bit way more options when it comes to Rust DB options.
Not just Java. There is Python as well. But what I fear is a large obstacle is that borrow rules make this more complicated than it should be. |
This comment has been minimized.
This comment has been minimized.
rumatoest
commented
Feb 19, 2019
•
ORMs are dangerous in many cases, because they use different object approach to treat your data and this is not what you really need. But any ORM better should use standartd low level DB API.
But it without it DB API would be extremely fragmented. |
This comment has been minimized.
This comment has been minimized.
|
While there's obviously some potential value in a standardized SQL binding layer to make ORMs and DB drivers interchangeable, that's largely a matter of developing such a layer and then convincing the rest of the Rust ecosystem that the value is real. As far as I know, no one has argued that any of this work needs any changes to the Rust language itself, or needs to be done within This seems like the sort of thing a Database Working Group would do, if one existed. I'd suggest anyone who feels strongly about this should try forming such a working group to actually develop these bindings and prove they'd be worth standardizing on. |
This comment has been minimized.
This comment has been minimized.
rumatoest
commented
Feb 19, 2019
•
That is why I think that rust developers from Mozilla must be involved. It should no be the part for std crate. It must be backed up by Mozilla in some way. Having even RFC draft of DB API backed by Rust developers is way more better, than waiting that rust ecosystem accidentally came to some standard by itself. Probably it would come to some standard in 10 years or so, but this is unacceptable time wasting and huge stopper for pushing Rust into masses. P.S. I would gladly participate in such project but only if it will be backed by Rust team. In other case such initiative would likely to fail. |
This comment has been minimized.
This comment has been minimized.
|
I don't think the pessimism about non-formally-Rust-backed initiatives is supported by the track record of the Rust ecosystem thus far. |
This comment has been minimized.
This comment has been minimized.
mamcx
commented
Feb 19, 2019
|
I have made a ORM in each language I have worked on (at least 7). I have used at least as much others ORMs in many platforms. I like databases so much, that I'm trying to build a relational language! 1- No "ORM" or "micro-orm" will work for all. None. Is just a fact that you will learn on The Vietnam of Computer Science. This is focused on OOP, but the impedance mismatch is much more generalized. No language that is not relational will be good enough. 2- But a lot can be automated/simplified. Mapping, for example. With the From trait rust have something very powerful that is not matched elsewhere (that I know or remember). 3- Instead, do similar to Python Database API Specification. Give some traits and features to be used as foundation for any database/orm layer. I think python have almost the best API specification around, and also is kind of easy of fulfill (other languages have things similar, but much more arcane to plug into). 4- The main thing is have a narray-like interface tailored for tabular data. That is all. Give From traits to convert the data and let each ORM layer to build on top. |
This comment has been minimized.
This comment has been minimized.
Ygg01
commented
Feb 19, 2019
Don't like all databases come with a relational language (SQL)? As for the rest of the argument, I'd consider it more plausible if there weren't tools that manage to abstract the divide in a really elegant manner like jOOQ and SqlAlchemy. |
This comment has been minimized.
This comment has been minimized.
mamcx
commented
Feb 19, 2019
Yes, but I'm not saying "building a RDBMS", instead "a language" like python, Lua, etc...
Pay attention to how them do that. Is far from simple. Sql Alchemy/jooq use all the tricks in the book to try to make a decent interface. Something like the DB-API is just a step towards build something like sql alchemy, but exist a lot to do before get there. |
This comment has been minimized.
This comment has been minimized.
rdbc-root
commented
Feb 19, 2019
|
A new org/repo has just been created to design and build the basic DB connectivity layer for Rust. https://github.com/rust-dbc/rdbc Please request membership and contribute Thank you |
This comment has been minimized.
This comment has been minimized.
weiznich
commented
Feb 19, 2019
|
As diesel core team member I want to use this possibility to clarify some common misunderstandings about diesel.
I see diesel not as ORM in it's core functionality. Yes there are certain ORM functionalities, but even those are a bit different than most traditional ORM's.
The backend and connection abstraction are fundamental, all other parts could be combined as needed (or wanted). So if someone is just interested in a common interface to execute raw sql queries just grab
Sure no approach will work for everyone. (That's a bold argument that some SQL binding does not belong into a standard library!). Therefore we have several ways in diesel to provide hand written SQL pieces.
That written: Diesel has currently it's own set of issues when it comes to highly dynamic queries where not even the type and number of output values is known at compile time. (That is fixable, just needs some work). Also it is currently required to know the used backend at compile time. (It's possible to write code that supports multiple backends but that could be easier (== not requiring that much trait bounds))
Obviously I'm biased here but that I think that's already done by the connection trait in diesel. Beside of that I'm happy to see an alternative approach on that problem Finally my opinion to the question if something like a basic DB connectivity layer should be part of the standard library: No, because that would basically froze the design and prevent in cooperating possible future improvements. (The DBMS development by itself is not frozen so I assume that there will be changes over time how such an interface could look like.) Additionally it's possible to write that as third party crate and it's not something that is fundamental for all kinds of applications. |
This comment has been minimized.
This comment has been minimized.
rumatoest
commented
Feb 20, 2019
•
It would not work for you this way. Only until you pull a hell of the effort to create 100% API + some implementation by yourself. And only if your vision would be at least at 50% compatible with others needs, that maybe you'll have a chance to make it standard. @weiznich
|
This comment has been minimized.
This comment has been minimized.
weiznich
commented
Feb 20, 2019
I think it's not the right solution to just make the abstraction async. Not every database system out there provides an async API (Notably sqlite does not for example.) Additionally async adds some overhead, both mentally for the implementation and performance wise if the implementing type does not support it. That brings me to the conclusion that it's probably better to have both: An async and a sync interface that could be implemented depending on the actual support.
There is nothing in diesel preventing someone from writing the needed operators to support those query on a specific backend. It's just build in there to say that a given expression is only valid for certain backends. For example see the implementation of the PostgreSQL any function
The target of diesel is to provide some kind of abstraction for SQL based relational databases. This implies that the query language is text based. This does not assume anything about the actual transport protocol used to talk to the database. (For example PostgreSQL uses some sort of (partially) binary protocol there.) |
This comment has been minimized.
This comment has been minimized.
bluetech
commented
Feb 26, 2019
|
A little note on this comment:
Unless I have it wrong, tokio's multithreaded runtime requires |
This comment has been minimized.
This comment has been minimized.
weiznich
commented
Feb 26, 2019
That's all right, but I may have simplified things a bit to much above. So let me elaborate on that a bit more: In the end it boils down to the following: The potential user of such an async implementation will need to write some code that gets a connection and does something with that connection in some async way. Eventually this work will be split up into several function because of reusability, …. Now we want to share the connection between those single methods. async fn do_stuff() -> QueryResult<Stuff> {
let connection = await!(get_connection())?;
let stuff1 = await!(do_stuff1(&connection))?;
await!(do_stuff2(&connection))?
}
async fn do_stuff1(conn: &PgConnection) -> QueryResult<Stuff> {
}
async fn do_stuff2(conn: &PgConnection) -> QueryResult<Stuff> {
}So now we pass a reference into a async function, that means the returned future somehow contains that reference. If we now look into the documentation for |
This comment has been minimized.
This comment has been minimized.
bluetech
commented
Feb 26, 2019
|
Thanks for the explanation @weiznich! So, the return type of |
This comment has been minimized.
This comment has been minimized.
ssokolow
commented
Feb 26, 2019
|
Also, I may be misremembering but, in the lead-up to Rust 1.0, wasn't there a bit of a big deal made of the realization that, on a theoretical level, if something can implement |
This comment has been minimized.
This comment has been minimized.
rumatoest
commented
Feb 27, 2019
•
|
@weiznich @bluetech We are talking about low level API and it should not be perfect. My point is that if you have async API by default that you can use other library which wraps it in sync interface. @weiznich acquiring connection probably should be done in a sync way, or it has to be hidden for user. You should have some kind of connection pool and that you run query over it. Because executing query is async you can do getting connection stuff there like BTW because low level API should no be extremely pretty we can hide 3rd party async libraries API behind callbacks (something like JS dudes do :( )
Looks not pretty, but it is only std Rust without 3rd party libraries. And now it is possible to create wrapper/adapter over it with sync or async (tokio) APIs |
This comment has been minimized.
This comment has been minimized.
rumatoest
commented
Feb 27, 2019
•
|
Actually I see it even in more complex way like.
|
steveklabnik commentedFeb 2, 2015
Wednesday Jun 04, 2014 at 22:17 GMT
For earlier discussion, see rust-lang/rust#14658
This issue was labelled with: A-libs, I-enhancement in the Rust repository
We need a generic library for SQL with implementations for at least MySQL and PostgreSQL.
Prefer a design that has a typed AST that can be checked at compile time. I'm told SqlAlchemy core does this well.
cc @kmcallister
Start out of tree. This crate would ideally be distributed by cargo, not as part of the main distro.