<?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: Michael Fatemi</title>
    <description>The latest articles on DEV Community by Michael Fatemi (@myfatemi04).</description>
    <link>https://dev.to/myfatemi04</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%2F663201%2F7f7671e6-434e-4c19-a986-a355aa0db0e7.jpeg</url>
      <title>DEV Community: Michael Fatemi</title>
      <link>https://dev.to/myfatemi04</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/myfatemi04"/>
    <language>en</language>
    <item>
      <title>Turn your Create React App into a Progressive Web App in 100 seconds</title>
      <dc:creator>Michael Fatemi</dc:creator>
      <pubDate>Sat, 10 Jul 2021 00:25:21 +0000</pubDate>
      <link>https://dev.to/myfatemi04/turn-your-create-react-app-into-a-progressive-web-app-in-100-seconds-3c11</link>
      <guid>https://dev.to/myfatemi04/turn-your-create-react-app-into-a-progressive-web-app-in-100-seconds-3c11</guid>
      <description>&lt;p&gt;&lt;a href="https://web.dev/progressive-web-apps/"&gt;Progressive Web Apps&lt;/a&gt; (PWAs) let regular apps become accessible offline. They also have access to more features than regular apps.&lt;/p&gt;

&lt;p&gt;React Apps need two features to become Progressive Web Apps.&lt;br&gt;
First, they need a service worker, which does work in the background of the app. Second, they need a &lt;code&gt;manifest.json&lt;/code&gt; file in the public folder, which includes the name of the app, the home page, and icons.&lt;/p&gt;

&lt;p&gt;If you're starting fresh, you can use the Create React App template &lt;code&gt;cra-template-pwa&lt;/code&gt; (or &lt;code&gt;cra-template-pwa-typescript&lt;/code&gt;) to bootstrap this process. If you want to create a React app from the start like this, use the command &lt;code&gt;npx create-react-app app-name --template cra-template-pwa&lt;/code&gt; or &lt;code&gt;npx create-react-app app-name --template cra-template-pwa-typescript&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But, if you're like me, you didn't think to add this template in the beginning, and are wondering how to add it to an existing app.&lt;/p&gt;
&lt;h2&gt;
  
  
  1. &lt;code&gt;manifest.json&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;manifest.json&lt;/code&gt; goes in the &lt;code&gt;public&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;Most parts are self-explanatory. You can generate this file with websites like &lt;a href="https://www.simicart.com/manifest-generator.html/"&gt;Simicart's&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here's an example. Note that this requires &lt;code&gt;favicon.ico&lt;/code&gt;, &lt;code&gt;logo192.png&lt;/code&gt;, and &lt;code&gt;logo512.png&lt;/code&gt; to be available in the &lt;code&gt;public&lt;/code&gt; folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"short_name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"App"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"My App"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"icons"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"src"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"favicon.ico"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"sizes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"64x64 32x32 24x24 16x16"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"image/x-icon"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"src"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"logo192.png"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"image/png"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"sizes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"192x192"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"src"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"logo512.png"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"image/png"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"sizes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"512x512"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"start_url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"display"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"standalone"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"theme_color"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"#000000"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"background_color"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"#ffffff"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;


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

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. &lt;code&gt;service-worker.js&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;For a baseline, go to the &lt;a href="https://github.com/cra-template/pwa/tree/master/packages/cra-template-pwa-typescript/template/src"&gt;cra-template-pwa github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Copy &lt;code&gt;service-worker.ts&lt;/code&gt; and &lt;code&gt;serviceWorkerRegistration.ts&lt;/code&gt; into the &lt;code&gt;src&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;Then, at the top of your &lt;code&gt;index.tsx&lt;/code&gt; (or any entrypoint), import the service worker registration like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;serviceWorkerRegistration&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./serviceWorkerRegistration&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;At the bottom of your &lt;code&gt;index.tsx&lt;/code&gt;, add the following code to opt into an "offline-first" app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;
&lt;span class="nx"&gt;serviceWorkerRegistration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;register&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://create-react-app.dev/docs/making-a-progressive-web-app/"&gt;Learn more about PWAs&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Spamming Scammers</title>
      <dc:creator>Michael Fatemi</dc:creator>
      <pubDate>Wed, 07 Jul 2021 22:46:19 +0000</pubDate>
      <link>https://dev.to/myfatemi04/phishers-4bna</link>
      <guid>https://dev.to/myfatemi04/phishers-4bna</guid>
      <description>&lt;p&gt;Have you ever received a text from a friend that was unfortunately hacked on Facebook?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Phishing&lt;/em&gt; is where an untrustworthy website pretends to be someone they are not, in order to collect visitors' login information.&lt;/p&gt;

