[rust-dev] 7 high priority Rust libraries that need to be written

kimhyunkang at gmail.com kimhyunkang at gmail.com
Thu Jun 5 02:11:45 PDT 2014

Hi list.

2014-06-05 17:20 GMT+09:00 Chris Morgan <me at chrismorgan.info>:

> On Thu, Jun 5, 2014 at 9:01 AM, Brian Anderson <banderson at mozilla.com>
> wrote:
> > # Date/Time (https://github.com/mozilla/rust/issues/14657)
> >
> > Our time crate is very minimal, and the API looks dated. This is a hard
> > problem and JodaTime seems to be well regarded so let's just copy it.
> I suggest that anyone interested in doing this read
> https://github.com/mozilla/rust/wiki/Lib-datetime and also, following
> on from that, https://github.com/luisbg/rust-datetime and
> https://mail.mozilla.org/pipermail/rust-dev/2013-September/005528.html
> > # SQL (https://github.com/mozilla/rust/issues/14658)
> >
> > Generic SQL bindings. I'm told SqlAlchemy core is a good system to learn
> > from.
> This is still an area for significant research. I believe that a
> system more similar to LINQ to SQL
> <http://msdn.microsoft.com/en-us/library/bb425822.aspx> than to
> SQLAlchemy is appropriate for our language; we have a good type system
> and the ability to do fancy compile-time things, so we should be using
> it.
> Also, incidentally, both of these things are higher-level tools; I
> would also like to see an attempt at safe SQL, e.g. `sql!(SELECT bar
> FROM foo)`. There are various things that Rust can do in that way,
> efficiently and correctly, that other languages can’t, and I’d like to
> see it tried out as an approach. The basic idea would be that any SQL
> would be permitted there and would be mapped onto type-safe constructs
> in Rust, all the way down to producing a struct type for each query
> with just the appropriate fields and so on. It might turn out to be a
> dud idea in the end, but I think it should be tried.
> As an aside, I am intending to post more about my vision for
> HTTP/web/SQL in Rust in the coming week which will have a few more
> details on these things.
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev

Actually, I was working on a small project, just to see if it's possible to
create type-safe SQL library for Rust.


I did not intend to open this up until it has more features, but it turns
out some people were thinking about similar projects anyway.

So far, it supports very basic mappings between POD struct and SQL table

pub struct TestTable {
    pub a: Option<int>,
    pub b: String

I implemented basic insert and "select * from table" operations for above

let db = sqlite3::open("insert_test.sqlite3").unwrap();
let records = [
    TestTable { a: None, b: "Hello, world!".to_str() },
    TestTable { a: Some(1), b: "Goodbye, world!".to_str() }


let select_records: Vec<TestTable> = db.select_all().collect();

*assert_eq!(*select_records, records*);*

I was also planning to add sql!() macro almost exactly same as Chris Morgan
suggests. However, you can't directly access type-checking part of rustc in
#![phase(syntax)] modules, which means you need some dirty hacks to
peroperly type-check such macros.

Maybe a LINQ-like Haskell project esqueleto (
https://hackage.haskell.org/package/esqueleto ) might be a better path for
us, but I don't know how to implement an equivalent in Rust, as we don't
have GADT (yet).

I'd love any comments, suggestions or a better idea for this project. I
also intend to add my current (very hackish) implementation plan of sql!()
macros few days later.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140605/c4fcd60c/attachment.html>

More information about the Rust-dev mailing list