<?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: Gloria Lim</title>
    <description>The latest articles on DEV Community by Gloria Lim (@glowiep).</description>
    <link>https://dev.to/glowiep</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%2F1278264%2Fb101c666-d29e-4a71-af3a-10d8600526d8.png</url>
      <title>DEV Community: Gloria Lim</title>
      <link>https://dev.to/glowiep</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/glowiep"/>
    <language>en</language>
    <item>
      <title>Prisma - A Modern ORM</title>
      <dc:creator>Gloria Lim</dc:creator>
      <pubDate>Tue, 19 Mar 2024 04:50:00 +0000</pubDate>
      <link>https://dev.to/glowiep/prisma-a-modern-orm-2knh</link>
      <guid>https://dev.to/glowiep/prisma-a-modern-orm-2knh</guid>
      <description>&lt;h2&gt;
  
  
  What is Prisma❓
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Prisma&lt;/strong&gt; is a modern &lt;a href="https://en.wikipedia.org/wiki/Object%E2%80%93relational_mapping"&gt;ORM&lt;/a&gt; (Object-Relational Mapping) library which integrates seamlessly with TypeScript and JavaScript. &lt;/p&gt;

&lt;p&gt;By ‘modern’, &lt;a href="https://www.prisma.io/docs/orm/overview/prisma-in-your-stack/is-prisma-an-orm"&gt;Prisma documentation&lt;/a&gt; emphasizes that Prisma ORM is fundamentally a new type of ORM, which does not suffer from the problems commonly associated with traditional ORMs such as &lt;a href="https://www.prisma.io/docs/orm/more/comparisons/prisma-and-typeorm#type-safety"&gt;bloated model instances and lack of type-safety&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Prisma was created to abstract away the low-level database interactions and increase developer control and productivity. I will touch on my experience using Prisma in this article.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an ORM? 🧐
&lt;/h2&gt;

&lt;p&gt;If you are not familiar with ORMs, this is a programming technique used to convert data between incompatible type systems, typically between object-oriented programming languages and relational databases. &lt;/p&gt;

&lt;p&gt;This abstraction simplifies database operations and makes it easier to work with databases in object-oriented applications.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjjk6cj5z6j9q6a1int1u.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjjk6cj5z6j9q6a1int1u.jpeg" alt="ORM Image" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Prisma 🪄
&lt;/h2&gt;

&lt;p&gt;Last weekend, I created &lt;a href="https://github.com/glowiep/country-api"&gt;a simple API&lt;/a&gt; project which uses Prisma for database operations, built on top of ExpressJS. &lt;/p&gt;

&lt;p&gt;Here is a conceptual mental model: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Now imagine if you’re building a really cool treehouse with your friends, Prisma is your architecture plan for this project. It is where you decide how many floors your treehouse will have, where the rooms are located and what color the walls will be. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In my simple API project, Express (web framework for Node.js) is the magical framework that helps build and decorate the treehouse. It provides the tools and materials to add features such as fun slides, swings and ladders.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  What I learned 💡
&lt;/h3&gt;

&lt;p&gt;In my experience using Prisma, I noticed that a lot can be done in a few steps. &lt;/p&gt;

&lt;p&gt;Need to create a new table? &lt;/p&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;Define your model in Prisma schema.&lt;/li&gt;
&lt;li&gt;Generate migration.&lt;/li&gt;
&lt;li&gt;Apply migration.&lt;/li&gt;
&lt;li&gt;Populate the new table with seed data.&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;Prisma Studio was an &lt;em&gt;exciting&lt;/em&gt; discovery for me. &lt;a href="https://www.prisma.io/docs/orm/tools/prisma-studio"&gt;Prisma Studio&lt;/a&gt; is a visual editor for the data in your database which runs on your browser. &lt;/p&gt;

