<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Bobbie Soedirgo</title>
    <description>The latest articles on DEV Community by Bobbie Soedirgo (@soedirgo).</description>
    <link>https://dev.to/soedirgo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F392000%2Fd4d056ca-cde4-4121-93d4-5bc6d5d980c7.jpeg</url>
      <title>DEV Community: Bobbie Soedirgo</title>
      <link>https://dev.to/soedirgo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/soedirgo"/>
    <language>en</language>
    <item>
      <title>A Rust Client for PostgREST</title>
      <dc:creator>Bobbie Soedirgo</dc:creator>
      <pubDate>Wed, 10 Jun 2020 12:59:25 +0000</pubDate>
      <link>https://dev.to/supabase/a-rust-client-for-postgrest-4ka5</link>
      <guid>https://dev.to/supabase/a-rust-client-for-postgrest-4ka5</guid>
      <description>&lt;p&gt;At &lt;a href="https://supabase.io" rel="noopener noreferrer"&gt;Supabase&lt;/a&gt;, we rely heavily on &lt;a href="https://postgrest.org/en/stable/index.html" rel="noopener noreferrer"&gt;PostgREST&lt;/a&gt;, an open source tool that turns your Postgres database into a RESTful API. We even have our own JavaScript client for it in the form of &lt;a href="https://github.com/supabase/postgrest-js" rel="noopener noreferrer"&gt;postgrest-js&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;But I use Rust, and it's required by my religion to rewrite everything in Rust, so rewrite it I did. To wit: &lt;a href="https://github.com/supabase/postgrest-rs" rel="noopener noreferrer"&gt;postgrest-rs&lt;/a&gt; 🦀.&lt;/p&gt;

&lt;h1&gt;
  
  
  🤔 What can I do with it?
&lt;/h1&gt;

&lt;p&gt;postgrest-rs brings an ORM interface to PostgREST. This means you can interact with Postgres (through PostgREST) from within Rust. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;postgrest&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Postgrest&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;Postgrest&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"https://your.postgrest.endpoint"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;resp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;
    &lt;span class="nf"&gt;.from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"table"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;.select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"*"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;.execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;.await&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  🤷‍♀️ Why would I want it?
&lt;/h1&gt;

&lt;p&gt;Say I have a table of &lt;code&gt;users&lt;/code&gt;, and I want to know the name of the last user that logged on. In PostgREST, you do this by making the following request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET https://your.postgrest.endpoint/users?select=username&amp;amp;order=last_seen.desc HTTP/1.1
Accept: application/vnd.pgrst.object+json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This gets cumbersome and error-prone as queries get more complex. Compare this to its equivalent in postgrest-rs, which feels more at home:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;Postgrest&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"https://your.postgrest.endpoint"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;resp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;
    &lt;span class="nf"&gt;.from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"users"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;.select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"username"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;.order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"last_seen.desc"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;.single&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;.execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;.await&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are many other cool stuff you can do, such as switching schemas, row filtering, calling stored procedures, and much more. You can check out the repo &lt;a href="https://github.com/supabase/postgrest-rs" rel="noopener noreferrer"&gt;here&lt;/a&gt; and play around with it. &lt;/p&gt;

&lt;p&gt;And there you have it! 🎉&lt;/p&gt;

&lt;p&gt;This project is part of my internship at Supabase. I saw that there was an interest in a &lt;a href="https://github.com/supabase/supabase/issues/5" rel="noopener noreferrer"&gt;Rust client library&lt;/a&gt;, and offered to work on that, among other things. Soon after, I'm writing a Rust library, and it was great! So credit where it's due: the Supabase team for all the support, and of course, PostgREST! &lt;/p&gt;




&lt;p&gt;We'll announce all our future features with more freebies here on DEV first. Follow us so that you don't miss out.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://app.supabase.io" rel="noopener noreferrer"&gt;Sign up&lt;/a&gt; for our early alpha!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmc0g5gv3k3py5jsh8rdr.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmc0g5gv3k3py5jsh8rdr.gif" alt="Follow us on dev.to"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
