<?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: Kolawole O. Gabriel</title>
    <description>The latest articles on DEV Community by Kolawole O. Gabriel (@segaz2002).</description>
    <link>https://dev.to/segaz2002</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%2F53950%2F4f6f056f-d77f-40a6-b047-941d33d77dcf.jpeg</url>
      <title>DEV Community: Kolawole O. Gabriel</title>
      <link>https://dev.to/segaz2002</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/segaz2002"/>
    <language>en</language>
    <item>
      <title>Ecto order_by text field</title>
      <dc:creator>Kolawole O. Gabriel</dc:creator>
      <pubDate>Thu, 19 Nov 2020 22:07:50 +0000</pubDate>
      <link>https://dev.to/segaz2002/ecto-orderby-text-field-430m</link>
      <guid>https://dev.to/segaz2002/ecto-orderby-text-field-430m</guid>
      <description>&lt;p&gt;This post demonstrates how to order an ecto query by a text field.&lt;br&gt;
by sending the order raw sql query through &lt;a href="https://hexdocs.pm/ecto/Ecto.Query.API.html#fragment/1"&gt;Ecto.Query.API.fragment/1&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Sample table
&lt;/h4&gt;

&lt;p&gt;Assuming we want to query a table containing a list of scheduled jobs with known statuses. e.g &lt;br&gt;
&lt;code&gt;RUNNING&lt;/code&gt;, &lt;code&gt;PENDING&lt;/code&gt;, &lt;code&gt;COMPLETED&lt;/code&gt;, &lt;code&gt;FAILED&lt;/code&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;task_ref&lt;/th&gt;
&lt;th&gt;status&lt;/th&gt;
&lt;th&gt;last_exec_timestamp&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2232323&lt;/td&gt;
&lt;td&gt;PENDING&lt;/td&gt;
&lt;td&gt;1605726253&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2232324&lt;/td&gt;
&lt;td&gt;FAILED&lt;/td&gt;
&lt;td&gt;1605726153&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;2132326&lt;/td&gt;
&lt;td&gt;RUNNING&lt;/td&gt;
&lt;td&gt;1605726233&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;2032326&lt;/td&gt;
&lt;td&gt;RUNNING&lt;/td&gt;
&lt;td&gt;1605726233&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;2932326&lt;/td&gt;
&lt;td&gt;FAILED&lt;/td&gt;
&lt;td&gt;1605726233&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;2233326&lt;/td&gt;
&lt;td&gt;COMPLETED&lt;/td&gt;
&lt;td&gt;1605726233&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;2238326&lt;/td&gt;
&lt;td&gt;FAILED&lt;/td&gt;
&lt;td&gt;1605726233&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Our objective is to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fetch all rows&lt;/li&gt;
&lt;li&gt;Order the rows in the following order
&lt;code&gt;RUNNING &amp;gt; PENDING &amp;gt; COMPLETED &amp;gt; FAILED&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Off we go&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt; &lt;span class="c1"&gt;#SomeModule&lt;/span&gt;
 &lt;span class="n"&gt;import&lt;/span&gt; &lt;span class="no"&gt;Ecto&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="no"&gt;Query&lt;/span&gt;

 &lt;span class="vi"&gt;@statuses_order&lt;/span&gt; &lt;span class="s2"&gt;"""
    (case(?)
      when 'RUNNING' then 1
      when 'PENDING' then 2
      when 'COMPLETED' then 3
      else 4
    end)
  """&lt;/span&gt;
 &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;your_function&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;Jobs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;order_by&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="ss"&gt;asc: &lt;/span&gt;&lt;span class="n"&gt;fragment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="vi"&gt;@statuses_order&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;Repo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
 &lt;span class="k"&gt;end&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just like that our jobs will be returned in the order which we have specified in the &lt;code&gt;@statuses_order&lt;/code&gt; module attribute.&lt;/p&gt;

&lt;p&gt;More information about this subject from elixir forum can be found &lt;a href="https://elixirforum.com/t/error-interpolating-a-variable-as-the-first-argument-of-an-ecto-fragment/6711/2"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Thats it! :) &lt;/p&gt;

</description>
      <category>ecto</category>
      <category>orderby</category>
      <category>fragment</category>
      <category>elixir</category>
    </item>
    <item>
      <title>Getting rid of specific git commits</title>
      <dc:creator>Kolawole O. Gabriel</dc:creator>
      <pubDate>Sun, 04 Oct 2020 09:09:29 +0000</pubDate>
      <link>https://dev.to/segaz2002/getting-rid-of-specific-git-commits-2ob3</link>
      <guid>https://dev.to/segaz2002/getting-rid-of-specific-git-commits-2ob3</guid>
      <description>&lt;p&gt;There are two possible reasons (that I can think of) you might want to revert a commit or specific commits:&lt;/p&gt;

&lt;p&gt;Scenario A: When working on a feature branch and you later realize a specific change is no longer relevant and you want to remove such commit/change.&lt;/p&gt;

&lt;p&gt;Scenario B: When you pushed a working branch to remote, just about to a create a pull request, you compared your branch and realize you have commits that are not related to your work, probably due to the local repository being out of sync.&lt;/p&gt;

&lt;p&gt;How to fix ?&lt;/p&gt;

&lt;p&gt;In the case of Scenario A; we can execute the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;git&lt;/span&gt; &lt;span class="n"&gt;revert&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;commit&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nb"&gt;hash&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;where &lt;code&gt;&amp;lt;commit-hash&amp;gt;&lt;/code&gt; is the targeted commit hash, done.&lt;/p&gt;

&lt;p&gt;Hint, we can list all commits together with their hash by executing&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;git&lt;/span&gt; &lt;span class="n"&gt;log&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;oneline&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Scenario B: where we need to remove multiple commits/changes from our branch, we can rebase interactively with a target base branch by executing&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;git&lt;/span&gt; &lt;span class="n"&gt;rebase&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;branch&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will result into an opened editor listing all the commits in the current working branch. &lt;/p&gt;

&lt;p&gt;Hint, rebase entails taking the current changes and stacking it on top of another branch, hence we can selectively pick the commits desired and reject others.&lt;/p&gt;

&lt;p&gt;With the editor opened, we can go ahead and remove specific commits as desired by simply deleting their records in the opened editor. There are instructions as to applicable commands in the editor. &lt;/p&gt;

&lt;p&gt;The opened editor with commands, should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;On completing the exercise and closing the editor, the rebase will work its way automatically.&lt;/p&gt;

&lt;p&gt;That is it. Fun coding!&lt;/p&gt;

</description>
      <category>git</category>
      <category>commit</category>
      <category>rebase</category>
    </item>
  </channel>
</rss>