&lt;p&gt;You can edit data directly in the model cells, as well as add and delete records. This may appeal to visual thinkers/ learners. You may also sort and filter data in the model (table) in Prisma Studio, which is more efficient than manually running SQL queries to check the status of your database.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffv0n35z6kkb12nv9px0v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffv0n35z6kkb12nv9px0v.png" alt="Prisma Studio" width="800" height="524"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9k61v0fm7m0127fkeli0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9k61v0fm7m0127fkeli0.png" alt="Country API in Prsma Studio" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Benefits 🔱
&lt;/h3&gt;

&lt;p&gt;After my first taste of working with Prisma, I can see the immense benefits it offers. &lt;/p&gt;

&lt;p&gt;Here are some of the greatest benefits (not limited to) of using Prisma:&lt;/p&gt;

&lt;p&gt;💼 &lt;strong&gt;Database Agnostic&lt;/strong&gt;: Prisma supports various databases such as PostgreSQL, MySQL, SQLite and SQL Server. This allows you to switch databases easily without worrying about making major changes in your application code.&lt;/p&gt;

&lt;p&gt;🧰 &lt;strong&gt;Migrations&lt;/strong&gt;: Prisma supports database migrations, this allows you to evolve your database schema over time and keep track of these changes.&lt;/p&gt;

&lt;p&gt;🗂 &lt;strong&gt;Schema-based Relationships&lt;/strong&gt;: Just as an architecture plans serves as a blueprint for building a treehouse, Prisma schema serves as a blueprint for developing and interacting with your database. You can define your data models, and the relationships between your data models in the Prisma Schema. This declarative Prisma schema provides a clear overview of the database current state.&lt;/p&gt;

&lt;p&gt;🤝 &lt;strong&gt;Collaboration&lt;/strong&gt;: If you are working in a team, a great benefit of using Prisma is it is easy for everyone to understand. Compare this to traditional workflows where if a developer is trying to understand the current table structure, they will likely have to spend some time digging into migration files. &lt;/p&gt;

&lt;p&gt;🖋 &lt;strong&gt;Type Safety&lt;/strong&gt;: &lt;a href="https://www.prisma.io/docs/orm/reference/prisma-client-reference"&gt;Prisma Client&lt;/a&gt; abstract away the low-level database interactions and provides an easily understandable API for querying and mutating data.&lt;/p&gt;

&lt;p&gt;In short, Prisma can have a positive impact on productivity as well as developer experience. &lt;/p&gt;

&lt;h2&gt;
  
  
  When should you use Prisma? ✅
&lt;/h2&gt;

&lt;p&gt;Prisma would be a good fit for your project if you are building a server-side application, which interacts with a database. Prisma’s ability to work with both TypeScript and JavaScript does make for a versatile choice for database interactions in Node.js applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to NOT use Prisma? ❎
&lt;/h2&gt;

&lt;p&gt;Like any other tool, Prisma does come with its own &lt;a href="https://www.prisma.io/docs/orm/overview/introduction/should-you-use-prisma"&gt;tradeoffs&lt;/a&gt;. If you need full control over your database queries, you would have to find an alternative. This is because Prisma ORM is an abstraction which takes away some of the control you might have over your database operations if you were to use plain SQL.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;I hope this inspires you to embark on a journey to explore Prisma one day (just as I have), and benefit from Prisma’s role in providing a solid and organized foundation for your database structure (analogous to a scalable and maintainable architectural guide for the construction of a treehouse).&lt;/p&gt;

&lt;h3&gt;
  
  
  Reference:
&lt;/h3&gt;