&lt;p&gt;I really dislike phishers, so I decided maybe I would get revenge. Five of my friends sent me a "video" just today.&lt;/p&gt;

&lt;p&gt;I clicked on the "video", and it took me to a fake Facebook login page. I looked into the page, and saw this HTML:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;
&lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="na"&gt;method=&lt;/span&gt;&lt;span class="s"&gt;"post"&lt;/span&gt; &lt;span class="na"&gt;action=&lt;/span&gt;&lt;span class="s"&gt;"https://mortalkomb07.xyz//save.php?api=1&amp;amp;amp;lan=facebooknew&amp;amp;amp;ht=1&amp;amp;amp;counter0=combo1407"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"mobile-login-form _5spm"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"login_form"&lt;/span&gt; &lt;span class="na"&gt;data-sigil=&lt;/span&gt;&lt;span class="s"&gt;"m_login_form"&lt;/span&gt; &lt;span class="na"&gt;data-autoid=&lt;/span&gt;&lt;span class="s"&gt;"autoid_2"&lt;/span&gt; &lt;span class="na"&gt;data-countryinsert=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    ...
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"pass"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"password"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"username"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    ...
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;I decided I would replicate fake requests, and hopefully overwhelm them with false data, at least delaying them from attacking other, real, accounts.&lt;/p&gt;

&lt;p&gt;I loaded some fake usernames, passwords, and country data (that was also included in the form.)&lt;/p&gt;

&lt;h1&gt;
  
  
  Setup
&lt;/h1&gt;

&lt;p&gt;First, we import some libraries.&lt;/p&gt;

&lt;p&gt;Then, we load some fake data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import requests
import random
import string
import json

url = 'https://mortalkomb07.xyz//save.php?api=1&amp;amp;lan=facebooknew&amp;amp;ht=1&amp;amp;counter0=combo1407'
chrome_user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'

firstnames = json.load(open("firstnames.json"))
surnames = json.load(open("surnames.json"))
countries_and_states = json.load(open("countries_and_states.json"))['countries']

email_domains = ['yahoo.com', 'gmail.com', 'hotmail.com', 'verizon.net']

letters = string.ascii_lowercase
numbers = string.digits

password_chars = string.ascii_letters + string.digits

coinflip = lambda: bool(random.randint(0, 1))

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

&lt;/div&gt;



&lt;h1&gt;
  
  
  The Loop
&lt;/h1&gt;

&lt;p&gt;Now, we loop 10,000,000 times.&lt;/p&gt;

&lt;p&gt;Each time, an email gets generated based on random names and surnames.&lt;/p&gt;

&lt;p&gt;A country and state are chosen randomly.&lt;/p&gt;

&lt;p&gt;A password is generated as a string of random characters.&lt;/p&gt;

