<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ken Aqshal on Medium]]></title>
        <description><![CDATA[Stories by Ken Aqshal on Medium]]></description>
        <link>https://medium.com/@kenaqshal31?source=rss-3fdb7ba3a9a1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wGBxu1n8ltyBHty99orbAg.jpeg</url>
            <title>Stories by Ken Aqshal on Medium</title>
            <link>https://medium.com/@kenaqshal31?source=rss-3fdb7ba3a9a1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 01:27:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kenaqshal31/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Debugging Dockerized Go Applications with VS Code]]></title>
            <link>https://levelup.gitconnected.com/debugging-dockerized-go-applications-with-vs-code-26b48e9c806b?source=rss-3fdb7ba3a9a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/26b48e9c806b</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[docker-compose]]></category>
            <dc:creator><![CDATA[Ken Aqshal]]></dc:creator>
            <pubDate>Tue, 07 Mar 2023 02:44:24 GMT</pubDate>
            <atom:updated>2023-03-14T15:17:07.843Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cQBcoaXQO9rdVwwh" /><figcaption>Cover image by author</figcaption></figure><p>For developers, debugging becomes a crucial and challenging aspect of software development. It’s like being a detective, searching for clues and piecing together the story of what went wrong in your code. But, just like any detective story, it’s also a challenge. Debugging in a containerized environment, like Docker, adds an extra layer of complexity. However, with the right tools and approach, debugging Go applications in Docker containers can be a straightforward and rewarding experience.</p><p>Go, also known as Golang, is a powerful open-source programming language known for its simplicity, efficiency, and reliability. But, when it comes to deploying and managing applications, there’s a better solution — Docker containers, especially when microservices continue to gain popularity. Docker containers provide a standardized, isolated environment for your Go applications, making deployment and management a breeze.</p><p>In this post, you will explore how to debug Go applications in Docker containers using Visual Studio Code. this post will cover the necessary steps for setting up the debugger and walk through the process of debugging a Go application both with docker and docker-compose. By the end of this post, you should better understand how to debug Go applications in Docker containers using Visual Studio Code.</p><p>So, if you’re ready to elevate your debugging game and make your life as a developer easier, keep reading! you won’t regret it.</p><h3>Prerequisite</h3><ul><li>Golang 1.16 or higher</li><li>Docker</li><li>Visual Studio Code</li></ul><h3>Setting up</h3><p>Firstly, ensure that all prerequisites are installed. Once that is done, proceed with setting up the project. In this blog, we will use <a href="https://docs.gofiber.io/">gofiber</a> for a sample application to debug Go applications. Follow the steps below:</p><ol><li>Create app folder</li></ol><pre>mkdir go-debugger &amp;&amp; cd go-debugger</pre><p>2. Add the following content to Dockerfile file</p><pre># syntax=docker/dockerfile:1<br>FROM golang:1.18-alpine<br><br>WORKDIR /app<br><br>COPY go.mod go.sum ./<br>RUN go mod download<br><br>COPY . .<br><br>RUN go build -o go-debugger .<br><br>EXPOSE 3000<br><br>CMD [&quot;/app/go-debugger&quot;]</pre><p>3. Build the image from the code</p><pre>docker build --tag go-debugger-image .</pre><p>4. After finishing the build, we can verify it by running command below in the terminal</p><pre>docker images --filter &quot;reference=go-debugger-image&quot;</pre><p>it will show the information about the local image that you create, and the information should be like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kzBq62NiGdwbdJ2iAmfWjA.png" /><figcaption>Search docker image. Image by author</figcaption></figure><p>5. After we check the image, let’s run your image as a container with this command</p><pre>docker run -d -p 3000:3000 --name go-debugger-container go-debugger-image</pre><p>6. Verify if the container is successfully run with the command</p><pre>docker ps --filter &quot;name=go-debugger-container&quot;</pre><p>the display information should be like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ri0H4mM7m3Y2KPOy_8qxBA.png" /><figcaption>Search docker container. Image by author</figcaption></figure><p>7. Check by open http://localhost:3000/, the page will show this to you</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*xnWseakruSfW_2CewOGM4Q.png" /><figcaption>Test the API. image by author</figcaption></figure><h3>But how to debug it?</h3><p>Great work verifying everything is working! Now, let’s take it a step further and debug the app inside the Docker container. But before we dive into debugging, we need to create a separate Dockerfile version specifically for debugging purposes. This way, we’ll have a “normal” Dockerfile to run the app as usual, without debug mode.</p><p>Why do we need to separate the Dockerfile? We’re using a third-party package called <a href="https://github.com/go-delve/delve"><strong>delve</strong></a> to enable us to debug the Go app inside the Docker container. And because we’re using an external package, we need to configure the Docker image differently to ensure that delve works properly.</p><p>So, let’s get ready to debug our app and unravel any issues lurking inside the container!</p><ol><li>Let’s create a dockerfile for debug only</li></ol><pre>touch Dockerfile.debug</pre><p>2. Add the following content to Dockerfile.debug file</p><pre>FROM golang:1.18-alpine<br><br>EXPOSE 3000 4000<br><br>WORKDIR /app<br>COPY go.mod go.sum ./<br>RUN go mod download<br><br>COPY . .<br><br>RUN CGO_ENABLED=0 go install -ldflags &quot;-s -w -extldflags &#39;-static&#39;&quot; github.com/go-delve/delve/cmd/dlv@latest<br><br>RUN CGO_ENABLED=0 go build -gcflags &quot;all=-N -l&quot; -o go-debugger .<br><br><br>CMD [ &quot;/go/bin/dlv&quot;, &quot;--listen=:4000&quot;, &quot;--headless=true&quot;, &quot;--log=true&quot;, &quot;--accept-multiclient&quot;, &quot;--api-version=2&quot;, &quot;exec&quot;, &quot;/app/go-debugger&quot; ]</pre><p>there are some commands that you must be aware of:</p><ul><li>--listen=:4000 this is will be the port that your debugger(delve) listen to. that&#39;s why we expose 2 ports in EXPOSE 3000 4000</li><li>CGO_ENABLED=0 is required for not making the delve configuration become <a href="https://stackoverflow.com/a/72558908/11900235">dynamic</a> compiled</li><li>-gcflags=all=&quot;-N -l&quot; is used for disable inlining and optimizing because it can <a href="https://github.com/golang/vscode-go/blob/master/docs/debugging.md#launch">interfere</a> with the debugging process</li></ul><p>3. Next step is you must build a new image with Dockerfile.debug configuration</p><pre>docker build --file Dockerfile.debug --tag go-debugger-image . </pre><p>4. After finish build the image, the next step is to remove the previous container because we can’t have 2 containers with the same name</p><pre>docker container rm go-debugger-container</pre><p>5. After deleting, let’s run your image as a container</p><pre>docker run -d -p 3000:3000 -p 4000:4000 --name  go-debugger-container go-debugger-image</pre><p>6. After successfully running your container. now let’s prepare the debugger in VS Code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MwJzt3oQAGbv0m0X7fiiDg.png" /><figcaption>Create debugger config. image by author</figcaption></figure><p>7. After that, you will have a launch.json , Add the following content to it</p><pre>{<br>    &quot;version&quot;: &quot;0.2.0&quot;,<br>    &quot;configurations&quot;: [{<br>        &quot;name&quot;: &quot;Go Containerized Debug&quot;,<br>        &quot;type&quot;: &quot;go&quot;,<br>        &quot;request&quot;: &quot;attach&quot;,<br>        &quot;mode&quot;: &quot;remote&quot;,<br>        &quot;port&quot;: 4000,<br>        &quot;host&quot;: &quot;127.0.0.1&quot;<br>    }]<br>}</pre><p>8. Now, let’s try to set some breakpoints and run the debugger</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qsx9dKza5PbMrUdc2JSSpg.png" /><figcaption>Set breakpoints and run debugger. Image by author</figcaption></figure><p>9. After you run the debugger, let’s verify it with open http://localhost:3000/test . it&#39;s should be automatic redirect to your vs code like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FY-uHdlxUrzKys8HdZ5OTA.png" /><figcaption>Debugging process. Image by author</figcaption></figure><p>Awesome! You’ve successfully set up your code for debugging in a Docker container. Now, get ready to dive deep into your code and uncover any pesky bugs that have been hiding!</p><h3>Debugging like a Pro with Docker Compose</h3><p>But hold on a minute…what if you want to take it to the next level and run your app with Docker Compose? After all, many modern development workflows rely on container management. Well, fear not! Setting it up with Docker Compose is easy as pie, and I’m here to show you how it’s done. Let’s get started!</p><p>1. Make sure that no application will use ports that we expose in Dockerfile.debug. In this case, you expose ports 3000 and 4000. if there&#39;s an application that used the port, stop it</p><p>2. let’s make the docker-compose.yml with command</p><pre>touch docker-compose.yml</pre><p>3. Add the following content to your docker-compose.yml</p><pre>version: &quot;3.9&quot;<br>services:<br>  app:<br>    build: <br>      context: .<br>      dockerfile: Dockerfile.debug<br>    ports:<br>      - &quot;3000:3000&quot;<br>      - &quot;4000:4000&quot;</pre><p>4. Now, let’s create and run the container with the command</p><pre>docker compose up</pre><p>5. Now let’s run the debugger in VS code like in step 8 before</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XzZbN32jKi7hyGh6q_Q3zg.png" /><figcaption>Set breakpoints and run debugger. Image by author</figcaption></figure><p>6. Verify the debug with an open URL http://localhost:3000/test and it will redirect to VS code like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0NCLLzF32Uc_6iq5FJQ3ZQ.png" /><figcaption>Debugging process. Image by author</figcaption></figure><p>Fantastic! You’re ready to take your debugging skills to the next level with Docker Compose. By leveraging this powerful tool, you’ll be able to manage your containers more effectively and streamline your development workflow. Whether you’re dealing with complex code or simply looking to improve your debugging abilities, Docker Compose is an excellent tool in your arsenal. So, what are you waiting for? It’s time to debug like a pro!</p><h3>Conclusion</h3><p>here is a wrap-up about this blog post that you’ve read</p><ul><li>Debugging is possible in Golang with the third-party package <a href="https://github.com/go-delve/delve">Delve</a></li><li>You can debug the app with delve on both docker and docker-compose with some additional.</li><li>I recommend separating the “normal” Dockerfile and “debug” Dockerfile because there’s a custom configuration to make Delve run smoothly, and changing the environment becomes easier.</li></ul><h3>Reference</h3><ul><li><a href="https://github.com/kenaqshal/go-debugger">Full code repository</a></li><li>VS code Golang debugging <a href="https://github.com/golang/vscode-go/blob/master/docs/debugging.md">guide</a></li><li>Delve usage <a href="https://github.com/go-delve/delve/tree/master/Documentation/api#usage">guide</a></li><li>CGO_ENABLED <a href="https://stackoverflow.com/questions/72539868/debug-golang-in-containers-with-delve-container-linux-go380-starting-containe">issue</a></li></ul><h3>Enjoyed this post?</h3><p>Check out some of my other articles:</p><ul><li><a href="https://www.kenaqshal.com/blog/connecting-to-multiple-databases-with-node-js-and-prisma">How To Connect Multiple Database With Node JS and Prisma</a></li><li><a href="https://www.kenaqshal.com/blog/race-condition-on-state-react-js">Race condition on state react.js</a></li><li><a href="https://www.kenaqshal.com/blog/understanding-pointer-in-golang">Understanding pointer in golang</a></li><li><a href="https://www.kenaqshal.com/blog/connecting-to-multiple-databases-with-node-js-and-prisma">How To Connect Multiple Database With Node JS and Prisma</a></li></ul><p><em>Originally published at </em><a href="https://www.kenaqshal.com/blog/debugging-dockerized-go-applications"><em>https://www.kenaqshal.com</em></a><em> on March 7, 2023.</em></p><h3>Level Up Coding</h3><p>Thanks for being a part of our community! Before you go:</p><ul><li>👏 Clap for the story and follow the author 👉</li><li>📰 View more content in the <a href="https://levelup.gitconnected.com/?utm_source=pub&amp;utm_medium=post">Level Up Coding publication</a></li><li>💰 Free coding interview course ⇒ <a href="https://skilled.dev/?utm_source=luc&amp;utm_medium=article">View Course</a></li><li>🔔 Follow us: <a href="https://twitter.com/gitconnected">Twitter</a> | <a href="https://www.linkedin.com/company/gitconnected">LinkedIn</a> | <a href="https://newsletter.levelup.dev/">Newsletter</a></li></ul><p>🚀👉 <a href="https://jobs.levelup.dev/talent/welcome?referral=true"><strong>Join the Level Up talent collective and find an amazing job</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26b48e9c806b" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/debugging-dockerized-go-applications-with-vs-code-26b48e9c806b">Debugging Dockerized Go Applications with VS Code</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Connect Multiple Database With Node JS and Prisma]]></title>
            <link>https://medium.com/@kenaqshal31/how-to-connect-multiple-database-with-node-js-and-prisma-b3abd3d0d21c?source=rss-3fdb7ba3a9a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3abd3d0d21c</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Ken Aqshal]]></dc:creator>
            <pubDate>Mon, 30 Jan 2023 10:34:33 GMT</pubDate>
            <atom:updated>2023-03-08T03:36:06.045Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mnPa6f1vNFO2GLKH" /><figcaption>Photo by Ken on Canva</figcaption></figure><p>Have you ever been in a situation where you have to access two databases on different platforms in an application?</p><p>Well, you found the right place to seek for help! When I researched this, I thought it would be very easy because I thought ORM currently supports the multiple database feature for my needs. But when I did research, I found that Prisma can only support <a href="https://www.prisma.io/docs/guides/database/multi-schema">multiple schema</a> in its official documentation.</p><p>Given that idea, it couldn’t fit in to the business case I was facing, not until I found <a href="https://github.com/prisma/prisma/issues/2443#issuecomment-630679118">this</a></p><p>This works like magic! I could access both PostgreSQL and MySQL databases in one application simultaneously.</p><p>Now, I’ll show you how to do it. Follow me.</p><h3>Step 1: Prerequisite</h3><p>What you need:</p><ul><li>Node JS</li><li>Nest JS CLI</li><li>PostgreSQL</li><li>MySQL</li></ul><h3>Preparing Repository</h3><p>We will be doing this tutorial with a Nest JS template. Therefore, if you haven’t installed the NestJS CLI yet, you need to install it globally first</p><pre>npm install -g @nestjs/cli </pre><p>After that, we initialize the project with the command</p><pre>nest new multi-database-prisma</pre><p>When there is a choice, we choose <strong>npm</strong> then after it’s done we move to the folder, then we move to the project and install Prisma with the command</p><pre>cd multi-database-prisma &amp;&amp; npm install prisma --save-dev</pre><p>Then when it’s done, we will initialize Prisma with the command</p><pre>npx prisma init</pre><p>The above command does 2 things:</p><ul><li>Create a prisma folder containing the schema.prisma file</li><li>Create a .env file After all the steps above are done, you&#39;re finished preparing the project repository we will use, but you can also check the <a href="https://www.prisma.io/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases-typescript-postgres#set-up-prisma">official</a> documentation if you want to know more.</li></ul><h3>Preparing Database</h3><p>After we’ve finished setting up the repository, you need to prepare a simulation of the existing databases. In this case, the naming of the 2 databases and each of their tables will be like this:</p><h4>First Database:</h4><p>name: first_db<br>platform: PostgreSQL<br>table: person</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/292/0*DloxdAsPwbK9FRQr" /><figcaption>Person Table</figcaption></figure><h4>Second Database:</h4><p>name: second_db<br>platform: MySQL<br>table: pets</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/277/0*vlOpaFaEbdQdDmga" /><figcaption>Pets Table</figcaption></figure><p>You can create tables with a structure like the above by running the following queries:</p><p>first_db(PostgreSQL)</p><pre>1 CREATE DATABASE &quot;first_db&quot;; 2CREATE TABLE &quot;public&quot;.&quot;person&quot; (&quot;id&quot; serial,&quot;name&quot; text NOT NULL, PRIMARY KEY (&quot;id&quot;)); 3INSERT INTO &quot;public&quot;.&quot;person&quot; (&quot;name&quot;) VALUES (&#39;ken&#39;);</pre><p>second_db(MySQL)</p><pre>1 CREATE DATABASE `second_db`; 2CREATE TABLE `second_db`.`pets` (`id` int NOT NULL AUTO_INCREMENT,`name` varchar(255),`type` varchar(255),`owner_id` int, PRIMARY KEY (id)); 3INSERT INTO `second_db`.`pets` (`name`, `type`, `owner_id`) VALUES (&#39;mochi&#39;, &#39;cat&#39;, &#39;1&#39;);</pre><h3>Step 2: defining the first database connection</h3><p>First, you need to fill in the DATABASE_URL variable in the .env file according to the credentials formed into a <strong>connection string</strong> like <a href="https://www.prisma.io/docs/reference/database-reference/connection-urls#env">this</a>. In the local env, the value of the env becomes like this</p><pre>postgresql://postgres:root@localhost:5432/db_name?schema=public</pre><p>because in this case, we will be using an existing database, we will run</p><pre>npx prisma db pull</pre><p>so we can generate <a href="https://www.prisma.io/docs/reference/api-reference/command-reference#db-pull">schema</a> based on the connected database.</p><p>After the above process is successful, we will generate the <strong>prisma client</strong> with the command.</p><pre>npx prisma generate</pre><p>according to the data model defined in the prisma/schema.prisma file.</p><h3>Step 3: defining the second database connection</h3><p>To define the second part, we need to create a new folder at the root named <strong>prisma-second</strong>, inside it we will create a file schema.prisma like this:</p><pre>generator client {<br>  provider = &quot;prisma-client-js&quot;<br>  output   = &quot;../node_modules/@internal/prisma-second/client&quot;<br>}<br><br>datasource db {<br>  provider = &quot;mysql&quot;<br>  url      = env(&quot;SECOND_DATABASE_URL&quot;)<br>}</pre><p>You might wonder why do we have to add the <strong>output</strong> to the client. It’s because when there are 2 instances of Prisma in one application, we have to specify the output when generating the data model, as mentioned <a href="https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/generating-prisma-client#using-a-custom-output-path">here</a> to avoid overwriting the Prisma client from the <strong>first</strong> database connection.</p><p>Then, we need to add the SECOND_DATABASE_URL variable to the .env file, and you fill in the DB credentials according to the connection string format like <a href="https://www.prisma.io/docs/reference/database-reference/connection-urls#env">this</a> in my case, the value of the variable will be like this:</p><pre>mysql://root:root@localhost:3306/second_db</pre><p>After that, we will do the DB pull again but with the added <a href="https://www.prisma.io/docs/reference/api-reference/command-reference#arguments-4">schema</a> argument to generate the <strong>second</strong> connection using this command:</p><pre>npx prisma db pull --schema=./prisma-second/schema.prisma</pre><p>After we finish generating the data model for the second existing database, we will then generate the Prisma client for the second DB using the command:</p><pre>npx prisma generate --schema=./prisma-second/schema.prisma</pre><p>And we must also add the schema argument to specify the schema we want to generate the <strong>Prisma client</strong> for. And if you look in the node_modules/@internal there will be a folder called Prisma Second, according to the path we defined in the schema.prisma file in the prisma-second folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/0*UD8VbFeiQpfHBrVZ" /><figcaption>Prisma Second Client Folder</figcaption></figure><h3>Step 4: Fetch data from 2 data source</h3><p>You will be trying to retrieve data from 2 different data sources. First of all, we will create a folder named prisma under src containing 3 files like this</p><p><strong>prisma.service.ts</strong></p><pre>import { Injectable, OnModuleDestroy, OnModuleInit } from &#39;@nestjs/common&#39;;<br>import { Prisma, PrismaClient } from &#39;@prisma/client&#39;;<br><br><br>@Injectable()<br>export class PrismaService<br>  extends PrismaClient&lt;Prisma.PrismaClientOptions, &#39;error&#39; | &#39;query&#39;&gt;<br>  implements OnModuleInit, OnModuleDestroy {<br><br>  async onModuleInit() {<br>    await this.$connect();<br><br>    this.$on(&#39;error&#39;, (_e) =&gt; {<br>      // Do something<br>    });<br><br>  }<br><br>  async onModuleDestroy() {<br>    await this.$disconnect();<br>  }<br>} </pre><p><strong>prisma-second.service.ts</strong></p><pre>import { Injectable, OnModuleDestroy, OnModuleInit } from &#39;@nestjs/common&#39;;<br>import { Prisma, PrismaClient } from &#39;@internal/prisma-second/client&#39;;<br><br>@Injectable()<br>export class PrismaSecondService<br>  extends PrismaClient&lt;Prisma.PrismaClientOptions, &#39;error&#39; | &#39;query&#39;&gt;<br>  implements OnModuleInit, OnModuleDestroy {<br><br><br>  async onModuleInit() {<br>    await this.$connect();<br><br>    this.$on(&#39;error&#39;, (_e) =&gt; {<br>      // Do something<br>    });<br><br>  }<br><br>  async onModuleDestroy() {<br>    await this.$disconnect();<br>  }<br>}</pre><p><strong>prisma.module.ts</strong></p><pre>import { Module } from &#39;@nestjs/common&#39;;<br>import { PrismaSecondService } from &#39;./prisma-second.service&#39;;<br><br>import { PrismaService } from &#39;./prisma.service&#39;;<br><br>@Module({<br>  providers: [PrismaService, PrismaSecondService],<br>  exports: [PrismaService, PrismaSecondService],<br>})<br>export class PrismaModule {}</pre><p>Your folder’s structure should be like this when you’ve added the files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*WDtsUZvEE0FYF09A" /></figure><p>After defining the Prisma module, we will create an API that will retrieve Person and Pets data from 2 different databases and return the result when we hit the API. To do that, change the files below like this: app.service.ts</p><pre>import { Injectable } from &#39;@nestjs/common&#39;;<br>import { PrismaService } from &#39;./prisma/prisma.service&#39;;<br>import { PrismaSecondService } from &#39;./prisma/prisma-second.service&#39;;<br>@Injectable()<br>export class AppService {<br>  constructor(private prisma: PrismaService, private prisma_second: PrismaSecondService) {}<br><br>  async getData(): Promise&lt;any&gt; {<br>    <br>    const persons = await this.prisma.person.findMany();<br><br>    const pets = await this.prisma_second.pets.findMany();<br><br>    let data = persons.map(person =&gt;{<br>      let pet = pets.filter(x =&gt; x.owner_id === person.id)<br>      return {<br>        ...person,<br>        pets: pet<br>      }<br>    })<br>    <br>    return data<br>  }<br>}</pre><p>app.controller.ts</p><pre>import { Controller, Get } from &#39;@nestjs/common&#39;;<br>import { AppService } from &#39;./app.service&#39;;<br><br>@Controller()<br>export class AppController {<br>  constructor(private readonly appService: AppService) {}<br><br>  @Get()<br>  getData() {<br>    return this.appService.getData();<br>  }<br>}</pre><p>app.module.ts</p><pre>import { Module } from &#39;@nestjs/common&#39;;<br>import { AppController } from &#39;./app.controller&#39;;<br>import { AppService } from &#39;./app.service&#39;;<br>import { PrismaModule } from &#39;./prisma/prisma.module&#39;;<br><br>@Module({<br>  imports: [PrismaModule],<br>  controllers: [AppController],<br>  providers: [AppService],<br>})<br>export class AppModule {}</pre><p>Then run the command below to start:</p><pre>npm run start </pre><p>If successful, next you need to open http://localhost:3000 then we will successfully be able to call the API with 2 different data sources</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/0*2pLWy5w8r613BAM9" /></figure><h3>Conclusion</h3><p>You can create multiple database connections of different types in one project using Prisma.io as long as you pay attention to the following things:</p><ul><li>Creating separate schema.prisma files that are separate from one another</li><li>Defining <a href="https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/generating-prisma-client#using-a-custom-output-path">output</a> for each Prisma client and ensuring that there are no paths that are the same</li><li>Running the npx prisma db pull and npx prisma generate commands for the other Prisma instances with the --schema argument to specify which schema we will run</li><li>Defining a <strong>different</strong> Prisma service for each connection.</li></ul><h3>Resource</h3><ol><li>Full code <a href="https://github.com/kenaqshal/multiple_database_nestJs_prisma">repository</a></li><li><a href="https://www.prisma.io/docs/guides/database/multi-schema">Multiple schema</a> documentation</li><li>Multiple Database / Datasource <a href="https://github.com/prisma/prisma/issues/2443#issuecomment-630679118">issue</a></li></ol><h3>Enjoyed this post?</h3><p>Check out some of my other articles:</p><ul><li><a href="https://www.kenaqshal.com/blog/debugging-dockerized-go-applications">Debugging Dockerized Go Applications with VS Code</a></li><li><a href="https://www.kenaqshal.com/blog/race-condition-on-state-react-js">Race condition on state react.js</a></li><li><a href="https://www.kenaqshal.com/blog/understanding-pointer-in-golang">Understanding pointer in golang</a></li></ul><p><em>Originally published at </em><a href="https://www.kenaqshal.com/blog/connecting-to-multiple-databases-with-node-js-and-prisma"><em>https://www.kenaqshal.com</em></a><em> on January 30, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3abd3d0d21c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding pointer in Go]]></title>
            <link>https://medium.com/@kenaqshal31/understanding-pointer-in-go-ec3fc02af3dd?source=rss-3fdb7ba3a9a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec3fc02af3dd</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[pointers]]></category>
            <dc:creator><![CDATA[Ken Aqshal]]></dc:creator>
            <pubDate>Tue, 25 Oct 2022 09:48:41 GMT</pubDate>
            <atom:updated>2023-03-08T03:31:55.227Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*leRUSra3EfsfArytldVLzA.png" /></figure><h3>So, what is a pointer?</h3><p>Pointer is the variable type in golang that contain memory address to become a reference rather than the value itself. imagine that you have variable called nickname that has value Ken, so the pointer is stored memory address where value Ken is being saved with <strong>hexadecimal</strong> format that have prefix 0x like 0xc000010250.</p><p>Every pointer variable has a *(asterisk) symbol before the data type when declared the variable with nil as a default value.</p><p>And it would help if you remembered that the pointer variable could not store a value that is not a pointer or vice versa because the pointer variable has a hexadecimal format in-store the memory address.</p><p>Suppose you are wondering why there’s a pointer in golang. In that case, the pointer is suitable for torturing developers computation speed since it’s just a “number” that has a small size if it compares to the actual value.</p><h3>How to use it?</h3><p>Ok, so before you start to use pointer in golang, there’s something that you must know before</p><ul><li>You can get pointer values in regular variables by adding an ampersand (&amp;) right before the variable name. The name of this method is reference.</li><li>Vice versa, you can get the original value of a pointer variable by using an asterisk(*) right before the variable name. This method is called dereference.</li></ul><p>So let’s jump into the example</p><pre>package main</pre><pre>import &quot;fmt&quot;</pre><pre>func main() {<br> var nicknameA string = &quot;Ken&quot;<br> var nicknameB *string = &amp;nicknameA</pre><pre>fmt.Println(&quot;nicknameA (value) :&quot;, nicknameA)<br> fmt.Println(&quot;nicknameA (memory address) :&quot;, &amp;nicknameA) //referencing<br> fmt.Println(&quot;nicknameB (value) :&quot;, *nicknameB)          //derefencing<br> fmt.Println(&quot;nicknameB (memory address) :&quot;, nicknameB)<br>}</pre><p>If you run this in terminal, it will be like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*R3W-l8YokILYHFXc" /></figure><p>we have nicknameA as a regular variable and nicknameB as a pointer, so we have two variables that contain the same memory address at the same time. that&#39;s why when you print value of nicknameA and dereference variable nicknameB it will be print the same value</p><p>And you can also take a look at the memory address where the value is being stored with print nicknameB, which is the pointer variable, and dereferencing of variable nicknameA so that you will get the pointer value (with hexadecimal format)</p><h3>Is there any effect when we change the value?</h3><p>As I mentioned, that pointer only stores a memory address. So when there are one or more pointer variables that contain memory address to the regular variable, if there&#39;s a change in the value of the regular variable, all pointer variables that have address to the regular variable will take effect to change the value when the pointer is being dereferenced</p><p>let’s take a look in an example</p><pre>package main</pre><pre>import &quot;fmt&quot;</pre><pre>func main() {<br> var nicknameA string = &quot;Ken&quot;<br> var nicknameB *string = &amp;nicknameA</pre><pre>fmt.Println(&quot;Before change value&quot;)<br> fmt.Println(&quot;nicknameA (value) :&quot;, nicknameA)<br> fmt.Println(&quot;nicknameA (memory address) :&quot;, &amp;nicknameA)<br> fmt.Println(&quot;nicknameB (value) :&quot;, *nicknameB)<br> fmt.Println(&quot;nicknameB (memory address) :&quot;, nicknameB)</pre><pre>nicknameA = &quot;Bram&quot;</pre><pre>fmt.Println(&quot;\nAfter change value&quot;)<br> fmt.Println(&quot;nicknameA (value) :&quot;, nicknameA)<br> fmt.Println(&quot;nicknameA (memory address) :&quot;, &amp;nicknameA)<br> fmt.Println(&quot;nicknameB (value) :&quot;, *nicknameB)<br> fmt.Println(&quot;nicknameB (memory address) :&quot;, nicknameB)<br>}</pre><p>If you take try to run it in terminal, it will be like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/0*Nri3pkp42iOckpLf" /></figure><p>As you see, the nicknameB stores the address from nicknameA. So when nicknameA changes, the value of deferencing nicknameB will follow the actual value of nicknameA. and the memory address it&#39;s still remain same because you just change the value not the address</p><h3>Pointer in parameter</h3><p>pointer can be used as parameter in function. all you have to do is add an asterisk(*) before the definition of data type of the parameter, the same way you define the pointer variable. and you can also use referenceing and dereferencing too inside the function. but keep in mind if you want to change the actual value of the pointer variable, you have to dereference in the left assignment like this</p><pre>func replace(old *string, new string) {<br> *old = new<br>}</pre><p>so let’s just take a look at an example on how to use pointer as a parameter</p><pre>package main</pre><pre>import &quot;fmt&quot;</pre><pre>func replace(old *string, new string) {<br> *old = new<br>}</pre><pre>func main() {<br>    var word string = &quot;Ken&quot;<br>    fmt.Println(&quot;before:&quot;, word)</pre><pre>replace(&amp;word, &quot;Bramasta&quot;)<br>    fmt.Println(&quot;after:&quot;, word)<br>}</pre><p>You will create a function with two parameters, the first is old as a pointer variable, and the second is new as a regular variable. The logic inside the function will replace the old value that is already being dereferenced in the left argument with the new one new parameter. if you try to run this in the terminal, it should be like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/0*w_7_j2znWEW1H0rd" /></figure><p>now we have successfully modified the value of a variable that exists outside of a function</p><h3>Still confused about it?</h3><p>Ok, so if you’re unfamiliar with the pointer concept, you will still have doubt in your head. But you will get used to it over time when using pointers, and I will give you a comparison to another language that doesn’t have a pointer concept, like javascript</p><p>In javascript when we want to change the value of the variable through the logic inside the function, we can make it with a defined variable that will contain the return from the function like this</p><pre>let counting = (counter) =&gt;{<br>    counter += 1<br>    return counter<br>}</pre><pre>let counter = 1<br>counter = counting(counter)</pre><p>When you run this, it will return 2, and I think this is the only way to change the variable value through logic inside the function. But different with golang, you can do it in two ways. the first one is just like in the JS</p><pre>package main</pre><pre>import &quot;fmt&quot;</pre><pre>func counting(counter int) int {<br> counter += 1<br> return counter<br>}</pre><pre>func main() {<br> var count int = 1<br> count = counting(count)<br> fmt.Println(count)<br>}</pre><p>But you can also do that by using the pointer as a parameter to change variable value through the logic inside the function without returning the value.</p><h3>Recap</h3><ul><li>You can define the pointer variable by adding an asterisk(*) before the data type</li><li>Pointer can be used as a parameter in a function</li><li>Ampersand(&amp;) on the regular variable will reference memory address of the value</li><li>Asterisk(*) on the pointer variable will dereference the original value</li><li>Pointer can be used to modify the value that exists outside the function</li></ul><h3>Enjoyed this post?</h3><p>Check out some of my other articles:</p><ul><li><a href="https://www.kenaqshal.com/blog/debugging-dockerized-go-applications">Debugging Dockerized Go Applications with VS Code</a></li><li><a href="https://www.kenaqshal.com/blog/connecting-to-multiple-databases-with-node-js-and-prisma">How To Connect Multiple Database With Node JS and Prisma</a></li><li><a href="https://www.kenaqshal.com/blog/race-condition-on-state-react-js">Race condition on state react.js</a></li></ul><p><em>Originally published at </em><a href="https://www.kenaqshal.com/blog/understanding-pointer-in-golang"><em>https://www.kenaqshal.com</em></a><em> on October 25, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec3fc02af3dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Race condition on state react.js]]></title>
            <link>https://medium.com/@kenaqshal31/race-condition-on-state-react-js-1cb02ee6a633?source=rss-3fdb7ba3a9a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cb02ee6a633</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Ken Aqshal]]></dc:creator>
            <pubDate>Tue, 05 Jul 2022 06:47:00 GMT</pubDate>
            <atom:updated>2023-03-08T03:28:23.211Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hPxqv2lPh-vAHjhZ" /></figure><p>If you’re already familiar with react you must be familiar with state in react component right? and since function component become more popular than class component making us more familiar with setState to display any local state in our component.</p><p>but did you have an experience where your state doesn’t display correct data? like they show you the outdated version of a specific state? if the answer is yes, it means that you get into a race condition of state in react</p><p>normally this condition will happen if you have two different requests for change data in state at a slightly simultaneous moment. and then your data will display different results depending on which request that complete in the first place</p><h3>How to reproduce</h3><p>let’s take a look at the implementation of the race condition of state for this example we will use <strong>useState</strong> for the implementation, we will break down it into the following state:</p><ul><li>Apple: formed object, which holds information about how many apples each person has and we will use setTimeout for performing your fake fetch whenever properties apple count in the state has changed</li></ul><pre>import { useState } from &quot;react&quot;;<br><br>export default function App() {<br>  const [apple, setApple] = useState({<br>    ken: 0,<br>    bramasta: 0,<br>  });<br><br>  const fakeFetch = () =&gt; {<br>    const rand = Math.random() * (5000 - 1000) + 1000;<br>    return new Promise((resolve) =&gt; {<br>      setTimeout(resolve, rand);<br>    });<br>  };<br><br>  const onCLick = (name) =&gt; {<br>    fakeFetch().then(() =&gt; {<br>      setApple({<br>        ...apple,<br>        [name]: apple[name] + 1,<br>      });<br>    });<br>  };<br>  return (<br>    &lt;div className=&quot;App&quot;&gt;<br>      &lt;h2&gt;How much apples do you have?&lt;/h2&gt;<br><br>      &lt;p&gt;Ken : {apple[&quot;ken&quot;]}&lt;/p&gt;<br>      &lt;p&gt;Bramasta : {apple[&quot;bramasta&quot;]}&lt;/p&gt;<br><br>      &lt;button onClick={() =&gt; onCLick(&quot;ken&quot;)}&gt;Ken&lt;/button&gt;<br>      &lt;button onClick={() =&gt; onCLick(&quot;bramasta&quot;)}&gt;Bramasta&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>now try to hit random on each button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/0*6qP4Ok26T2Wqj5YW.gif" /></figure><p>now if you look at the count carefully the state count is doesn’t look to change normally because the expectation ken and bramasta become 1 each, but we got the final value ken 1 and bramasta 0. if you notice that the count is like a glitch to decrease their value when another count add, if we draw in flow it will be like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/0*mTiHoRp147vo6N2b" /></figure><h3>why does this happens??</h3><p>this can happen when you direct access the state and the state is currently computable by another setApple. so it basically doesn’t take the latest value of apple but the state takes the value when onClick function is excecuted not when setApple is executed, which means when the user clicks the button the value is still the default value of the state in this case</p><p>and if you want to imagine the process in a picture, you can take a look picture below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/0*cttVoMC01ybNNP52" /></figure><p>so the lastest state (lowermost) is still used default state because when the user does the second click. the function is executed but the first process of the function is not done yet, so the second process is still using the default value because the first process hasn’t done setApple yet</p><h3>How to prevent?</h3><p>so if you already understand why this state change abnormally, the next step is to find a way how to prevent it, and luckily this method is already explained in <a href="http://reactjs.org/docs/hooks-reference.html#functional-updates">react documentation</a>. so if you pass setApple with a function as its argument. you will always get the latest previous value no matter what order it will be called. In this case, we will modify how we set the state in onCLick function to like this</p><pre>const onClick = (name) =&gt; {<br>  fakeFetch().then(() =&gt; {<br>    setApple((prevApple) =&gt; ({<br>      ...prevApple,<br>      [name]: prevApple[name] + 1,<br>    }));<br>  });<br>};</pre><p>now the flow is like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/251/1*TSS9aZXERLVCBDEvKSwJVw.png" /></figure><p>When you updated the function, rebuild it. and Voila it’s not will run as you expected no matter how much you click it. that’s because right now whenever we want to change the state value with setApple. the setApple will always look at the latest value through prevApple not when onCLick function is being executed. that is how we avoid the pitty fall of this state race in react</p><h3>Conclusion</h3><p>So you must add a note that if a state change is dependent on the state’s previous value, always use the function argument to ensure the state change uses the correct and latest state value.</p><h3>Final Code</h3><pre>import { useState } from &quot;react&quot;;<br>import &quot;./styles.css&quot;;<br><br>export default function App() {<br>  const [apple, setApple] = useState({<br>    ken: 0,<br>    bramasta: 0,<br>  });<br><br>  const fakeFetch = () =&gt; {<br>    const rand = Math.random() * (5000 - 1000) + 1000;<br>    return new Promise((resolve) =&gt; {<br>      setTimeout(resolve, rand);<br>    });<br>  };<br><br>  const onClick = (name) =&gt; {<br>    fakeFetch().then(() =&gt; {<br>      setApple((prevApple) =&gt; ({<br>        ...prevApple,<br>        [name]: prevApple[name] + 1,<br>      }));<br>    });<br>  };<br>  return (<br>    &lt;div className=&quot;App&quot;&gt;<br>      &lt;h2&gt;How much apples do you have?&lt;/h2&gt;<br><br>      &lt;p&gt;Ken : {apple[&quot;ken&quot;]}&lt;/p&gt;<br>      &lt;p&gt;Bramasta : {apple[&quot;bramasta&quot;]}&lt;/p&gt;<br><br>      &lt;button onClick={() =&gt; onClick(&quot;ken&quot;)}&gt;Ken&lt;/button&gt;<br>      &lt;button onClick={() =&gt; onClick(&quot;bramasta&quot;)}&gt;Bramasta&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h3>Resources</h3><ul><li><a href="http://reactjs.org/docs/hooks-reference.html#functional-updates">setState documentation</a></li><li><a href="https://codesandbox.io/s/xenodochial-rgb-4rjjdz">Full code sample</a></li></ul><p>Any queries and improvements are most welcome😉</p><h3>Enjoyed this post?</h3><p>Check out some of my other articles:</p><ul><li><a href="https://www.kenaqshal.com/blog/debugging-dockerized-go-applications">Debugging Dockerized Go Applications with VS Code</a></li><li><a href="https://www.kenaqshal.com/blog/connecting-to-multiple-databases-with-node-js-and-prisma">How To Connect Multiple Database With Node JS and Prisma</a></li><li><a href="https://www.kenaqshal.com/blog/understanding-pointer-in-golang">Understanding pointer in golang</a></li></ul><p><em>Originally published at </em><a href="https://www.kenaqshal.com/blog/race-condition-on-state-react-js"><em>https://www.kenaqshal.com</em></a><em> on July 5, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cb02ee6a633" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Things you need to know about local storage in JavaScript]]></title>
            <link>https://medium.com/@kenaqshal31/things-you-need-to-know-about-local-storage-in-javascript-6f62d919b0bc?source=rss-3fdb7ba3a9a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f62d919b0bc</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ken Aqshal]]></dc:creator>
            <pubDate>Sat, 09 Apr 2022 14:57:44 GMT</pubDate>
            <atom:updated>2023-03-08T03:17:52.954Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wtAHhXoHMUFyEH62" /><figcaption>Photo by <a href="https://unsplash.com/@ruchindra?utm_source=medium&amp;utm_medium=referral">Ruchindra Gunasekara</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>What it’s Local Storage</h3><p>local Storage is a Storage mechanism that same as Session storage in Web Storage API, that allows you to save states like simple key-value store in object concept in JavaScript</p><p>The different mechanism between object and web storage stays intact during every page load. And the keys and the values are always stored in strings (note that, as with objects, integer keys will be automatically converted to strings)</p><h3>The Different between Local Storage and Session Storage</h3><p>the main concept that makes the two things different is the duration mechanism for storing the value. LocalStorage will never get expired even when the user closes and open the browser multiple time. However, if you use sessionStorage, the state will be clear when the browser is closed.</p><h3>Where is it being stored?</h3><p>LocalStorage is stored as an SQLite file under the user’s profile folder. if you use google chrome, it will be stored in \AppData\Local\Google\Chrome\User Data\Default\Local Storage and in firefox, the browser will store it in webappsstore.sqlite,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pBUCKS7ccksczUwY" /><figcaption>Photo by <a href="https://unsplash.com/@alex_andrews?utm_source=medium&amp;utm_medium=referral">Alexander Andrews</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>The Function Properties</h3><h3>key</h3><p>The key() the method comes in handy in situations where you need to loop through keys and pass a number or index to retrieve the name of the key for the value that has already been set in Storage.</p><h4>var KeyName = localStorage.key(index);</h4><h3>setItem</h3><p>this method allows you to store values in the Storage</p><p>It takes two parameters: a key and a value itself. We can use the key later to fetch the value you attached.</p><pre>localStorage.setItem(&#39;background&#39;, &#39;dark&#39;);</pre><p>Where background is the key, and dark is the value. Also, note that localStorage you can only store strings.</p><p>To store values that form in arrays and objects, you must convert them to strings before setting them to Storage.</p><p>To do this, we use JSON.stringify() a method before we pass the value to setItem().</p><pre>//store object  <br>const animal = {name: &quot;Crow&quot;, color: &quot;Black&quot;}  <br>localStorage.setItem(&#39;user&#39;, JSON.stringify(animal));  <br>  <br>//store array  <br>const arrAnimal = [{name: &quot;Crow&quot;, color: &quot;Black&quot;}, {name: &quot;Bull&quot;, color: &quot;Red&quot;}]  <br>localStorage.setItem(&#39;user&#39;, JSON.stringify(arrAnimal));</pre><h3>getItem</h3><p>To get items from Storage, we use the getItem() method. The method allows you to access the data stored in the Storage.</p><p>getItem() Accepts only one parameter, which is the key one that you used to set before, and returns the value as a string.</p><p>To retrieve an animal key:</p><pre>localStorage.getItem(&#39;animal&#39;);</pre><p>Returns a string with value as:</p><pre>&quot;{name: &#39;Crow&#39;, color: &#39;Black&#39;}&quot;</pre><p>Because the return value always returns a string, you must first convert it back to an object.</p><p>To do that, we can use JSON.parse() the method to convert a JSON string into a JavaScript object.</p><pre>JSON.parse(localStorage.getItem(&#39;animal&#39;));</pre><h3>removeItem</h3><p>To delete local data, use the removeItem() method.</p><p>When passed a key name in the removeItem() The method will remove the key from Storage if it exists. But if there is no item associated with the given key, the method will do nothing.</p><pre>localStorage.removeItem(&#39;animal&#39;);</pre><h3>clear</h3><p>Use the clear() method to reset all items that are already stored in Storage.</p><p>When this method is invoked, it will clear the entire record in the storage domain, and It does not receive any parameters.</p><pre>localStorage.clear();</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jes4zjMHoVU7X4eq" /><figcaption>Photo by <a href="https://unsplash.com/@justinchrn?utm_source=medium&amp;utm_medium=referral">Justin Chrn</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Things that you must note</h3><p>Besides LocalStorage having a cool feature to help us store global value easily, it still has limits. below thing, you must note when you use local Storage is</p><ul><li>Please do not use it to store sensitive user information in because localStorage is accessible to the user</li><li>Max size for storage data is limited to 5MB</li><li>local Storage is not secure as it has no form of data protection and can be accessed by any code on your web page</li><li>localStorage still, adopt synchronous when the function is being executed, which means Storage must run each operation sequentially</li></ul><p>I hope you found this article useful and you learned something from it. If you did, please consider sharing it on Twitter so others can find it 😊</p><h3>Enjoyed this post?</h3><p>Check out some of my other articles:</p><ul><li><a href="https://www.kenaqshal.com/blog/understanding-pointer-in-golang">Understanding pointer in golang</a></li><li><a href="https://www.kenaqshal.com/blog/currency-formatting-on-javascript-es6">Currency formatting on JavaScript ES6</a></li><li><a href="https://www.kenaqshal.com/blog/race-condition-on-state-react-js">Race condition on state react.js</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f62d919b0bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Story: Become a QA at one of the biggest banks in Indonesia at the age of 19]]></title>
            <link>https://medium.com/@kenaqshal31/my-story-become-a-qa-at-one-of-the-biggest-banks-in-indonesia-at-the-age-of-19-24c9e091dc08?source=rss-3fdb7ba3a9a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/24c9e091dc08</guid>
            <category><![CDATA[software-testing]]></category>
            <category><![CDATA[quality-assurance]]></category>
            <category><![CDATA[banking]]></category>
            <category><![CDATA[automation-testing]]></category>
            <category><![CDATA[experience]]></category>
            <dc:creator><![CDATA[Ken Aqshal]]></dc:creator>
            <pubDate>Tue, 01 Feb 2022 10:58:23 GMT</pubDate>
            <atom:updated>2023-03-08T03:09:05.278Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8trrq0Pmh_87zXtD" /><figcaption>Photo by <a href="https://unsplash.com/@seanpollock?utm_source=medium&amp;utm_medium=referral">Sean Pollock</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>The Story Before Onboarding</h3><p>OK, before I start telling my experience. I want to let you know that I am a developer who predominantly uses TypeScript and focuses on the backend role. This started with my boss who suddenly informed me that I have to participate in a project by Bank Rakyat Indonesia and at first, I was excited because I will have experience in a project that makes middlewares for large scale and also experience in finance. When I attend the project briefing, I found out that in this project I will become a QA, and the first thing that I felt when I found out about it was that I am annoyed with my boss. But then I changed my mindset. If I can take advantage of this opportunity I can learn about how the banking system works and I also can take side hustle as a programmer, so it’s OK.</p><p>And here I am. I was interviewed to become a team member of this project by the head and team leader, and guess what the result turned out? I got approved to join. The interview itself was quite difficult because the questions were intensively about finance, banking experience, and middleware on a large scale, but I managed to answer all of them. Then, I was told that I will join the Middleware team at the HQ building on January 20, 2020.</p><h3>My First Impression of the First Day</h3><p>The first time I went to the floor where I worked, I was surprised by one thing: the table was not isolated like most companies I’ve been to. The concept of the table itself is an open desk fashion and that makes me happy because it’s easier to chat with other coworkers. Also when I arrived, I was surprised because it turned out to be a floor for developers while the floor for QA was on the lower floor. Well, when I came, the others were already focused on their respective work.</p><figure><img alt="Open Desk Concept Like This!!" src="https://cdn-images-1.medium.com/max/1024/0*bf1Ekj9C_GU8MLzm" /><figcaption>Open Desk Concept Like This!!</figcaption></figure><p>What’s strange for me here is that when I was on board, I was only accompanied by the team leader without being introduced to all of my team members. It took me 2 weeks to meet all of my team members because of the hybrid work-life between remote and onsite workers.</p><h3>How’s the Adaptation?</h3><p>OK, in this section I will explain highlighted points during my adaptation process and how big the learning curve was in the problems that I found during the process.</p><ol><li>There were no onboarding documents🤯 , I think that’s a fatal error for an enterprise-class company. Why? Because, while they have influence, there was no onboarding team document, which makes it difficult for me to learn about the culture and flow within the company.</li><li>The wiki of the application is outdated and incomplete😤. This makes it difficult for me to test the wares. Most issues I found were missing tutorial steps or the tutorial was not equipped with complementary pictures, which makes it difficult to understand the flow in a short time.</li><li>And this is what I think is enough to make it difficult for me to walk alone without guidance. There was no guide from each application about the explanation of each flow in an application. but actually, this can be prevented if the technical writer from the dev team can make a more complete and detailed unit test.</li></ol><h3>The Experience in My Role</h3><p>The scope of my work in this role was to create test cases, create automation test scripts using JMeter base on those test cases, provide the necessary documentation, and also keep track of issues and provide support until UAT and deployment tests.</p><p>What’s challenging here was that we had to adapt to a lot of things in different teams, because each team has its style of working and communicating so we had to adapt to each team. And here, I learned many new things for cases that might occur in the banking system. How to do the remark system, reversal, and suspend. Also with the status on the account such as freeze, close, and dormant.</p><p>When I was doing that, I thought I might be ridiculed because of my knowledge in banking when presenting the project to my head. But apparently NO. My head was there providing insight, suggestions for testing scenarios, mechanisms, and a lot of knowledge about the bank system. And sometimes when presenting to him, I thought, “Oh, yes, that’s possible. Why didn’t I think of it when I was doing the analysis,” that’s why I got excited to study banking. Because I know he is the right person to be my mentor as well as my teacher in addition to a teammate. And this will also be a provision that can help me in the future.</p><h3>Things I’ve Learned from this Journey</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-mcPoE0BFtItTU-R" /><figcaption>Photo by <a href="https://unsplash.com/@foxxmd?utm_source=medium&amp;utm_medium=referral">Matt Duncan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>1. You Are What You Think 🤔</h4><p>If you feel you don’t deserve to join a team because you are still young even though you have experience. You are wrong. You are worthy because you have also passed the test. And boom. When I think that I can compete with those above my age, I became more confident and didn’t feel inferior anymore</p><p><strong>When you think you are big, you get big.</strong></p><h4>2. It’s OK to Start Small 🙌</h4><p>I used to think we had to start big. It’s just because here, I have a lot of knowledge that I have to learn. So I understand what it feels like. It’s OK starting from small and simple things that later turn into extraordinary things.</p><h4>3. The Importance of Recording Progress 📕</h4><p>Finding something new or failing at something? I used to take notes and evaluate them. I used to be reluctant to do it, but now I do it so often. Why? Because I realize that I can’t improve if I don’t know what to improve in the future and what mistakes I can’t repeat. You don’t realize how much you have been growing until you move back to the beginning.</p><h4>4. Don’t Be Afraid to Take Challenges and Fail 🏃</h4><p>As I said, you don’t have to be afraid about that because it is part of the progress that leads you to become a better version of who you are. Because without that, we don’t make any progress. Deliberate practice and record progress, I’m never afraid to fail again.</p><h3>Afterwords</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nheKFFWAy7gXlY0VGvZeww.jpeg" /><figcaption>Yap that&#39;s me in navy</figcaption></figure><p>Thank you all for 1-year experience, as a person who is only 19 years old it’s valuable even though I have to end it because I preferred being a dev compared to a QA because being a QA at BRI has become my comfort zone and I feel that being a dev is more fun because I meet many challenges. but thanks for the knowledge that I have gained during this 1 year, it has been a success for you. Hope to be the best team. See you.</p><h3>Enjoyed this post?</h3><p>Check out some of my other articles:</p><ul><li><a href="https://www.kenaqshal.com/blog/things-you-need-to-know-about-local-storage-in-javascript">Things you need to know about local storage in JavaScript</a></li><li><a href="https://www.kenaqshal.com/blog/currency-formatting-on-javascript-es6">Currency formatting on JavaScript ES6</a></li><li><a href="https://www.kenaqshal.com/blog/race-condition-on-state-react-js">Race condition on state react.js</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24c9e091dc08" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>