&lt;p&gt;Prisma Documentation: &lt;a href="https://www.prisma.io/docs"&gt;https://www.prisma.io/docs&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How To Make A Responsive Component in React</title>
      <dc:creator>Gloria Lim</dc:creator>
      <pubDate>Fri, 16 Feb 2024 22:00:56 +0000</pubDate>
      <link>https://dev.to/glowiep/how-to-make-a-responsive-component-in-react-11ln</link>
      <guid>https://dev.to/glowiep/how-to-make-a-responsive-component-in-react-11ln</guid>
      <description>&lt;p&gt;This is how useState and useEffect can be used to make a component responsive based on the &lt;em&gt;window.innerWidth&lt;/em&gt; or the viewport width in React.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Result ✨
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExbTRlMjBseHM5Z2lsMTN6OTN6NHkxcHRmdzBvOXFta3Z6OW96bzM0diZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/RGc61FyNczCLEf9oVy/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExbTRlMjBseHM5Z2lsMTN6OTN6NHkxcHRmdzBvOXFta3Z6OW96bzM0diZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/RGc61FyNczCLEf9oVy/giphy.gif" alt="Final Product" width="480" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, the &lt;a href="https://mui.com/material-ui/react-text-field/"&gt;TextField&lt;/a&gt; component is imported from &lt;a href="https://mui.com/material-ui/"&gt;@mui/material&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code ⌨
&lt;/h2&gt;

&lt;p&gt;Here is my React component file which defines a React component named NewMemo, that renders a text area using the Material-UI TextField component. &lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  What Is Going On❓
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;useState&lt;/strong&gt; hook initializes the windowWidth state with the initial window width minus 150 pixels (so that it does not take up 100% width of the screen).&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;useEffect&lt;/strong&gt; hook is used to add an event listener for the resize event on the window. &lt;/li&gt;
&lt;li&gt;When the window is resized, the &lt;em&gt;handleResize&lt;/em&gt; function is called, updating the windowWidth state.&lt;/li&gt;
&lt;li&gt;A cleanup function is returned from the useEffect hook. This is to remove the event listener when the component is unmounted.&lt;/li&gt;
&lt;li&gt;The empty dependency array ([ ]) means that the effect runs only once after the initial render.&lt;/li&gt;
&lt;li&gt;The component returns a div with the class name "memo-textarea."&lt;/li&gt;
&lt;li&gt;Inside the div, there is a TextField component from Material-UI.&lt;/li&gt;
&lt;li&gt;The sx prop is used to apply custom styles to the TextField. Width is set dynamically based on the windowWidth state, and there's some margin.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Refresher - What Are Hooks💡
&lt;/h2&gt;

&lt;p&gt;React Hooks are functions that allow functional components in React to manage state, lifecycle events and side effects. &lt;br&gt;
They were introduces in React 16.8 as a way to enable stateful logic in functional components, which was only possible previously with class components.&lt;/p&gt;

&lt;h3&gt;
  
  
  TLDR - Rule of Hooks 🔱
&lt;/h3&gt;

&lt;p&gt;There are a few rules to using Hooks to ensure consistent and correct usage of React Hooks. Just remember:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Only Call Hooks at the Top Level of your React functional component.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Only Call Hooks from React Functions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Do Not Call Hooks Conditionally.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Always Call Hooks in the Same Order.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Only Call Hooks from React Components or Custom Hooks.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;useState&lt;/strong&gt; and &lt;strong&gt;useEffect&lt;/strong&gt; hooks are two of the most commonly used React hooks. This was just one example of its application.&lt;/p&gt;

&lt;p&gt;Media queries can also be used to build a responsive design. Let me know your thoughts!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/glowiep/quick-memo"&gt;Visit code repository&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Custom Code Snippets in VS Code</title>
      <dc:creator>Gloria Lim</dc:creator>
      <pubDate>Thu, 15 Feb 2024 02:38:25 +0000</pubDate>
      <link>https://dev.to/glowiep/custom-code-snippets-in-vs-code-ohj</link>
      <guid>https://dev.to/glowiep/custom-code-snippets-in-vs-code-ohj</guid>
      <description>&lt;p&gt;When coding in Visual Studio Code, how often did you feel unsure about the syntax or format of a function, and had to look it up in Google? Were you so focused coding in Python for the past 3 months and have now forgotten how React hooks look like?&lt;/p&gt;

&lt;p&gt;This is a great reason to set up custom snippets in VS Code.&lt;/p&gt;