&lt;p&gt;Finally, a request is sent to their server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
for x in range(10000000):
    email = ''
    # first name
    email += random.choice(firstnames).lower()

    # add a surname
    if coinflip():
        email += "." if coinflip() else ""
        email += random.choice(surnames).lower()

    if coinflip():
        email += str(random.randint(0, 100))

    email += "@" + random.choice(email_domains)

    password = ''
    for y in range(random.randint(8, 20)):
        password += random.choice(password_chars)

    country_and_states = random.choice(countries_and_states)
    while len(country_and_states['states']) == 0:
        country_and_states = random.choice(countries_and_states)

    country = country_and_states['country']
    state = random.choice(country_and_states['states'])

    # send the request

    requests.post(url, {
        "ua": "",
        "email": email,
        "pass": password,
        "pais": country,
        "Country": country,
        "country": country,
        "state": state
    }, headers={
        "User-Agent": chrome_user_agent
    }, allow_redirects=False)

    print("sent", x + 1, "fake emails and passwords")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Later, the output is:&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%2F1h5ejbvwjho09mwn1bac.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%2F1h5ejbvwjho09mwn1bac.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This was a fun exercise, and hopefully the scammers get held back.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>cybersecurity</category>
    </item>
    <item>
      <title>Add Caching to Any Python Function in One Line</title>
      <dc:creator>Michael Fatemi</dc:creator>
      <pubDate>Wed, 07 Jul 2021 22:24:13 +0000</pubDate>
      <link>https://dev.to/myfatemi04/cache-any-function-in-one-line-3ig7</link>
      <guid>https://dev.to/myfatemi04/cache-any-function-in-one-line-3ig7</guid>
      <description>&lt;p&gt;Did you know that Python actually has built-in decorators that can add a cache to any function? &lt;em&gt;&lt;a href="https://realpython.com/primer-on-python-decorators/"&gt;(what are decorators?)&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let's say I have a function that requires a bit a computing power. For this example, I'll use a fibonacci sequence calculator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def fib(x):
    if x &amp;lt;= 1:
        return 1
    return fib(x - 1) + fib(x)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using Python's builtin &lt;code&gt;functools&lt;/code&gt; library, I can add a "cache" in one line. A cache will remember the outputs of a compute-heavy function so the values don't need to be calculated multiple times.&lt;/p&gt;

&lt;p&gt;If a set of inputs have already been calculated, the &lt;code&gt;cache&lt;/code&gt; decorator will return the calculated result without running the &lt;code&gt;fib()&lt;/code&gt; function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
from functools import cache

@cache
def fib(x):
    if x &amp;lt;= 1:
        return 1
    return fib(x - 1) + fib(x)

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

&lt;/div&gt;



&lt;p&gt;However, &lt;code&gt;@cache&lt;/code&gt; will store an unlimited number of inputs and outputs. If we want to limit it to only, say, 1,000 cached values, we can use a "least-recently-used" or "LRU" cache.&lt;/p&gt;

&lt;p&gt;With this type of cache, Python will only cache the 1,000 most recently used values. If a new value is calculated, the 1,001st value will be "evicted" from the cache (removed from memory).&lt;/p&gt;

&lt;p&gt;Example 1 (note that we do not need parentheses):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
from functools import lru_cache

@lru_cache
def fib(x):
    if x &amp;lt;= 1:
        return 1
    return fib(x - 1) + fib(x)

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

&lt;/div&gt;



&lt;p&gt;Example 2 (maximum size of 1000 elements):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
from functools import lru_cache

@lru_cache(max_size=1000)
def fib(x):
    if x &amp;lt;= 1:
        return 1
    return fib(x - 1) + fib(x)

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

&lt;/div&gt;



</description>
      <category>python</category>
    </item>
    <item>
      <title>A Next-Generation ORM: Prisma</title>
      <dc:creator>Michael Fatemi</dc:creator>
      <pubDate>Wed, 07 Jul 2021 19:36:20 +0000</pubDate>
      <link>https://dev.to/myfatemi04/use-prisma-s-powerful-javascript-client-generator-to-write-a-blog-app-18gj</link>
      <guid>https://dev.to/myfatemi04/use-prisma-s-powerful-javascript-client-generator-to-write-a-blog-app-18gj</guid>
      <description>&lt;h1&gt;
  
  
  What is Prisma?
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://prisma.io" rel="noopener noreferrer"&gt;Prisma&lt;/a&gt; is one of the best database libraries I've ever used. In a nutshell, you write a schema, and Prisma can apply the changes to your database, and generate a Typescript client library custom-tailored to your databases.&lt;/p&gt;

&lt;h1&gt;
  
  
  What are we making?
&lt;/h1&gt;

&lt;p&gt;For this example, I'll use a simple blog app. It has a &lt;code&gt;User&lt;/code&gt; table, and an &lt;code&gt;Article&lt;/code&gt; table. &lt;code&gt;Users&lt;/code&gt; can have many &lt;code&gt;Articles&lt;/code&gt;, and each &lt;code&gt;Article&lt;/code&gt; only has one author.&lt;/p&gt;

