<?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: 66np</title>
    <description>The latest articles on DEV Community by 66np (@66np).</description>
    <link>https://dev.to/66np</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%2F651923%2F5a6575fe-717d-4954-a9d3-100a2cd38723.jpeg</url>
      <title>DEV Community: 66np</title>
      <link>https://dev.to/66np</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/66np"/>
    <language>en</language>
    <item>
      <title>Arrays in SQL? Yay or Nay?</title>
      <dc:creator>66np</dc:creator>
      <pubDate>Tue, 06 Dec 2022 23:21:28 +0000</pubDate>
      <link>https://dev.to/66np/arrays-in-sql-yay-or-nay-1ink</link>
      <guid>https://dev.to/66np/arrays-in-sql-yay-or-nay-1ink</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Photo by Naim Benjelloun&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer:&lt;/strong&gt; Coming from a dev perspective, &lt;em&gt;NOT&lt;/em&gt; DBA.&lt;/p&gt;

&lt;p&gt;I'm visiting this topic for an nth time, and decided to illustrate use cases (with and without), and come up with a pros/cons list. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; In a database for a social networking platform, suppose I need to organize the data for a user's friends. &lt;/p&gt;

&lt;p&gt;This can be done in 1 of 2 ways:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; Within a singular table ('user profile')&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;| id | name | friends_id |
--------------------------
| 1  | jess | {3, 4}     |
| 2  | mike |            |
| 3  | raj  | {1}        |
| 4  | sam  | {1}        |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; Split into two tables ('user_profile', 'user_friends')&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;| id | name |
-------------
| 1  | jess |
| 2  | mike |
| 3  | raj  |
| 4  | sam  |

| id | user_id | friend_id |
----------------------------
| 1  | 1       | 3         |
| 2  | 1       | 4         |
| 3  | 3       | 1         |
| 4  | 4       | 1         |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;PROS:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Spatial locality allows us to minimize the number of query calls to the DB which can be a bit of performance booster (i.e. INSERT INTO user_profile (name, friends_id) VALUES ('jess', ARRAY[3, 4]); &lt;strong&gt;VS.&lt;/strong&gt; INSERT INTO user_profile (name) VALUES ('jess'); INSERT INTO user_friends (user_id, friend_id) VALUES (1, 3); INSERT INTO user_friends (user_id, friend_id) VALUES (1, 4);)&lt;/li&gt;
&lt;li&gt;Reduces data redundancy (i.e. the multiple records for user id 1 under table 'user_friends')&lt;/li&gt;
&lt;li&gt;Can be especially useful when processing large amounts of data (i.e. PostGIS point data, ML datasets)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;CONS:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Breaks database normalization rules like 1NF (First Normal Form) being a multi-valued attribute which introduces CRUD anomalies (i.e. UPDATE user_profile SET friends_id = array_append(friends_id, 2) WHERE id = 1; &lt;strong&gt;VS.&lt;/strong&gt; INSERT user_friends (user_id, friend_id) VALUES (1, 2);)&lt;/li&gt;
&lt;li&gt;Breaks database normalization rules like introducing null values where the data &lt;em&gt;can&lt;/em&gt; be normalized (i.e. User with id 2 in the first example has 0 friends, consequently nulling the friends_id column. This could've been prevented by introducing the second table 'user_friends'.)&lt;/li&gt;
&lt;li&gt;Does not allow for modularity or new information per entry within the array (What if I wanted to date when each friendship was initiated through the app? Order the data based on this new attribute?)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;| id | name |
-------------
| 1  | jess |
| 2  | mike |
| 3  | raj  |
| 4  | sam  |

| id | user_id | friend_id | created_at |
-----------------------------------------
| 1  | 1       | 3         | 2020-09-02 |
| 2  | 1       | 4         | 2020-03-20 | 
| 3  | 3       | 1         | 2020-09-02 |
| 4  | 4       | 1         | 2020-03-20 |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Not a lot of SQL Engines and ORMS are optimized to handle arrays and lists (i.e. from experience, the schema file generated by Diesel ORM for Rust tends to mess up on optional array fields, as well as reported issues on migrations to MySQL/SQLite)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What are your thoughts?&lt;/p&gt;

</description>
      <category>sql</category>
      <category>postgres</category>
      <category>database</category>
      <category>design</category>
    </item>
    <item>
      <title>How To Publish A Static React/Node.js App Using cPanel (the easy way)</title>
      <dc:creator>66np</dc:creator>
      <pubDate>Tue, 22 Jun 2021 01:09:31 +0000</pubDate>
      <link>https://dev.to/66np/how-to-publish-a-static-react-node-js-app-using-cpanel-the-easy-way-199o</link>
      <guid>https://dev.to/66np/how-to-publish-a-static-react-node-js-app-using-cpanel-the-easy-way-199o</guid>
      <description>&lt;p&gt;I've been stuck on this problem recently and finally figured it out a week in. Except the solution surely took less than ten minutes so I decided to share the wisdom.&lt;/p&gt;

&lt;p&gt;Pro-tip: &lt;b&gt;Forget the Setup Node.js App feature&lt;/b&gt; on your cPanel. Instead, you want to focus your attention on the &lt;em&gt;build&lt;/em&gt; folder. When you run &lt;em&gt;yarn run build&lt;/em&gt;, you are effectively generating static files to be used in production. &lt;/p&gt;

&lt;p&gt;Once I made all my changes locally, I used the following steps to deploy my site:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;On your local machine&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;1)&lt;/b&gt; In your &lt;em&gt;package.json&lt;/em&gt;, add the line &lt;em&gt;"homepage":"&amp;lt;yourdomain&amp;gt;"&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;2)&lt;/b&gt; In your VSCode terminal, run &lt;em&gt;yarn run build&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;     You should see something like this:&lt;/p&gt;

&lt;p&gt;     &lt;em&gt;The project was built assuming it is hosted at &amp;lt;yourdomain&amp;gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you're seeing '/' or anything else in place of your domain, run &lt;em&gt;export PUBLIC_URL=&amp;lt;yourdomain&amp;gt;&lt;/em&gt; first, then run &lt;em&gt;yarn run build&lt;/em&gt; again. This time, you should see your domain.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;3)&lt;/b&gt; Go into the directory &lt;em&gt;/&amp;lt;yourproject&amp;gt;/build/&lt;/em&gt;, highlight all the files and folders, right-click and navigate to &lt;em&gt;Send to &amp;gt; Compressed (zipped) folder&lt;/em&gt; to generate a zipped folder.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;On your cPanel&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;4)&lt;/b&gt; Go into the directory &lt;em&gt;/home/&amp;lt;yourusername&amp;gt;/&amp;lt;yourdomain&amp;gt;/&lt;/em&gt; and &lt;em&gt;Upload&lt;/em&gt; the zipped folder. Then, extract its contents like this:&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%2Fuploads%2Farticles%2Fub7m1p5m4dspg4huyjso.png" 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%2Fuploads%2Farticles%2Fub7m1p5m4dspg4huyjso.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Remember to delete the .zip folder, and voila! You're done!&lt;/p&gt;

&lt;p&gt;A few notes to keep in mind here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For some, it may take a while to load under your actual domain or in the same browser with all that cPanel activity. I used Incognito mode and other devices to check visit my domain and see the updates.&lt;/li&gt;
&lt;li&gt;I have not tried this with a full stack application (keyword: static) as of yet. Though I will be confronting it in the near future so stay tuned!&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>node</category>
      <category>react</category>
      <category>javascript</category>
      <category>html</category>
    </item>
  </channel>
</rss>
