<?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: José Freitas</title>
    <description>The latest articles on DEV Community by José Freitas (@joji).</description>
    <link>https://dev.to/joji</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%2F2549511%2F71c72d4f-9ff4-48b6-aeb3-c1445a1b29fd.png</url>
      <title>DEV Community: José Freitas</title>
      <link>https://dev.to/joji</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/joji"/>
    <language>en</language>
    <item>
      <title>GQL— Write SQL queries in your Git repo!</title>
      <dc:creator>José Freitas</dc:creator>
      <pubDate>Tue, 10 Dec 2024 02:06:31 +0000</pubDate>
      <link>https://dev.to/joji/gql-write-sql-queries-in-your-git-repo-4g6p</link>
      <guid>https://dev.to/joji/gql-write-sql-queries-in-your-git-repo-4g6p</guid>
      <description>&lt;p&gt;&lt;strong&gt;TLDR — saving you time!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The article introduces an open-source tool that allows you to execute SQL queries on a Git repository. In other words, you can query commit messages, authors, branches, etc., formatted in a table, as if your repository were a massive database. ;)&lt;/p&gt;




&lt;p&gt;There are several ways to obtain specific information about a repository — not all of them are easy, quick, or elegant to execute or visualize. Possibly, the most suitable approach so far would be to use the graphical interface of the platform where your project is hosted (GitHub, GitLab, and the like) and leverage the tools they provide. &lt;/p&gt;

&lt;p&gt;All of them cover the basics — but sometimes you need something more specific, and that’s what we’ll explore here. Meet Git Query Language, an SQL-like language for performing queries on .git files!&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing the tool
&lt;/h2&gt;

&lt;p&gt;Use the command below to install it on Windows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;winget install gitql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or if you're using Mac (or homebrew on Linux):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew install gql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Let's start with an example repository
&lt;/h2&gt;

&lt;p&gt;...and what better repository to use than the tool's own repository? 😄&lt;/p&gt;

&lt;p&gt;Run the command below to clone the repository to your machine through SSH.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone git@github.com:AmrDeveloper/GQL.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alright, we have our query language, and we have our "database." Let's test it!&lt;/p&gt;

&lt;p&gt;Open the terminal and navigate to the tool's project directory. Type the command below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gitql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will open an interactive session in the terminal, as shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8w0kcvri1juq6f2iws9e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8w0kcvri1juq6f2iws9e.png" width="437" height="126"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's start small by querying the commit titles. We'll limit it to 5 records since there are many commits.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT title FROM commits LIMIT 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, the table we want to query is "commits," but at the end of the article, you'll find a list of all the tables available in the tool.&lt;br&gt;
We’ll have:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjh4r56hchwt6wco57web.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjh4r56hchwt6wco57web.png" width="683" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pretty cool, isn’t it? But so far, it doesn’t tell us much. Who made the commits? Who’s responsible?! Let’s find out!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT title, name AS author FROM commits LIMIT 5 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0q0imw40d8ln1sw05a8y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0q0imw40d8ln1sw05a8y.png" width="800" height="348"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Phew, that’s better now. We know who made each commit. Now we can better visualize who worked on each feature — or bug — just the way we’re used to. And hey, when was everything done? We need to know that too!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT title, name AS author, datetime AS commit_date FROM commits LIMIT 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjh3nnrqp3o2mcfcby1py.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjh3nnrqp3o2mcfcby1py.png" width="800" height="264"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Perfect. We have the commit title, the author, the date/time... Anyone missing the commit ID?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT commit_id AS id, title, name AS author, datetime AS commit_date FROM commits LIMIT 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnhn8xaob4hwp8h34vqf4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnhn8xaob4hwp8h34vqf4.png" width="800" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There we go. I think that’s enough. Now, how about asking our repository a few more questions?&lt;/p&gt;

&lt;h3&gt;
  
  
  What was the infamous “first commit” of the repository?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT commit_id AS id, title, name AS author, datetime AS commit_date FROM commits LIMIT 1 ORDER BY commit_date ASC
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F53i33hmlu4latrmo1ptb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F53i33hmlu4latrmo1ptb.png" width="800" height="99"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What were the last 5 commits made by this AmrDeveloper person?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT commit_id AS id, title, name AS author, datetime AS commit_date FROM commits LIMIT 5 WHERE LOWER(author) = "amr
developer" ORDER BY commit_date DESC
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fynicb25bpze9wz2bq948.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fynicb25bpze9wz2bq948.png" width="800" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Hmm… Now I only want the features! The last 5 features!
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT commit_id AS id, title, name AS author, datetime AS commit_date FROM commits WHERE title LIKE "feat%" LIMIT 5 ORDER BY commit_date DESC
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fezp77g0uapy84h9vx0yu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fezp77g0uapy84h9vx0yu.png" width="800" height="286"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Especially useful when your project follows Conventional Commits.&lt;/p&gt;

&lt;h3&gt;
  
  
  What are the project's tags?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM tags
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmm2ey06yodlqlzbqkawv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmm2ey06yodlqlzbqkawv.png" width="523" height="688"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And… done! I mean, the tool can do much more — but I think you got a pretty good idea of how it works, right? 😄&lt;br&gt;
You can check out the tables available in the tool &lt;a href="https://github.com/AmrDeveloper/GQL/blob/master/docs/structure/tables.md" rel="noopener noreferrer"&gt;here&lt;/a&gt;. And the full documentation &lt;a href="https://amrdeveloper.github.io/GQL/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;I'm passionate about "collecting" interesting open-source tools. I plan to gradually share them in a list on my &lt;a href="https://www.linkedin.com/in/j-alexandre-freitas/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; while posting articles diving a bit deeper into specific tools. If you have any questions, feedback, or suggestions, feel free to DM me. See ya. ;)&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>programming</category>
      <category>backend</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