&lt;p&gt;Recently, I added custom snippets for React hooks. The snippet lives in a JSON file and looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"useReducer Hook": {
            "prefix": "use",
            "body": ["const ${1:INITIAL_STATE} = {", "", "}", "", "function reducer(state, action) {", "  switch (action.type) {", "    case \"${4:NameMe}\":", "      // Do something here", "      return", "  }", "}", "", "const [${2:state}, ${3:dispatch}] = useReducer(reducer, $1)"],
            "description": "Creates a useReducer expression"
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The key for the snippet object, "useReducer Hook" is the &lt;strong&gt;snippet name&lt;/strong&gt;. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;prefix&lt;/strong&gt; defines one or more trigger words that display the snippet in IntelliSense.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;body&lt;/strong&gt; is one or more lines of content, which will be joined as multiple lines upon insertion. Newlines and embedded tabs will be formatted according to the context in which the snippet is inserted.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;description&lt;/strong&gt; is an optional description of the snippet displayed by IntelliSense.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Source: &lt;a href="https://code.visualstudio.com/docs/editor/userdefinedsnippets#:~:text=Create%20your%20own%20snippets,-You%20can%20easily&amp;amp;text=To%20create%20or%20edit%20your,should%20appear%20for%20all%20languages."&gt;VS Code Docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my React JavaScript file, I can simply type in 'use' as I had predefined it as a shortcut to the custom snippet.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5nr234mossp9pjag8noq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5nr234mossp9pjag8noq.png" alt="Code snippet preview" width="642" height="696"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  💡What It Looks Like
&lt;/h2&gt;

&lt;p&gt;As you can see, I have 3 predefined custom snippets there. It shows a preview of the code snippet, and when I hit enter, it prints the snippet to my file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5p4f6sa8lt1ozar9mwfh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5p4f6sa8lt1ozar9mwfh.png" alt="Code snippet" width="631" height="342"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you look closely at the configuration, you will notice the parameters that starts with $. These are the user insertion points, and it will automatically place your text cursor there right after the snippet is added to your file. &lt;/p&gt;

&lt;h2&gt;
  
  
  🔧To Create A Custom Snippet
&lt;/h2&gt;

&lt;h4&gt;
  
  
  (for just about anything!)
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;In VS Code, open &lt;strong&gt;File&lt;/strong&gt; &amp;gt; &lt;strong&gt;Preferences&lt;/strong&gt; &amp;gt; &lt;strong&gt;Configure User Snippets&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;You have the option to create a &lt;strong&gt;New Global Snippets file&lt;/strong&gt; option to create a global configuration file. Or &lt;strong&gt;New Snippets file for ...&lt;/strong&gt; to create a local configuration file.&lt;/li&gt;
&lt;li&gt;Select the language for the code snippet.&lt;/li&gt;
&lt;li&gt;Give the file an easily identifiable name.&lt;/li&gt;
&lt;li&gt;Notice the comments in the newly created file. It gives you a guide on what is required for the custom snippet to work. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You can copy and paste the example in the commented out code there as a baseline.&lt;/p&gt;

&lt;p&gt;I have also created XML and SQL code snippets for my daily work and it has been a great experience! &lt;/p&gt;

&lt;p&gt;You can &lt;a href="https://gist.github.com/glowiep/6949391f98e902f8299c2ccf4e69a416"&gt;visit this Gist&lt;/a&gt; to see an example of my JavaScript configuration code.&lt;/p&gt;

&lt;h3&gt;
  
  
  💫Shortcut
&lt;/h3&gt;

&lt;p&gt;You can also use this wonderful &lt;a href="https://snippet-generator.app/?description=&amp;amp;tabtrigger=&amp;amp;snippet=&amp;amp;mode=vscode"&gt;snippet generator&lt;/a&gt; by Pawel Grzybek to create your snippets.&lt;/p&gt;

&lt;p&gt;If you gave this a try, let me know your thoughts!&lt;/p&gt;

</description>
      <category>vscode</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
