<?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>Forem: Henrique Vicente</title>
    <description>The latest articles on Forem by Henrique Vicente (@henvic).</description>
    <link>https://forem.com/henvic</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%2F186307%2F8f7f5b07-3bcc-4d42-b3ea-8c31c2a49bce.jpeg</url>
      <title>Forem: Henrique Vicente</title>
      <link>https://forem.com/henvic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/henvic"/>
    <language>en</language>
    <item>
      <title>Back to basics: Writing an application using Go and PostgreSQL with pgx</title>
      <dc:creator>Henrique Vicente</dc:creator>
      <pubDate>Wed, 19 Jan 2022 17:04:07 +0000</pubDate>
      <link>https://forem.com/henvic/back-to-basics-writing-an-application-using-go-and-postgresql-with-pgx-4fb3</link>
      <guid>https://forem.com/henvic/back-to-basics-writing-an-application-using-go-and-postgresql-with-pgx-4fb3</guid>
      <description>&lt;p&gt;By reading this tutorial, you'll learn how to use &lt;a href="https://www.postgresql.org/"&gt;PostgreSQL&lt;/a&gt; with the &lt;a href="https://www.golang.org/"&gt;Go&lt;/a&gt; programming language using the &lt;a href="https://github.com/jackc/pgx"&gt;pgx&lt;/a&gt; driver and toolkit in a very productive manner.&lt;br&gt;
Furthermore, with the provided source code, you'll be able to learn how to write efficient and sound unit and integration tests, ready to be run locally or on a Continuous Integration environment, such as GitHub Actions.&lt;br&gt;
Use the Table of Contents to skip to a specific part of this long post.&lt;br&gt;
Don't forget to check out the accompanying repository &lt;a href="https://github.com/henvic/pgxtutorial"&gt;github.com/henvic/pgxtutorial&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Context
&lt;/h2&gt;

&lt;p&gt;PostgreSQL, also known as Postgres, is an extendible feature-rich &lt;a href="https://arctype.com/blog/postgres-ordbms-explainer/"&gt;Object-Relational Database Management System&lt;/a&gt; that is almost 100% &lt;a href="https://en.wikipedia.org/wiki/SQL_compliance"&gt;SQL standards-compliant&lt;/a&gt; and released as open source software under a permissive license.&lt;/p&gt;

&lt;p&gt;Much of the content in this tutorial is based on experience I acquired working for &lt;a href="https://hatchstudio.co/"&gt;HATCH Studio&lt;/a&gt;, even though I'm just shy of ten months there.&lt;br&gt;
My first assignments involved improving some data structures we used internally and led to a team discussion about moving from a document-based database to a more traditional relational database in the face of some challenges.&lt;br&gt;
Next, we held a brainstorming session where we assembled our backend team to analyze our situation and discuss options. I already had some limited experience using PostgreSQL with pgx for a pet project and was pleased to discover that the rest of the team also saw PostgreSQL as an excellent choice for meeting our needs: great developer experience, performance, reliability, and scalability.&lt;/p&gt;

&lt;p&gt;For our search infrastructure, we started using &lt;a href="https://aws.amazon.com/opensearch-service/"&gt;Amazon OpenSearch Service&lt;/a&gt;.&lt;br&gt;
We listen to PostgreSQL database changes via its &lt;a href="https://www.postgresql.org/docs/current/protocol-logical-replication.html"&gt;Logical Streaming Replication Protocol&lt;/a&gt; and ingest data into our &lt;a href="https://opensearch.org/"&gt;OpenSearch&lt;/a&gt;/&lt;a href="https://www.elastic.co/elastic-stack/"&gt;Elasticsearch&lt;/a&gt; search engine through a lightweight connector built in-house.&lt;/p&gt;

&lt;p&gt;It works similar to hooking &lt;a href="https://kafka.apache.org/"&gt;Apache Kafka&lt;/a&gt;, but is easier to use and allows us to move faster without breaking things: running integration tests on a developer machine takes only seconds: much of which is an overkill &lt;code&gt;time.Sleep()&lt;/code&gt; so we never waste time with flaky tests caused by the eventual consistency characteristics of the search engine.&lt;br&gt;
This solution will not be presented now but in a future opportunity.&lt;/p&gt;
&lt;h2&gt;
  
  
  tl;dr
&lt;/h2&gt;

&lt;p&gt;To play with it install &lt;a href="https://go.dev/"&gt;Go&lt;/a&gt; on your system.&lt;br&gt;
You'll need to connect to a &lt;a href="https://www.postgresql.org/"&gt;PostgreSQL&lt;/a&gt; database.&lt;br&gt;
You can check if a connection is working by calling &lt;code&gt;psql&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Clone my repository with any of the following commands:&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;gh repo clone henvic/pgxtutorial
&lt;span class="nv"&gt;$ &lt;/span&gt;git clone https://github.com/henvic/pgxtutorial.git
&lt;span class="nv"&gt;$ &lt;/span&gt;git clone git@github.com:henvic/pgxtutorial.git
&lt;span class="c"&gt;# then:&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;pgxtutorial
&lt;span class="c"&gt;# Create a database&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;psql &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"CREATE DATABASE pgxtutorial;"&lt;/span&gt;
&lt;span class="c"&gt;# Set the environment variable PGDATABASE&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PGDATABASE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;pgxtutorial
&lt;span class="c"&gt;# Run migrations&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;tern migrate &lt;span class="nt"&gt;-m&lt;/span&gt; ./migrations
&lt;span class="c"&gt;# Run all tests passing INTEGRATION_TESTDB explicitly&lt;/span&gt;
&lt;span class="nv"&gt;$ INTEGRATION_TESTDB&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true &lt;/span&gt;go &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; ./...
&lt;span class="c"&gt;# Execute application&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;go run ./cmd/pgxtutorial
2021/11/22 07:21:21 HTTP server listening at localhost:8080
2021/11/22 07:21:21 gRPC server listening at 127.0.0.1:8082
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The blog post continues on my website at &lt;a href="https://henvic.dev/posts/go-postgres/"&gt;henvic.dev/posts/go-postgres&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>go</category>
      <category>postgres</category>
    </item>
    <item>
      <title>Homelab: Intel NUC with the ESXi hypervisor</title>
      <dc:creator>Henrique Vicente</dc:creator>
      <pubDate>Mon, 20 Apr 2020 22:29:10 +0000</pubDate>
      <link>https://forem.com/henvic/homelab-intel-nuc-with-the-esxi-hypervisor-31ni</link>
      <guid>https://forem.com/henvic/homelab-intel-nuc-with-the-esxi-hypervisor-31ni</guid>
      <description>&lt;p&gt;In this blog post, I’m going to talk a little about my experience running multiple operating systems with an Intel NUC I recently bought and the ESXi 7 hypervisor. My main idea was to use this homelab for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Network Area Storage (NAS)&lt;/li&gt;
&lt;li&gt;Kubernetes cluster&lt;/li&gt;
&lt;li&gt;FreeBSD playground&lt;/li&gt;
&lt;li&gt;Managing backup&lt;/li&gt;
&lt;li&gt;Stage and development machine for Go projects&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The blog post continues on my website at &lt;a href="https://henvic.dev/posts/homelab/"&gt;henvic.dev/posts/homelab&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>homelab</category>
      <category>homeserver</category>
      <category>esxi</category>
      <category>bsd</category>
    </item>
  </channel>
</rss>
