<?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 Chandru K on Medium]]></title>
        <description><![CDATA[Stories by Chandru K on Medium]]></description>
        <link>https://medium.com/@chandru.mech.chn?source=rss-fe9ee15229ea------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*SNNAx8GLEJRc4ZeS</url>
            <title>Stories by Chandru K on Medium</title>
            <link>https://medium.com/@chandru.mech.chn?source=rss-fe9ee15229ea------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 18:26:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chandru.mech.chn/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[Commonly Used Sql Staments and Syntax]]></title>
            <link>https://medium.com/@chandru.mech.chn/commonly-used-sql-staments-and-syntax-a34a7ea7b3a2?source=rss-fe9ee15229ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/a34a7ea7b3a2</guid>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Chandru K]]></dc:creator>
            <pubDate>Thu, 14 Nov 2024 02:32:07 GMT</pubDate>
            <atom:updated>2024-11-14T02:32:35.107Z</atom:updated>
            <content:encoded><![CDATA[<h3>Commonly Used Sql Statements and Syntax</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*qhVY_SDT-TAEt2LKlwu7iQ.jpeg" /></figure><h3>SELECT : Retrieve Data</h3><p>Syntax:</p><pre>SELECT column1, column2, ...<br>FROM table_name<br>WHERE condition<br>ORDER BY column1 ASC|DESC<br>LIMIT number_of_rows;</pre><p>Example:</p><pre>SELECT firstName, lastName, email<br>FROM students<br>WHERE age &gt; 18<br>ORDER BY lastName DESC<br>LIMIT 10;</pre><h3>INSERT INTO - Insert Data</h3><h4>Syntax:</h4><pre>INSERT INTO table_name (column1, column2, ...)<br>VALUES (value1, value2, ...);</pre><p>Example:</p><pre>INSERT INTO students (firstName, lastName, age, email)<br>VALUES (&#39;John&#39;, &#39;Doe&#39;, 22, &#39;john.doe@example.com&#39;);</pre><h4><strong>UPDATE - Modify Existing Data</strong></h4><h4>Syntax:</h4><pre>UPDATE table_name<br>SET column1 = value1, column2 = value2, ...<br>WHERE condition;</pre><h4>Example:</h4><pre>UPDATE students<br>SET email = &#39;newemail@example.com&#39;<br>WHERE studentId = 101;</pre><h3>DELETE - Delete Data</h3><h4>Syntax:</h4><pre>DELETE FROM table_name<br>WHERE condition;</pre><h4>Example:</h4><pre>DELETE FROM students<br>WHERE age &lt; 18;</pre><h3>CREATE TABLE - Create a New Table</h3><h4>Syntax:</h4><pre>CREATE TABLE table_name (<br>  column1 datatype [constraint],<br>  column2 datatype [constraint],<br>  ...<br>);</pre><h4>Example:</h4><pre>CREATE TABLE students (<br>  studentId INT PRIMARY KEY,<br>  firstName VARCHAR(50),<br>  lastName VARCHAR(50),<br>  age INT,<br>  email VARCHAR(100)<br>);</pre><h3>6. ALTER TABLE - Modify an Existing Table</h3><h4>Add Column:</h4><pre>ALTER TABLE table_name<br>ADD column_name datatype;</pre><h4>Example:</h4><pre>ALTER TABLE students<br>ADD phoneNumber VARCHAR(15);</pre><h4>Drop Column:</h4><pre>ALTER TABLE table_name<br>DROP COLUMN column_name;</pre><h4>Example:</h4><pre>ALTER TABLE students<br>DROP COLUMN phoneNumber;</pre><h3>DROP TABLE - Delete a Table</h3><h4>Syntax:</h4><pre>DROP TABLE table_name;</pre><h4>Example:</h4><pre>DROP TABLE students;</pre><h3>JOIN - Combine Data from Multiple Tables</h3><p>INNER JOIN - Returns records that have matching values in both tables.</p><pre>SELECT columns<br>FROM table1<br>INNER JOIN table2<br>ON table1.column = table2.column;</pre><h4>Example:</h4><pre>SELECT students.firstName, students.lastName, courses.courseName<br>FROM students<br>INNER JOIN course_enrollments<br>ON students.studentId = course_enrollments.studentId<br>INNER JOIN courses<br>ON course_enrollments.courseId = courses.courseId;</pre><p>LEFT JOIN - Returns all records from the left table and matched records from the right table. If no match, NULL is returned for right table columns.</p><pre>SELECT columns<br>FROM table1<br>LEFT JOIN table2<br>ON table1.column = table2.column;</pre><h4>Example:</h4><pre>SELECT employees.name, departments.name<br>FROM employees<br>LEFT JOIN departments<br>ON employees.departmentId = departments.departmentId;</pre><p>RIGHT JOIN - Returns all records from the right table and matched records from the left table. If no match, NULL is returned for left table columns.</p><pre>SELECT columns<br>FROM table1<br>RIGHT JOIN table2<br>ON table1.column = table2.column;</pre><p>FULL OUTER JOIN - Returns all records when there is a match in either left or right table.</p><pre>SELECT columns<br>FROM table1<br>FULL OUTER JOIN table2<br>ON table1.column = table2.column;</pre><h3>GROUP BY - Group Rows that Have the Same Values</h3><h4>Syntax:</h4><pre>SELECT column, COUNT(*)<br>FROM table_name<br>GROUP BY column;</pre><h4>Example:</h4><pre>SELECT department, COUNT(*)<br>FROM employees<br>GROUP BY department;</pre><h3>HAVING - Filter Data After Grouping (Used with GROUP BY)</h3><h4>Syntax:</h4><pre>SELECT column, COUNT(*)<br>FROM table_name<br>GROUP BY column<br>HAVING COUNT(*) &gt; 5;</pre><h4>Example:</h4><pre>SELECT department, COUNT(*)<br>FROM employees<br>GROUP BY department<br>HAVING COUNT(*) &gt; 10;</pre><h3>ORDER BY - Sort Data</h3><h4>Syntax:</h4><pre>SELECT column1, column2, ...<br>FROM table_name<br>ORDER BY column1 [ASC|DESC], column2 [ASC|DESC];</pre><h4>Example:</h4><pre>SELECT firstName, lastName, age<br>FROM students<br>ORDER BY age DESC;</pre><h3>DISTINCT - Select Unique Values</h3><h4>Syntax:</h4><pre>SELECT DISTINCT column<br>FROM table_name;</pre><h4>Example:</h4><pre>SELECT DISTINCT city<br>FROM employees;</pre><h3>LIKE - Pattern Matching</h3><h4>Syntax:</h4><pre>SELECT column1, column2<br>FROM table_name<br>WHERE column1 LIKE pattern;</pre><h4>Example:</h4><pre>SELECT firstName, email<br>FROM students<br>WHERE email LIKE &#39;%@example.com&#39;;</pre><h3>IN - Match a Value Against a List of Values</h3><h4>Syntax:</h4><pre>SELECT column<br>FROM table_name<br>WHERE column IN (value1, value2, ...);</pre><h4>Example:</h4><pre>SELECT firstName, lastName<br>FROM students<br>WHERE department IN (&#39;Physics&#39;, &#39;Mathematics&#39;);</pre><h3>BETWEEN - Filter Results Within a Range</h3><h4>Syntax:</h4><pre>SELECT column<br>FROM table_name<br>WHERE column BETWEEN value1 AND value2;</pre><h4>Example:</h4><pre>SELECT firstName, lastName<br>FROM students<br>WHERE age BETWEEN 18 AND 25;</pre><h3>IS NULL / IS NOT NULL - Check for Null Values</h3><h4>Syntax:</h4><pre>SELECT column<br>FROM table_name<br>WHERE column IS NULL;</pre><h4>Example:</h4><pre>SELECT firstName, lastName<br>FROM students<br>WHERE email IS NULL;</pre><h3>LIMIT - Limit the Number of Records</h3><h4>Syntax</h4><pre>SELECT column1, column2<br>FROM table_name<br>LIMIT number_of_records;</pre><h4>Example:</h4><pre>SELECT firstName, lastName<br>FROM students<br>LIMIT 5;</pre><h3>ALTER TABLE - Modify a Table Structure</h3><p><strong>Rename Table</strong>:</p><pre>ALTER TABLE old_table_name<br>RENAME TO new_table_name;</pre><p><strong>Add Column</strong>:</p><pre>ALTER TABLE table_name<br>ADD column_name datatype;</pre><p><strong>Drop Column</strong>:</p><pre>ALTER TABLE table_name<br>DROP COLUMN column_name;</pre><h3>EXISTS - Check if a Subquery Returns Any Results</h3><h4>Syntax:</h4><pre>SELECT column<br>FROM table_name<br>WHERE EXISTS (SELECT column FROM another_table WHERE condition);</pre><h4>Example:</h4><pre>SELECT firstName, lastName<br>FROM students<br>WHERE EXISTS (<br>    SELECT studentId<br>    FROM course_enrollments<br>    WHERE studentId = students.studentId<br>);</pre><h3>UNION - Combine Results of Two Queries</h3><h4>Syntax:</h4><pre>SELECT column FROM table1<br>UNION<br>SELECT column FROM table2;</pre><h4>Example:</h4><pre>SELECT firstName FROM students<br>UNION<br>SELECT firstName FROM employees;</pre><h3>CASE - Conditional Logic in SQL</h3><h4>Syntax:</h4><pre>SELECT column,<br>       CASE<br>           WHEN condition THEN &#39;value1&#39;<br>           WHEN condition THEN &#39;value2&#39;<br>           ELSE &#39;default_value&#39;<br>       END AS alias_name<br>FROM table_name;</pre><h4>Example:</h4><pre>SELECT firstName, age,<br>       CASE<br>           WHEN age &lt; 18 THEN &#39;Minor&#39;<br>           ELSE &#39;Adult&#39;<br>       END AS age_group<br>FROM students;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a34a7ea7b3a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stored Procedures In Sql]]></title>
            <link>https://medium.com/@chandru.mech.chn/stored-procedures-in-sql-c10eb4a3bea6?source=rss-fe9ee15229ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/c10eb4a3bea6</guid>
            <category><![CDATA[sql-stored-procedure]]></category>
            <category><![CDATA[stored-procedure]]></category>
            <dc:creator><![CDATA[Chandru K]]></dc:creator>
            <pubDate>Fri, 16 Aug 2024 12:19:28 GMT</pubDate>
            <atom:updated>2024-08-16T13:10:33.174Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/348/1*t60mgeKS_FK7qdsii7L20g.png" /></figure><p>Stored procedures are a powerful feature in SQL Server (MSSQL) that allow you to encapsulate and manage SQL code efficiently. They offer a range of benefits including improved performance, enhanced security, and simplified maintenance. In this blog, we’ll explore what stored procedures are, how to create and use them, and provide examples to illustrate their effectiveness.</p><p><strong>What is a Stored Procedure?</strong></p><p>A stored procedure is a precompiled collection of one or more SQL statements that you can execute as a single unit. Stored procedures can include control-of-flow statements, variables, and complex logic, making them a versatile tool for database management.</p><p><strong>Benefits of Using Stored Procedures:</strong></p><ul><li><strong>Performance Improvement</strong>: Stored procedures are precompiled, which means SQL Server optimizes them for execution, reducing the overhead of query parsing and compilation.</li><li><strong>Security</strong>: You can grant users permissions to execute stored procedures without giving them direct access to the underlying tables.</li><li><strong>Code Reusability</strong>: You can write complex queries once and reuse them across multiple applications or modules.</li><li><strong>Maintenance</strong>: Modifying a stored procedure is often easier and less error-prone than updating individual queries scattered across an application.</li></ul><h4>Creating a Stored Procedure</h4><p>To create a stored procedure in SQL Server, you use the CREATE PROCEDURE statement. Let’s walk through an example where we create a stored procedure to insert employee records into an Employees table.</p><p><strong>Step 1: Define the Table</strong></p><p>First, ensure you have the Employees table created in your database:</p><pre>CREATE TABLE Employees (<br>    EmployeeId INT IDENTITY(1,1) PRIMARY KEY,<br>    firstName NVARCHAR(255),<br>    middleName NVARCHAR(255),<br>    lastName NVARCHAR(255),<br>    dob DATE,<br>    gender VARCHAR(50),<br>    createdAt DATETIMEOFFSET(7),<br>    updatedAt DATETIMEOFFSET(7)<br>);</pre><p><strong>Step 2: Create the Stored Procedure</strong></p><p>Now, let’s create a stored procedure named spCreateEmployee that inserts a new employee into the Employees table:</p><pre>USE [databaseName]<br>GO<br><br>-- Drop the procedure if it already exists<br>IF OBJECT_ID(&#39;dbo.spCreateEmployee&#39;, &#39;P&#39;) IS NOT NULL<br>    DROP PROCEDURE dbo.spCreateEmployee;<br>GO<br><br>-- Create the stored procedure<br>CREATE PROCEDURE [dbo].[SP_CreateEmployee]<br> @firstName varchar(20),<br> @lastName varchar(10),<br> @middleName varchar(5),<br> @dob date,<br> @gender varchar(10),<br> @createdAt datetimeoffset,<br> @updatedAt datetimeoffset,<br> @Action varchar(10),<br> @employeeId int null = null<br>AS<br>BEGIN<br>IF @Action = &#39;Add&#39;<br><br> BEGIN<br>    Insert Into Employees (firstName,lastName,middleName,dob,gender,createdAt,updatedAt)<br> values(@firstName,@lastName,@middleName,@dob,@gender,@createdAt,@updatedAt)<br><br>-- To Return the Data which we have created<br>SELECT * FROM dbo.Employees where [id] = SCOPE_IDENTITY();<br> END<br><br> ELSE IF @Action = &#39;Update&#39;<br> BEGIN<br> UPDATE Employees SET <br> firstName=@firstName,<br> lastName=@lastName,<br> dob=@dob,<br> gender=@gender<br> WHERE id= @employeeId<br><br>-- To return the updated data<br>SELECT * FROM dbo.Employees where [id] = @employeeId;<br> END<br><br>END</pre><h4>Using the Stored Procedure</h4><p>Once the stored procedure is created, you can call it to insert new records into the Employees table. Here’s how you can execute it using SQL Server Management Studio (SSMS), Here You can call same stored procedure for creating and updating by changing the Action from Add to Update and Pass the EmployeeId when Update Action to be Done.</p><pre>EXEC SP_CreateEmployee<br> @firstName=&#39;testing&#39;,<br> @lastName=&#39;user&#39;,<br> @middleName=&#39; &#39;,<br> @dob=&#39;1999/10/10&#39;,<br> @gender = &#39;Male&#39;,<br> @createdAt=&#39;2024-08-16T16:05:16.3484710+05:30&#39;,<br> @updatedAt=&#39;2024-08-16T16:05:16.3484710+05:30&#39;,<br> @Action =&#39;Add&#39;<br> --@employeeId =32</pre><h4>Integrating with Node.js</h4><p>You can also call stored procedures from a Node.js application using the mssql package. Here’s an example of how to call the spCreateEmployee stored procedure from Node.js:</p><p><strong>Create a Database Connection:</strong></p><pre>const sql = require(&#39;mssql&#39;);<br><br>const config = {<br>  user: &#39;your_username&#39;,<br>  password: &#39;your_password&#39;,<br>  server: &#39;localhost&#39;,<br>  database: &#39;testDatabase&#39;,<br>  options: {<br>    encrypt: true,<br>    trustServerCertificate: false<br>  }<br>};<br><br>async function getConnection() {<br>  try {<br>    const pool = await sql.connect(config);<br>    return pool;<br>  } catch (err) {<br>    console.error(&#39;Database connection error:&#39;, err);<br>    throw err;<br>  }<br>}</pre><p><strong>Call the Stored Procedure:</strong></p><pre>async function createEmployee(firstName, middleName, lastName, dob, gender, createdAt, updatedAt) {<br>  try {<br>    const pool = await getConnection();<br>    <br>    const result = await pool.request()<br>      .input(&#39;firstName&#39;, sql.NVarChar, firstName)<br>      .input(&#39;middleName&#39;, sql.NVarChar, middleName)<br>      .input(&#39;lastName&#39;, sql.NVarChar, lastName)<br>      .input(&#39;dob&#39;, sql.Date, dob)<br>      .input(&#39;gender&#39;, sql.VarChar, gender)<br>      .input(&#39;createdAt&#39;, sql.DateTimeOffset, createdAt)<br>      .input(&#39;updatedAt&#39;, sql.DateTimeOffset, updatedAt)<br>      .execute(&#39;dbo.spCreateEmployee&#39;);<br><br>    console.log(&#39;Employee created successfully:&#39;, result);<br>  } catch (err) {<br>    console.error(&#39;Error creating employee:&#39;, err);<br>  }<br>}<br><br>// Example usage<br>createEmployee(<br>  &#39;John&#39;, &#39;A&#39;, &#39;Doe&#39;, &#39;1985-06-15&#39;, &#39;Male&#39;,<br>  new Date().toISOString(), new Date().toISOString()<br>);</pre><h4>Conclusion</h4><p>Stored procedures are a crucial feature in SQL Server that enhance performance, security, and maintainability. They allow for efficient execution of complex SQL operations and can be easily integrated into various applications, including those built with Node.js. By encapsulating SQL logic into procedures, you can streamline your database operations and ensure consistency across your applications.</p><p>Whether you’re managing data for a small application or a large enterprise system, mastering stored procedures can greatly improve your database management and application performance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c10eb4a3bea6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git Commands for Beginners]]></title>
            <link>https://medium.com/@chandru.mech.chn/git-commands-for-beginners-6ca2206f1920?source=rss-fe9ee15229ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ca2206f1920</guid>
            <dc:creator><![CDATA[Chandru K]]></dc:creator>
            <pubDate>Fri, 02 Aug 2024 10:50:44 GMT</pubDate>
            <atom:updated>2024-08-02T10:50:44.201Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*Uuh75Yql_ZJhE1GvZ7Tz5g.png" /></figure><p>Okay, let’s talk about Git! Not the creepy crawly thing, but the amazing tool that saves a coder’s life.</p><p>If you’re new to the coding world, Git can seem to be a huge, twisted ball of string.</p><p>But don’t worry; it’s your new best buddy. Think of Git as a time machine for your code.</p><p>You can go back in time, correct troublesome errors, and work with other developers without losing your head.</p><p>It’s like having powers in your code! And trust me, you will thank yourself in the future for knowing this.</p><p>I’ll break down Git into easy-to-understand pieces, with enough of examples and interesting details to keep you engaged.</p><h4>Core Git Commands:</h4><ul><li><strong>Creating a new Git repository</strong></li></ul><pre>git init</pre><p>Consider this command to be like building up a comfortable little house for your code. You are basically saying to your computer, “Hey, I want to keep track of every change I make to this project.”</p><ul><li><strong>Cloning an existing repository</strong></li></ul><pre>git clone https://github.com/username/repo.git</pre><p>Want to get all of the code and history for your team’s project? Simply run git clone followed by the project’s site address. It’s like downloading a complete copy of everything onto your computer. Easy peasy!</p><h3>Basic Workflow</h3><ul><li><strong>Checking the repository status</strong></li></ul><pre>git status</pre><p>Feeling lost in your code jungle? Do not panic! git status is your trustworthy compass. It’ll offer you a clear view of what’s going on in your repository right now.</p><ul><li><strong>Staging changes for commit</strong></li></ul><pre>git add .</pre><p>Are you ready to save your progress? To stage changes, use git add. It&#39;s like saying, &quot;Hey Git, take a look at this!&quot;.</p><ul><li><strong>Committing changes to the local repository</strong></li></ul><pre>git commit -m &quot;Add awesome new feature&quot;</pre><p>Use git commit to seal the deal. It’s like starting a diary entry on what you did.</p><ul><li><strong>Viewing commit history</strong></li></ul><pre>git log</pre><p>Curious about history? git log shows the history of your commits. Time travel, anyone?</p><ul><li><strong>Comparing changes between commits or working directory</strong></li></ul><pre>git diff</pre><p>Want to see what’s changed? git diff is like a before-and-after comparison.</p><h3>Branching and Merging</h3><ul><li><strong>Creating, listing, and deleting branches</strong></li></ul><pre>git branch new-feature</pre><p>Branches are like alternate realities. Create one with git branch and explore new features without affecting the main timeline.</p><ul><li><strong>Switching between branches</strong></li></ul><pre>git checkout new-feature</pre><p>git checkout lets you move between branches.</p><ul><li><strong>Merging branches</strong></li></ul><pre>git merge new-feature</pre><p>Have you found the perfect feature? Use git merge to bring it back to the main timeline.</p><ul><li><strong>Rebase one branch onto another</strong></li></ul><pre>git rebase main</pre><p>Rebasing is like rearranging history. Use it to keep your commits clean and linear.</p><h3>Remote Repositories</h3><ul><li><strong>Managing remote repositories</strong></li></ul><pre>git remote add origin https://github.com/username/repo.git</pre><p>git remote connects your local repository to a remote one. It’s similar to linking your phone with the cloud.</p><ul><li><strong>Pushing changes to a remote repository</strong></li></ul><pre>git push origin main</pre><p>git push will send your commits to the remote repository. It’s similar to transferring your stuff to the cloud.</p><ul><li><strong>Fetching and merging changes from a remote repository</strong></li></ul><pre>git pull origin main</pre><p>Keep up to date using git pull. It’s like getting the newest updates from the cloud.</p><h3>Advanced Git Commands</h3><h3>Undoing Changes</h3><ul><li><strong>Undoing the last commit or unstaging change</strong>s</li></ul><pre>git reset --hard HEAD~1</pre><p>Made a mistake? git reset is like an undo button for your commits.</p><ul><li><strong>Reversing a commit without modifying history</strong></li></ul><pre>git revert &lt;commit_hash&gt;</pre><p>Need to go back without changing history? git revert is your buddy.</p><ul><li><strong>Discarding changes in the working directory</strong></li></ul><pre>git checkout -- &lt;file&gt;</pre><p>Regret that last change? Use git checkout -- to discard uncommitted changes.</p><h3>Finding and Fixing Issues</h3><ul><li>Showing who last modified a line of code</li></ul><pre>git blame &lt;file&gt;</pre><p>Pointing fingers? git blame shows who changed what and when.</p><ul><li><strong>Finding the commit that introduced a bug</strong></li></ul><pre>git bisect start</pre><p>Hunting a bug? git bisect helps you find the exact commit that caused it.</p><ul><li>Applying a single commit from one branch to another</li></ul><pre>git cherry-pick &lt;commit_hash&gt;</pre><p>Want a specific change? git cherry-pick lets you apply a commit from one branch to another.</p><h3>Collaboration and Workflow</h3><ul><li>Temporarily saving changes</li></ul><pre>git stash</pre><p>Need to switch tasks? git stash saves your changes temporarily.</p><ul><li>Creating and managing tags</li></ul><pre>git tag v1.0</pre><p>Mark important points in your project’s history with git tag.</p><ul><li>Including other Git repositories as submodules</li></ul><pre>git submodule add https://github.com/username/repo.git</pre><p>Managing a large project? Use git submodule to include other repositories.</p><h3>Best Practices and Tips</h3><h3>Importance of clear and descriptive commit messages</h3><p>Think of your commit messages as diary entries. Clear and descriptive messages make it easier to understand the history of your project.</p><h3>Using branches effectively for feature development and bug fixes</h3><p>Branches are your best friends for keeping new features and bug fixes separate from the main project.</p><h3>Keeping your repository clean and organized</h3><p>Regularly clear up old branches and use.Use gitignore to keep your repository clean.</p><h3>Resolving merge conflicts</h3><p>Don’t panic if you find a merge conflict. Review the changes made to figure out which ones to keep.</p><h3>Tips for most effective Git usage.</h3><ul><li><strong>Commit messages</strong>: Keep them short, however informative.</li><li><strong>Branching strategies</strong>: Choose a branching strategy that fits your workflow, such as Git Flow or GitHub Flow.</li><li><strong>Using tags and releases</strong>: Tag important milestones and build releases for versioned deployments.</li></ul><h3>Troubleshooting</h3><h3>Common challenges along with solutions</h3><p>Got stuck? Here are two common Git issues and approaches to resolve them:</p><ul><li><strong>Merge conflicts</strong>: Resolve conflicts manually and then commit.</li><li><strong>Detached HEAD</strong>: Reattach with git checkout main.</li></ul><h3>Useful Git commands for troubleshooting</h3><ul><li>git log: View the commit history.</li><li>git diff: Compare the changes made.</li><li>git bisect: Find the commit that created the bug.</li></ul><h3>Final Words</h3><p>So there you have it! Git might seem scary at first, but with these basic commands and a little experience, you’ll be managing your projects like a pro.</p><p>Remember that Git is here to make your life simpler, so use its power and let it help you become an even better web developer.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ca2206f1920" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sequelize Associations & Magic Methods]]></title>
            <link>https://medium.com/@chandru.mech.chn/sequelize-associations-magic-methods-43a053dee99e?source=rss-fe9ee15229ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/43a053dee99e</guid>
            <category><![CDATA[sequelize]]></category>
            <dc:creator><![CDATA[Chandru K]]></dc:creator>
            <pubDate>Fri, 02 Aug 2024 10:19:09 GMT</pubDate>
            <atom:updated>2024-08-02T10:19:09.724Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O1_Ce63LFM_UgRtFfw53RQ.png" /></figure><h3><strong>Objective:</strong></h3><p>The objective of this article is to provide more understandable (visual) documentation on Sequelize associations and magic methods.</p><p>When implementing a backend database, Sequelize is a powerful and effective object relational mapping (ORM) platform. Some of its capabilities, however, are obscured by pages of deterring and dense documentation. When I was first learning Sequelize, I struggled to understand model associations and their respective “magic methods”.</p><h4>Associations &amp; Magic Methods:</h4><p>An association in Sequelize is a relationship between two models (a source and target model). Creating an association generally involves adding a foreign key to one model which creates a reference to the other. There are several Sequelize associations, including <em>has one</em>,<em> belongsTo</em>,<em> hasMany</em>, and <em>belongsToMany. </em>In terms of implementation, the key difference between these associations is in which model (the source or the target) the foreign key resides. I’ve made a series of visualization tools (see below) to help differentiate between these associations.</p><p>“Magic methods” are simply methods that are generated by defining Sequelize associations. As their name implies, the capabilities they invoke are quite magical. The visualizations below also outline which magic methods a given association will create. Alternatively, another way to easily see what magic methods a model has access to, is to use:</p><pre>Object.keys(ModelName.prototype)</pre><h4>Base Models:</h4><p>For the purpose of this demonstration, I will begin with two base models — a parent and a child model. The tables below show how the 4 Sequelize associations mentioned above affect these base models, and what magic methods are created as a result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*vXVd0sPhzTZbiJOFXuPenA.png" /></figure><h4>One-To-One:</h4><p><em>One-to-one associations are between exactly two models connected by a single foreign key.</em></p><h4>Belongs To:</h4><p>Associations where the foreign key exists on the<strong> source model.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XAcsD3I-hJHwq1M2IErzsw.png" /></figure><h4>Has One:</h4><p>Associations where the foreign key exists on the<strong> target model</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wovfAzxAkDAGoXBWEX4CIQ.png" /></figure><h4>One-To-Many:</h4><p>One-to-Many associations connect one source with multiple targets. The targets however, are connected to exactly one specific source.</p><h4>Has Many</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sk3JrwFU8V3j1NtEuCRCcw.png" /></figure><h4>Many-To-Many</h4><p>Many-to-Many associations connect one source with many targets. The targets can also be connected to many sources.</p><h4>Belongs To Many</h4><p>Unlike the 3 previous associations, belongsToMany associations create a new joint table with the foreign keys of the target and source models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YeFp9pSq0xcPOErgq4HTVA.png" /></figure><h4>Conclusion</h4><p>I hope these visualizations clarify the distinct differences between Sequelize associations and their corresponding magic methods. Once you understand these differences, Sequelize is extremely powerful in establishing relational databases and querying data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43a053dee99e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Big O Notation]]></title>
            <link>https://medium.com/@chandru.mech.chn/understanding-big-o-notation-81a27e3295b8?source=rss-fe9ee15229ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/81a27e3295b8</guid>
            <category><![CDATA[big-o-notation]]></category>
            <dc:creator><![CDATA[Chandru K]]></dc:creator>
            <pubDate>Tue, 28 May 2024 11:15:54 GMT</pubDate>
            <atom:updated>2024-05-28T11:15:54.264Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Big-O-Notation" src="https://cdn-images-1.medium.com/max/279/1*jlxpkJyKVWrMP4MSuwOroQ.png" /></figure><p>Big O notation expresses the upper bound of an algorithm’s running time. It provides a high-level understanding of the algorithm’s efficiency in terms of time (<strong>time complexity</strong>) or space (<strong>space complexity</strong>).</p><ul><li>Big O notation helps analyze the efficiency of algorithms by describing how their runtime or space requirements grow as the input size increases.</li><li>It allows programmers to compare different algorithms and choose the most efficient one for a specific problem.</li><li>Understanding Big O helps predict how algorithms will perform as the input size grows.</li></ul><p><strong>Common Big O Notations:</strong></p><ul><li>O(1) — Constant Time</li><li>O(log n) — Logarithmic Time</li><li>O(n) — Linear Time</li><li>O(n log n) — Linearithmic Time</li><li>O(n²) — Quadratic Time</li><li>O(2^n) — Exponential Time</li><li>O(n!) — Factorial Time</li></ul><p><strong>Examples of Big O Notations:</strong></p><h4>1. O(1) — Constant Time</h4><p>An algorithm is O(1) if its running time does not change with the size of the input.</p><p><strong>Example:</strong> Accessing an element in an array by index.</p><pre>function getElement(array, index) {<br>    return array[index];<br>}</pre><h4>2. O(log n) — Logarithmic Time</h4><p>An algorithm is O(log n) if its running time grows logarithmically with the input size.</p><p><strong>Example:</strong> Binary search in a sorted array.</p><pre>function binarySearch(array, target) {<br>    let left = 0;<br>    let right = array.length - 1;<br>    <br>    while (left &lt;= right) {<br>        let mid = Math.floor((left + right) / 2);<br>        <br>        if (array[mid] === target) {<br>            return mid;<br>        } else if (array[mid] &lt; target) {<br>            left = mid + 1;<br>        } else {<br>            right = mid - 1;<br>        }<br>    }<br>    <br>    return -1; // Target not found<br>}</pre><h4>3. O(n) — Linear Time</h4><p>An algorithm is O(n) if its running time grows linearly with the input size.</p><p><strong>Example:</strong> Finding the maximum element in an array.</p><pre>function findMax(array) {<br>    let max = array[0];<br>    <br>    for (let i = 1; i &lt; array.length; i++) {<br>        if (array[i] &gt; max) {<br>            max = array[i];<br>        }<br>    }<br>    <br>    return max;<br>}</pre><h4>4. O(n log n) — Linearithmic Time</h4><p>An algorithm is O(n log n) if its running time grows in proportion to n log n.</p><p><strong>Example:</strong> Merge sort algorithm.</p><pre>function mergeSort(array) {<br>    if (array.length &lt;= 1) {<br>        return array;<br>    }<br>    <br>    const mid = Math.floor(array.length / 2);<br>    const left = array.slice(0, mid);<br>    const right = array.slice(mid);<br>    <br>    return merge(mergeSort(left), mergeSort(right));<br>}<br><br>function merge(left, right) {<br>    let result = [];<br>    let leftIndex = 0;<br>    let rightIndex = 0;<br>    <br>    while (leftIndex &lt; left.length &amp;&amp; rightIndex &lt; right.length) {<br>        if (left[leftIndex] &lt; right[rightIndex]) {<br>            result.push(left[leftIndex]);<br>            leftIndex++;<br>        } else {<br>            result.push(right[rightIndex]);<br>            rightIndex++;<br>        }<br>    }<br>    <br>    return result.concat(left.slice(leftIndex)).concat(right.slice(rightIndex));<br>}</pre><h4>5. O(n²) — Quadratic Time</h4><p>An algorithm is O(n²) if its running time grows quadratically with the input size.</p><p><strong>Example:</strong> Bubble sort algorithm.</p><pre>function bubbleSort(array) {<br>    let n = array.length;<br>    <br>    for (let i = 0; i &lt; n - 1; i++) {<br>        for (let j = 0; j &lt; n - 1 - i; j++) {<br>            if (array[j] &gt; array[j + 1]) {<br>                [array[j], array[j + 1]] = [array[j + 1], array[j]]; // Swap elements<br>            }<br>        }<br>    }<br>    <br>    return array;<br>}</pre><h4>6. O(2^n) — Exponential Time</h4><p>An algorithm is O(2^n) if its running time grows exponentially with the input size.</p><p><strong>Example:</strong> Calculating the nth Fibonacci number using a naive recursive approach.</p><pre>function fibonacci(n) {<br>    if (n &lt;= 1) {<br>        return n;<br>    }<br>    return fibonacci(n - 1) + fibonacci(n - 2);<br>}</pre><h4>7. O(n!) — Factorial Time</h4><p>An algorithm is O(n!) if its running time grows factorially with the input size.</p><p><strong>Example:</strong> Generating all permutations of a string.</p><pre>function permute(str) {<br>    if (str.length &lt;= 1) {<br>        return [str];<br>    }<br>    <br>    let permutations = [];<br>    for (let i = 0; i &lt; str.length; i++) {<br>        let char = str[i];<br>        let remainingChars = str.slice(0, i) + str.slice(i + 1);<br>        let remainingPerms = permute(remainingChars);<br>        <br>        for (let perm of remainingPerms) {<br>            permutations.push(char + perm);<br>        }<br>    }<br>    <br>    return permutations;<br>}</pre><h3>Conclusion:</h3><p>Understanding Big O notation is crucial for analyzing and comparing the efficiency of algorithms. By grasping the concepts and examples provided, developers can make informed decisions to optimize their code and improve performance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81a27e3295b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>