&lt;p&gt;To install Prisma, run &lt;code&gt;yarn add prisma -D&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Schema
&lt;/h1&gt;

&lt;p&gt;In a folder called &lt;code&gt;prisma&lt;/code&gt; at the root of your project, you can create a file called &lt;code&gt;schema.prisma&lt;/code&gt;. This is where the descriptions (or "schemas") of your tables will be stored.&lt;/p&gt;

&lt;p&gt;Prisma uses this file to apply changes to the database, and generate a custom client for us.&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%2Fcx7105ct7z5bpx80m64t.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%2Fcx7105ct7z5bpx80m64t.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;You can ignore the &lt;code&gt;migrations&lt;/code&gt; folder for now.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Datasource
&lt;/h2&gt;

&lt;p&gt;To specify where your database will be, you start a &lt;code&gt;datasource&lt;/code&gt; block.&lt;/p&gt;

&lt;p&gt;In the following snippet, I use an SQLite database (a lightweight database good for quickly testing apps, which stores the database in a single file). For the "url" of the SQLite database, I specify &lt;code&gt;database.db&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Sqlite
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;datasource db {
  provider = "sqlite"
  url      = "file:./database.db"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Postgres
&lt;/h4&gt;

&lt;p&gt;Alternatively, you can use Postgres or MySQL as your database.&lt;/p&gt;

&lt;p&gt;Because exposing Postgres's database url can compromise its security, we can store it as an environment variable to avoid putting it directly in the code. Prisma supports &lt;a href="https://www.npmjs.com/package/dotenv" rel="noopener noreferrer"&gt;.env files&lt;/a&gt;, which loads environment variables from a file called &lt;code&gt;.env&lt;/code&gt;, allowing for a portable development environment.&lt;/p&gt;

&lt;p&gt;This is what the snippet for a Postgres database would look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;datasource db {
  provider = "postgres"
  // Access the DATABASE_URL variable.
  url      = env("DATABASE_URL")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Generator
&lt;/h2&gt;

&lt;p&gt;Remember how I said Prisma can generate client-side code for you?&lt;/p&gt;

&lt;p&gt;This snippet specifies exactly what behavior the Prisma generator will follow. This has worked perfectly for me.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;generator client {
  provider = "prisma-client-js"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How the turntables...
&lt;/h2&gt;

&lt;p&gt;Now, it's time for us to add our tables. For this example, I'll use a simple blog app. It has a &lt;code&gt;User&lt;/code&gt; table, and an &lt;code&gt;Article&lt;/code&gt; table. &lt;code&gt;Users&lt;/code&gt; can have many &lt;code&gt;Articles&lt;/code&gt;, and each &lt;code&gt;Article&lt;/code&gt; only has one author.&lt;/p&gt;

&lt;p&gt;We'll start with some basic details about each user, so we can get familiar with the syntax of Prisma.&lt;/p&gt;

&lt;p&gt;To start the schema for a table, we declare a &lt;code&gt;model&lt;/code&gt; block:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;model User {
  // Our fields (columns) go here...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll add an ID column, which will be an integer, an email column, which will be a string, and a name column, which will also be a string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;model User {
  id          Int
  email       String
  name        String
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because we want our ID to be indexable, we'll add the &lt;code&gt;@id&lt;/code&gt; decorator. This is a simple app, so we'll make its value automatically increment for each user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;model User {
  id          Int    @id @default(autoincrement())
  email       String
  name        String
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because we want each user's email to be unique, we'll add the &lt;code&gt;@unique&lt;/code&gt; decorator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;model User {
  id     Int    @id @default(autoincrement())
  email  String @unique
  name   String
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, time for our &lt;code&gt;Article&lt;/code&gt; model. We'll make an ID field in the same way as before, and also add a title field, a content field, and a field to specify when the article was published. Finally, we'll add an &lt;code&gt;authorId&lt;/code&gt; field for the ID of the user who authored the article.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;model Article {
  id          Int @id @default(autoincrement())
  authorId    Int
  title       String
  content     String
  publishedAt DateTime
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;a href="https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference/#model-fields" rel="noopener noreferrer"&gt;Here's a complete list of data types supported by Prisma.&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Our article has a field called &lt;code&gt;authorId&lt;/code&gt;, but wouldn't it be nice if there were a field called &lt;code&gt;author&lt;/code&gt; which &lt;em&gt;had the type User&lt;/em&gt;? With Prisma, we can actually make this happen!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;model Article {
  id          Int @id @default(autoincrement())
  authorId    Int
  author      User
  title       String
  content     String
  publishedAt DateTime
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We aren't done yet, but there isn't much left to do.&lt;/p&gt;

&lt;p&gt;We just need to use the &lt;code&gt;@relation&lt;/code&gt; decorator.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;@relation&lt;/code&gt; decorator uses this syntax:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@relation(fields: [authorId], references: [id])&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Let's break this down.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;fields&lt;/code&gt; attribute specifies which field of the &lt;code&gt;Article&lt;/code&gt; references the id of the author. The &lt;code&gt;references&lt;/code&gt; attribute specifies which field of the User table the &lt;code&gt;fields&lt;/code&gt; attribute points to.&lt;/p&gt;

&lt;p&gt;That might have been wordy, so I'll just show you what it would look like in the schema:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;model Article {
  id          Int @id @default(autoincrement())
  authorId    Int
  author      User @relation(fields: [authorId], references: [id])
  title       String
  content     String
  publishedAt DateTime
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Perfect.&lt;/p&gt;

&lt;p&gt;There is one final step. Because each Article has an author, logically, each User will have several Articles. We actually cannot avoid adding that to the schema.&lt;/p&gt;

&lt;p&gt;To reflect this in our schema, we just add an &lt;code&gt;articles&lt;/code&gt; field to the &lt;code&gt;User&lt;/code&gt; model. We'll make it have the type &lt;code&gt;Article[]&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;model User {
  id       Int    @id @default(autoincrement())
  email    String @unique
  name     String
  articles Article[]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Phew! We're done with &lt;code&gt;schema.prisma&lt;/code&gt; for this article.&lt;/p&gt;

&lt;p&gt;Here's what the final &lt;code&gt;schema.prisma&lt;/code&gt; looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;datasource db {
  provider = "sqlite"
  url      = "file:./database.db"
}

generator client {
  provider = "prisma-client-js"
}

model User {
  id       Int    @id @default(autoincrement())
  email    String @unique
  name     String
  articles Article[]
}

model Article {
  id          Int @id @default(autoincrement())
  authorId    Int
  author      User @relation(fields: [authorId], references: [id])
  title       String
  content     String
  publishedAt DateTime
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Applying changes to the database
&lt;/h1&gt;

&lt;p&gt;Now, we want Prisma apply these changes to our database. This will automatically generate the custom client SDK. The process of applying changes to a database is called "migration".&lt;br&gt;
The command to apply these changes is:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;yarn prisma migrate dev&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;dev&lt;/code&gt; at the end specifies that we're working in the development environment.&lt;/p&gt;

&lt;p&gt;We will need to specify a name for the migration, so we'll just write &lt;code&gt;initial migration&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If everything goes well, the output will look something 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%2Fbmjuo1u63r28itjhwpdn.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%2Fbmjuo1u63r28itjhwpdn.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we're ready to start manipulating the database.&lt;/p&gt;
&lt;h1&gt;
  
  
  Using the Client
&lt;/h1&gt;

&lt;p&gt;Now that we've generated the client code, we can start using Prisma.&lt;/p&gt;

&lt;p&gt;If the generated client code doesn't show up, try running the command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;yarn prisma generate&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We'll write our code in a file called &lt;code&gt;index.js&lt;/code&gt;. Prisma also has built-in Typescript support.&lt;/p&gt;

&lt;p&gt;To create an instance of the Prisma client, we import the &lt;code&gt;PrismaClient&lt;/code&gt; class from &lt;code&gt;@prisma/client&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;PrismaClient&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@prisma/client&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;prisma&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PrismaClient&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because Prisma's client is custom-generated for our database, it has built-in Intellisense.&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%2Flw5xq4si4tqletb2um1l.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%2Flw5xq4si4tqletb2um1l.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's walk through some examples of how we would use the Prisma client.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a User
&lt;/h2&gt;

&lt;p&gt;First, we'll create a user.&lt;/p&gt;

&lt;p&gt;This is simple enough: creating any table in Prisma can be done with &lt;code&gt;prisma.[table name].create()&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="nx"&gt;prisma&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Michael Fatemi&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;REDACTED&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;If we want to retrieve the ID that was autogenerated for the user:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="nx"&gt;prisma&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;select&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Michael Fatemi&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;REDACTED&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Creating an Article
&lt;/h2&gt;

&lt;p&gt;Because each Article references a User, Prisma doesn't allow us to specify the &lt;code&gt;authorId&lt;/code&gt; manually, as this might violate the foreign key constraint created by SQL. So, we must specify that we are "connecting" a User to the article, through the syntax shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createArticle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;authorId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;prisma&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;article&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;authorId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;publishedAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Listing Articles written by a user
&lt;/h2&gt;

&lt;p&gt;We can fetch data about a user like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getArticles&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;prisma&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findFirst&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;select&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;articles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;userId&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Listing users who wrote an article before a certain date
&lt;/h2&gt;

&lt;p&gt;This might not be useful in the real world, but can demonstrate how powerful Prisma can be.&lt;/p&gt;

&lt;p&gt;This example also shows how you can create more complex queries than checking for equality of a value. You can also check if a value is less than (&lt;code&gt;lt&lt;/code&gt;), greater than (&lt;code&gt;gt&lt;/code&gt;), equal to (&lt;code&gt;eq&lt;/code&gt;), or others by passing an object to the &lt;code&gt;where&lt;/code&gt; clause instead of a value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getUsersWhoWroteAnArticleBefore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;prisma&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findMany&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;select&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;articles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;some&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;publishedAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;lt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;date&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Thanks for reading this article, I hope it was helpful for learning how to use Prisma to auto-generate code!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>sql</category>
      <category>node</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Add interactive maps to your website without an API</title>
      <dc:creator>Michael Fatemi</dc:creator>
      <pubDate>Wed, 07 Jul 2021 18:38:53 +0000</pubDate>
      <link>https://dev.to/myfatemi04/add-interactive-maps-to-your-website-without-an-api-20f8</link>
      <guid>https://dev.to/myfatemi04/add-interactive-maps-to-your-website-without-an-api-20f8</guid>
      <description>&lt;p&gt;You may have wanted to add maps to your website for data analysis, at some point. I definitely did, when I developed a Coronavirus tracker last year. Trying to add maps, especially interactive ones, was difficult! It required loading the geometry of the map manually, and if you wanted to make it possible to hover over a state (for example, in the US), it was a nightmare.&lt;/p&gt;

&lt;p&gt;Use a new type of map: &lt;em&gt;svg maps&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;If they're in the right use case, SVG maps can be much more effective for representing data specific to several countries at once, like Coronavirus case counts, and much easier to integrate with.&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%2Fnejhrq97ox95zwp7k631.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%2Fnejhrq97ox95zwp7k631.png" alt="World Map of Coronavirus Case Counts"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Some Benefits
&lt;/h3&gt;

&lt;p&gt;You can make these maps interactive! Because SVGs are integrated with the DOM, you can add event listeners to individual states with one line of code: &lt;code&gt;document.getElementById('united-states')&lt;/code&gt;, or &lt;code&gt;document.getElementById('south-korea')&lt;/code&gt;. This also allows you to style the regions of the map, and shade them based on the data you want to visualize.&lt;/p&gt;

&lt;p&gt;These maps are used live on &lt;a href="//ncov2019.live"&gt;https://ncov2019.live/map&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;They don't require any API keys or custom scripting.&lt;/p&gt;

&lt;p&gt;They are minimalistic.&lt;/p&gt;

&lt;p&gt;These maps are available from several places, and I found mine on &lt;a href="//simplemaps.com"&gt;simplemaps.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can combine this with the &lt;a href="https://dev.tosvg-pan-zoom"&gt;https://www.npmjs.com/package/svg-pan-zoom&lt;/a&gt; library to let users scroll through the map.&lt;/p&gt;

</description>
      <category>webdev</category>
    </item>
  </channel>
</rss>
