<div dir="ltr">Hi list.<div class="gmail_extra"><br><br><div class="gmail_quote">2014-06-05 17:20 GMT+09:00 Chris Morgan <span dir="ltr"><<a href="mailto:me@chrismorgan.info" target="_blank">me@chrismorgan.info</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="">On Thu, Jun 5, 2014 at 9:01 AM, Brian Anderson <<a href="mailto:banderson@mozilla.com">banderson@mozilla.com</a>> wrote:<br>

> # Date/Time (<a href="https://github.com/mozilla/rust/issues/14657" target="_blank">https://github.com/mozilla/rust/issues/14657</a>)<br>
><br>
> Our time crate is very minimal, and the API looks dated. This is a hard<br>
> problem and JodaTime seems to be well regarded so let's just copy it.<br>
<br>
</div>I suggest that anyone interested in doing this read<br>
<a href="https://github.com/mozilla/rust/wiki/Lib-datetime" target="_blank">https://github.com/mozilla/rust/wiki/Lib-datetime</a> and also, following<br>
on from that, <a href="https://github.com/luisbg/rust-datetime" target="_blank">https://github.com/luisbg/rust-datetime</a> and<br>
<a href="https://mail.mozilla.org/pipermail/rust-dev/2013-September/005528.html" target="_blank">https://mail.mozilla.org/pipermail/rust-dev/2013-September/005528.html</a><br>
<div class=""><br>
> # SQL (<a href="https://github.com/mozilla/rust/issues/14658" target="_blank">https://github.com/mozilla/rust/issues/14658</a>)<br>
><br>
> Generic SQL bindings. I'm told SqlAlchemy core is a good system to learn<br>
> from.<br>
</div>This is still an area for significant research. I believe that a<br>
system more similar to LINQ to SQL<br>
<<a href="http://msdn.microsoft.com/en-us/library/bb425822.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/bb425822.aspx</a>> than to<br>
SQLAlchemy is appropriate for our language; we have a good type system<br>
and the ability to do fancy compile-time things, so we should be using<br>
it.<br>
<br>
Also, incidentally, both of these things are higher-level tools; I<br>
would also like to see an attempt at safe SQL, e.g. `sql!(SELECT bar<br>
FROM foo)`. There are various things that Rust can do in that way,<br>
efficiently and correctly, that other languages can’t, and I’d like to<br>
see it tried out as an approach. The basic idea would be that any SQL<br>
would be permitted there and would be mapped onto type-safe constructs<br>
in Rust, all the way down to producing a struct type for each query<br>
with just the appropriate fields and so on. It might turn out to be a<br>
dud idea in the end, but I think it should be tried.<br>
<br>
As an aside, I am intending to post more about my vision for<br>
HTTP/web/SQL in Rust in the coming week which will have a few more<br>
details on these things.<br>
<div class=""><div class="h5">_______________________________________________<br>
Rust-dev mailing list<br>
<a href="mailto:Rust-dev@mozilla.org">Rust-dev@mozilla.org</a><br>
<a href="https://mail.mozilla.org/listinfo/rust-dev" target="_blank">https://mail.mozilla.org/listinfo/rust-dev</a><br>
</div></div></blockquote></div><br></div><div class="gmail_extra">Actually, I was working on a small project, just to see if it's possible to create type-safe SQL library for Rust.</div><div class="gmail_extra"><br></div>
<div class="gmail_extra"><a href="https://github.com/kimhyunkang/rust-sql">https://github.com/kimhyunkang/rust-sql</a><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">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.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">So far, it supports very basic mappings between POD struct and SQL table</div><div class="gmail_extra"><br></div><div class="gmail_extra"><font face="courier new, monospace">#[sql_table]</font></div>
<div class="gmail_extra"><font face="courier new, monospace">pub struct TestTable {</font></div><div class="gmail_extra"><font face="courier new, monospace">    pub a: Option<int>,</font></div><div class="gmail_extra">
<font face="courier new, monospace">    pub b: String</font></div><div class="gmail_extra"><font face="courier new, monospace">}</font></div><div class="gmail_extra"><br></div><div class="gmail_extra">I implemented basic insert and "select * from table" operations for above table.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra"><pre style="font-family:Consolas,'Liberation Mono',Monaco,Courier,monospace;font-size:12px;margin-top:0px;margin-bottom:0px;color:rgb(51,51,51);line-height:18px">
<div class="" id="LC61" style="padding-left:10px;height:18px"><span class="" style="font-weight:bold">let</span> <span class="">db</span> <span class="" style="font-weight:bold">=</span> <span class="">sqlite3</span><span class="" style="font-weight:bold">::</span><span class="">open</span><span class="">(</span><span class="" style="color:rgb(221,17,68)">"insert_test.sqlite3"</span><span class="">).</span><span class="">unwrap</span><span class="">();</span></div>
<div class="" id="LC62" style="padding-left:10px;height:18px"><span class="" style="font-weight:bold">let</span> <span class="">records</span> <span class="" style="font-weight:bold">=</span> <span class="">[</span></div>
<div class="" id="LC63" style="padding-left:10px;height:18px">    <span class="">TestTable</span> <span class="">{</span> <span class="">a</span><span class="" style="font-weight:bold">:</span> <span class="">None</span><span class="">,</span> <span class="">b</span><span class="" style="font-weight:bold">:</span> <span class="" style="color:rgb(221,17,68)">"Hello, world!"</span><span class="">.</span><span class="">to_str</span><span class="">()</span> <span class="">},</span></div>
<div class="" id="LC64" style="padding-left:10px;height:18px">    <span class="">TestTable</span> <span class="">{</span> <span class="">a</span><span class="" style="font-weight:bold">:</span> <span class="">Some</span><span class="">(</span><span class="" style="color:rgb(0,153,153)">1</span><span class="">),</span> <span class="">b</span><span class="" style="font-weight:bold">:</span> <span class="" style="color:rgb(221,17,68)">"Goodbye, world!"</span><span class="">.</span><span class="">to_str</span><span class="">()</span> <span class="">}</span></div>
<div class="" id="LC65" style="padding-left:10px;height:18px"><span class="">];</span></div><div class="" id="LC66" style="padding-left:10px;height:18px"><br></div><div class="" id="LC67" style="padding-left:10px;height:18px">
<span class="">db</span><span class="">.</span><span class="">create_table_if_not_exists</span><span class="" style="font-weight:bold">::<</span><span class="">TestTable</span><span class="" style="font-weight:bold">></span><span class="">();</span></div>
<div class="" id="LC68" style="padding-left:10px;height:18px"><span class="">db</span><span class="">.</span><span class="">insert_many</span><span class="">(</span><span class="">records</span><span class="">.</span><span class="">iter</span><span class="">());

</span></div><div class="" id="LC68" style="padding-left:10px;height:18px"><span class=""><span class="" style="font-weight:bold"><br></span></span></div><div class="" id="LC68" style="padding-left:10px;height:18px"><span class="" style="font-weight:bold">let</span> select_<span class="">records</span><span class="" style="font-weight:bold">:</span> <span class="">Vec</span><span class="" style="font-weight:bold"><</span><span class="">TestTable</span><span class="" style="font-weight:bold">></span> <span class="" style="font-weight:bold">=</span> <span class="">db</span><span class="">.</span><span class="">select_all</span><span class="">().</span><span class="">collect</span><span class="">();</span><br>
</div><div class="" id="LC68" style="padding-left:10px;height:18px"><span class=""><span class=""><br></span></span></div><div class="" id="LC68" style="padding-left:10px;height:18px"><span class=""><span class=""><b>assert_eq!(</b></span></span>select_<span class="">records, records</span><b>);</b></div>
</pre></div><div class="gmail_extra"><br></div><div class="gmail_extra">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.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">Maybe a LINQ-like Haskell project esqueleto ( <a href="https://hackage.haskell.org/package/esqueleto">https://hackage.haskell.org/package/esqueleto</a> ) 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).</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">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.</div>
</div>