<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Muhammad Muneeb Ur Rehman</title>
    <description>The latest articles on DEV Community by Muhammad Muneeb Ur Rehman (@muneebkhan4).</description>
    <link>https://dev.to/muneebkhan4</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1016213%2F82318760-d7ac-4b08-b551-61954b1ac5ff.jpeg</url>
      <title>DEV Community: Muhammad Muneeb Ur Rehman</title>
      <link>https://dev.to/muneebkhan4</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/muneebkhan4"/>
    <language>en</language>
    <item>
      <title>Demystifying Custom Hooks in React: What, When, and How</title>
      <dc:creator>Muhammad Muneeb Ur Rehman</dc:creator>
      <pubDate>Wed, 20 Aug 2025 12:47:20 +0000</pubDate>
      <link>https://dev.to/muneebkhan4/demystifying-custom-hooks-in-react-what-why-and-how-58kl</link>
      <guid>https://dev.to/muneebkhan4/demystifying-custom-hooks-in-react-what-why-and-how-58kl</guid>
      <description>&lt;p&gt;React hooks have completely changed the way we write components. They allow us to handle state, side effects, and context in a cleaner, more functional way. But sometimes, we find ourselves writing the same hook logic again and again. That’s where custom hooks come to the rescue.&lt;/p&gt;

&lt;p&gt;In this article, we’ll explore:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What custom hooks are&lt;/li&gt;
&lt;li&gt;When to use them&lt;/li&gt;
&lt;li&gt;How to create and use them with real-world examples&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What are Custom Hooks?
&lt;/h2&gt;

&lt;p&gt;A custom hook is simply a JavaScript function whose name starts with &lt;code&gt;use&lt;/code&gt; and that can use other hooks inside it (&lt;code&gt;useState&lt;/code&gt;, &lt;code&gt;useEffect&lt;/code&gt;, &lt;code&gt;useContext&lt;/code&gt;, etc.).&lt;/p&gt;

&lt;p&gt;They allow us to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Extract reusable logic from components&lt;/li&gt;
&lt;li&gt;Keep your components clean and focused&lt;/li&gt;
&lt;li&gt;Share logic between different components without duplicating code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of them as small utilities that encapsulate hook-related logic and can be plugged into any component.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to Use Custom Hooks
&lt;/h2&gt;

&lt;p&gt;You should consider creating a custom hook when:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reusing logic:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If multiple components need the same piece of logic (e.g., fetching data, handling form inputs).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Improving readability:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Components should mainly focus on UI, not business logic. Moving logic to hooks makes code more readable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Separation of concerns&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Keeps logic modular and testable, just like splitting functions in regular JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Create a Custom Hook
&lt;/h2&gt;

&lt;p&gt;Let’s start with a real-world scenario: fetching data from an API.&lt;br&gt;
Normally, we’d write the fetching logic inside a component with &lt;code&gt;useEffect&lt;/code&gt;. But if multiple components need to fetch data, we’ll end up repeating the same code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1: A Custom Hook for Fetching Data&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState, useEffect } from "react";

// Custom Hook
export function useFetch(url) {
  const [data, setData] = useState(null);
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState(null);

  useEffect(() =&amp;gt; {
    let isMounted = true;

    async function fetchData() {
      try {
        const response = await fetch(url);
        if (!response.ok) throw new Error("Failed to fetch");
        const result = await response.json();
        if (isMounted) {
          setData(result);
          setError(null);
        }
      } catch (err) {
        if (isMounted) setError(err.message);
      } finally {
        if (isMounted) setLoading(false);
      }
    }

    fetchData();

    return () =&amp;gt; { isMounted = false; };
  }, [url]);

  return { data, loading, error };
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Using it in a Component&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function UsersList() {
  const { data: users, loading, error } = useFetch("https://jsonplaceholder.typicode.com/users");

  if (loading) return &amp;lt;p&amp;gt;Loading users...&amp;lt;/p&amp;gt;;
  if (error) return &amp;lt;p&amp;gt;Error: {error}&amp;lt;/p&amp;gt;;

  return (
    &amp;lt;ul&amp;gt;
      {users.map(user =&amp;gt; (
        &amp;lt;li key={user.id}&amp;gt;{user.name}&amp;lt;/li&amp;gt;
      ))}
    &amp;lt;/ul&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;Now, whenever we need to fetch data in another component, we just call &lt;code&gt;useFetch(url)&lt;/code&gt; instead of rewriting the same code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2: A Custom Hook for Form Handling&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Forms are everywhere, and handling form state can get repetitive. Let’s create a reusable hook to manage form inputs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from "react";

export function useForm(initialValues) {
  const [values, setValues] = useState(initialValues);

  const handleChange = (e) =&amp;gt; {
    const { name, value } = e.target;
    setValues({
      ...values,
      [name]: value,
    });
  };

  const resetForm = () =&amp;gt; setValues(initialValues);

  return { values, handleChange, resetForm };
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Using it in a Login Form&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function LoginForm() {
  const { values, handleChange, resetForm } = useForm({ email: "", password: "" });

  const handleSubmit = (e) =&amp;gt; {
    e.preventDefault();
    console.log("Submitted:", values);
    resetForm();
  };

  return (
    &amp;lt;form onSubmit={handleSubmit}&amp;gt;
      &amp;lt;input
        type="email"
        name="email"
        value={values.email}
        onChange={handleChange}
        placeholder="Email"
      /&amp;gt;
      &amp;lt;input
        type="password"
        name="password"
        value={values.password}
        onChange={handleChange}
        placeholder="Password"
      /&amp;gt;
      &amp;lt;button type="submit"&amp;gt;Login&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Any new form (signup, profile update, contact form) can now reuse this same &lt;code&gt;useForm&lt;/code&gt; hook.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Custom hooks let you encapsulate logic and reuse it across components.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They make your code cleaner, modular, and easier to maintain.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use them for tasks like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fetching data&lt;/li&gt;
&lt;li&gt;Form handling&lt;/li&gt;
&lt;li&gt;Authentication checks&lt;/li&gt;
&lt;li&gt;Managing browser events (scroll, resize, etc.)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ending Notes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Custom hooks are not some advanced React trick they’re just functions. But when used wisely, they can dramatically improve your code quality and development speed.&lt;/p&gt;

&lt;p&gt;Next time you find yourself copy-pasting hook logic, stop and think:&lt;br&gt;
“Can I move this into a custom hook?”&lt;/p&gt;

&lt;p&gt;Chances are, the answer is yes and your future self will thank you.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>programming</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Understanding React's useContext Hook: A Complete Guide</title>
      <dc:creator>Muhammad Muneeb Ur Rehman</dc:creator>
      <pubDate>Sun, 03 Aug 2025 14:26:03 +0000</pubDate>
      <link>https://dev.to/muneebkhan4/understanding-reacts-usecontext-hook-a-complete-guide-1540</link>
      <guid>https://dev.to/muneebkhan4/understanding-reacts-usecontext-hook-a-complete-guide-1540</guid>
      <description>&lt;p&gt;The &lt;code&gt;useContext&lt;/code&gt; hook in React is a powerful way to share state between components without manually passing props through every level of the component tree. It makes your code cleaner, more maintainable, and is a key part of building scalable React applications.&lt;/p&gt;

&lt;p&gt;In this article, we will explore:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What &lt;code&gt;useContext&lt;/code&gt; is&lt;/li&gt;
&lt;li&gt;How it works under the hood&lt;/li&gt;
&lt;li&gt;Realistic code examples&lt;/li&gt;
&lt;li&gt;Best practices and pitfalls&lt;/li&gt;
&lt;li&gt;A visual diagram to understand its flow&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;1. What is &lt;code&gt;useContext&lt;/code&gt;?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In React, data is typically passed from parent to child via props. But when your app grows, passing props through multiple levels (also known as prop drilling) becomes cumbersome.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;useContext&lt;/code&gt; allows you to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a Context (a shared data store)&lt;/li&gt;
&lt;li&gt;Provide that context to a part of your component tree&lt;/li&gt;
&lt;li&gt;Access that data directly from any nested component without manually passing props&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of it as a global state for a section of your component tree.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. How &lt;code&gt;useContext&lt;/code&gt; Works&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a Context using &lt;code&gt;React.createContext()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Wrap your components with a Provider that supplies the data.&lt;/li&gt;
&lt;li&gt;Consume the context in any child component using &lt;code&gt;useContext&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Here’s a simple example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { createContext, useContext, useState } from 'react';

// 1. Create Context
const ThemeContext = createContext();

function App() {
  const [theme, setTheme] = useState('light');

  return (
    // 2. Provide Context
    &amp;lt;ThemeContext.Provider value={{ theme, setTheme }}&amp;gt;
      &amp;lt;Toolbar /&amp;gt;
    &amp;lt;/ThemeContext.Provider&amp;gt;
  );
}

function Toolbar() {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;ThemedButton /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

function ThemedButton() {
  // 3. Consume Context
  const { theme, setTheme } = useContext(ThemeContext);

  return (
    &amp;lt;button
      style={{ background: theme === 'light' ? '#fff' : '#333', color: theme === 'light' ? '#000' : '#fff' }}
      onClick={() =&amp;gt; setTheme(theme === 'light' ? 'dark' : 'light')}
    &amp;gt;
      Current Theme: {theme}
    &amp;lt;/button&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What happens here?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The App component provides a theme value to all nested components.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ThemedButton&lt;/code&gt; can access &lt;code&gt;theme&lt;/code&gt;and &lt;code&gt;setTheme&lt;/code&gt; directly, without prop drilling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Interactive Example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine you have multiple buttons across different components that need to know the current theme. Without context, you would pass the theme through every component, even if they don’t use it.&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;useContext&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The state is centralized.&lt;/li&gt;
&lt;li&gt;Any component in the tree can read and update the theme instantly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. Best Practices&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use Context for Global State that Changes Infrequently&lt;/li&gt;
&lt;li&gt;Themes, authenticated user info, language settings&lt;/li&gt;
&lt;li&gt;Avoid Overusing Context&lt;/li&gt;
&lt;li&gt;For high-frequency updates (like mouse positions), context can trigger unnecessary re-renders&lt;/li&gt;
&lt;li&gt;Combine with &lt;code&gt;useReducer&lt;/code&gt; for Complex State&lt;/li&gt;
&lt;li&gt;Create a Context + Reducer for global state management like Redux-lite&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;5. Visual Diagram of useContext Flow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Below is a visual representation of how useContext works:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Context Provider wraps the components.&lt;/li&gt;
&lt;li&gt;Context Consumers (via useContext) read the data directly.&lt;/li&gt;
&lt;li&gt;Updates in the provider immediately propagate to all consumers.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ Context Provider ]
        |
        | provides value
        v
+-------------------+
|  Child Component  |
|   useContext()    |
+-------------------+
        |
        | accesses context
        v
   No Prop Drilling!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;With &lt;code&gt;useContext&lt;/code&gt;, your React applications become cleaner, more maintainable, and easier to scale. Combine it with hooks like &lt;code&gt;useReducer&lt;/code&gt; for a lightweight global state management solution.&lt;/p&gt;

</description>
      <category>react</category>
      <category>usecontexthook</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Building a Highly Scalable Ride-Sharing System Architecture</title>
      <dc:creator>Muhammad Muneeb Ur Rehman</dc:creator>
      <pubDate>Sun, 03 Aug 2025 14:01:40 +0000</pubDate>
      <link>https://dev.to/muneebkhan4/building-a-highly-scalable-ride-sharing-system-architecture-1pic</link>
      <guid>https://dev.to/muneebkhan4/building-a-highly-scalable-ride-sharing-system-architecture-1pic</guid>
      <description>&lt;p&gt;Building a ride-sharing platform that can handle millions of users in real-time requires thoughtful system design, distributed computing expertise, and robust cloud infrastructure. Below is a comprehensive guide on how to architect a scalable system for ride-hailing applications like Uber or Lyft.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Overview of System Requirements
&lt;/h2&gt;

&lt;p&gt;Ride-sharing systems must:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Handle millions of concurrent rider and driver requests&lt;/li&gt;
&lt;li&gt;Provide real-time geolocation updates&lt;/li&gt;
&lt;li&gt;Ensure high availability and low latency&lt;/li&gt;
&lt;li&gt;Scale seamlessly across regions&lt;/li&gt;
&lt;li&gt;Integrate with multiple external services (maps, payments, notifications)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To meet these demands, the system is typically designed as a set of distributed microservices communicating asynchronously.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Core Architecture Components
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Client Applications&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Rider App (iOS/Android): Requests rides, tracks driver locations, receives trip and payment updates.&lt;/p&gt;

&lt;p&gt;Driver App (iOS/Android): Receives ride requests, updates location in real-time, handles navigation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. API Gateway &amp;amp; Load Balancer&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Entry point for all requests.&lt;/li&gt;
&lt;li&gt;Handles routing, authentication, and rate-limiting.&lt;/li&gt;
&lt;li&gt;Distributes load across microservices for fault tolerance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Core Microservices&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User Service – Manages rider and driver profiles, sessions, and authentication.&lt;/li&gt;
&lt;li&gt;Ride Matching Service – Matches riders with nearby drivers using real-time geolocation.&lt;/li&gt;
&lt;li&gt;Geolocation Service – Continuously tracks positions using high-speed, in-memory databases like Redis.&lt;/li&gt;
&lt;li&gt;Pricing &amp;amp; Surge Service – Dynamically calculates fares and surge pricing.&lt;/li&gt;
&lt;li&gt;Trip Service – Manages the ride lifecycle (requested → accepted → completed).&lt;/li&gt;
&lt;li&gt;Payment &amp;amp; Billing Service – Handles ride payments, refunds, and payouts.&lt;/li&gt;
&lt;li&gt;Notification Service – Sends push notifications and in-app updates in real-time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. Event Bus / Message Queue&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Kafka, Pulsar, or AWS SQS for event-driven communication.&lt;/li&gt;
&lt;li&gt;Decouples microservices and allows horizontal scaling.&lt;/li&gt;
&lt;li&gt;Key events: ride_requested, driver_location_updated, trip_completed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;5. Databases and Storage&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Operational Databases:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PostgreSQL/MySQL for user profiles.&lt;/li&gt;
&lt;li&gt;MongoDB/Cassandra for trip data with high write throughput.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cache Layer:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Redis / Memcached for fast lookups of active trips and driver availability.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Analytics &amp;amp; Data Warehouse:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;BigQuery or Snowflake for analytics, reporting, and ML pipelines.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;6. External Integrations&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Maps &amp;amp; Routing APIs (Google Maps, Mapbox)&lt;/li&gt;
&lt;li&gt;Payment Gateways (Stripe, PayPal, Adyen)&lt;/li&gt;
&lt;li&gt;Push Notifications (Firebase, OneSignal)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;7. Monitoring &amp;amp; Observability&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Centralized Logging: ELK Stack or Datadog&lt;/li&gt;
&lt;li&gt;Metrics &amp;amp; Tracing: Prometheus, Grafana, OpenTelemetry&lt;/li&gt;
&lt;li&gt;Kubernetes auto-scaling and health checks&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. High-Level Data Flow
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Ride Request: Rider sends a ride request → API Gateway → Ride Matching Service.&lt;/li&gt;
&lt;li&gt;Driver Matching: Ride Matching queries Geolocation Service for nearby drivers.&lt;/li&gt;
&lt;li&gt;Fare Calculation: Pricing Service determines the dynamic fare.&lt;/li&gt;
&lt;li&gt;Driver Notification: Closest driver is notified via Notification Service.&lt;/li&gt;
&lt;li&gt;Trip Lifecycle: Driver accepts → Trip Service updates trip status → Event Bus streams updates.&lt;/li&gt;
&lt;li&gt;Real-Time Updates: Geolocation Service tracks driver movements and provides ETA updates.&lt;/li&gt;
&lt;li&gt;Payment &amp;amp; Completion: Payment Service charges rider and schedules driver payout.&lt;/li&gt;
&lt;li&gt;Analytics &amp;amp; ML: All events are logged to the Event Bus and Data Warehouse for insights.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. Example Architecture Diagram
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Text Representation&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  [ Rider App ]         [ Driver App ]
              |                    |
              +--------API Gateway &amp;amp; LB--------+
                                |
   +------------+----------------+----------------+-------------+
   |            |                |                |             |
[User]    [Ride Matching]   [Trip Service]   [Payment]   [Notification]
   |            |                |                |             |
   |      [Geolocation] &amp;lt;--------+                |             |
   |            |                                 |             |
   +-----[Event Bus / Queue]----------------------+-------------+
                     |
        +------------------------------+
        |        Databases &amp;amp; Cache      |
        | (SQL, NoSQL, Redis, Data Lake)|
        +------------------------------+
                     |
              [Analytics &amp;amp; ML]

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Visual Diagram&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxq3fkeuxn64zj68rxdz8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxq3fkeuxn64zj68rxdz8.png" alt="Visual diagram of system architecture" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Key Design Principles for Scalability
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Microservices and Decoupling – Isolate responsibilities to scale services independently.&lt;/li&gt;
&lt;li&gt;Event-Driven Architecture – Use message queues for asynchronous, fault-tolerant workflows.&lt;/li&gt;
&lt;li&gt;Caching and In-Memory Datastores – Reduce latency for hot data like driver locations.&lt;/li&gt;
&lt;li&gt;Global Load Balancing – Ensure availability across regions and automatically failover.&lt;/li&gt;
&lt;li&gt;Observability and Auto-Scaling – Continuous monitoring with Kubernetes scaling policies.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By following these principles and leveraging a modern cloud-native stack, your ride-sharing system can scale globally, handle sudden traffic spikes, and maintain a smooth, low-latency user experience.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>softwaredevelopment</category>
      <category>softwareengineering</category>
      <category>design</category>
    </item>
    <item>
      <title>Medical Disease Information Retrieval System: Code Documentation and Implementation Guide</title>
      <dc:creator>Muhammad Muneeb Ur Rehman</dc:creator>
      <pubDate>Sat, 20 May 2023 19:44:56 +0000</pubDate>
      <link>https://dev.to/muneebkhan4/medical-disease-information-retrieval-system-code-documentation-and-implementation-guide-3620</link>
      <guid>https://dev.to/muneebkhan4/medical-disease-information-retrieval-system-code-documentation-and-implementation-guide-3620</guid>
      <description>&lt;p&gt;The Medical Disease Information Retrieval System is a Python program designed to retrieve disease information based on user queries. This document serves as a comprehensive guide to understanding the code and implementing the system effectively. The system utilizes &lt;strong&gt;Natural Language Processing (NLP)&lt;/strong&gt; techniques, such as &lt;strong&gt;text preprocessing&lt;/strong&gt; and &lt;strong&gt;TF-IDF&lt;/strong&gt; vectorization, to calculate the &lt;strong&gt;cosine similarity&lt;/strong&gt; between user queries and a collection of disease-related documents.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Overview:&lt;/strong&gt;&lt;br&gt;
The code is divided into several sections, each responsible for a specific task. Let's explore each section in detail:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Importing Required Libraries:&lt;/strong&gt;&lt;br&gt;
The initial lines of code import the necessary libraries, including os for file handling, nltk for natural language processing, and sklearn for the TF-IDF vectorization.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import os
import nltk
from nltk.corpus import stopwords
from nltk.stem import SnowballStemmer
from sklearn.feature_extraction.text import TfidfVectorizer

# nltk.download('stopwords')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Preprocessing the Dataset:&lt;/strong&gt;&lt;br&gt;
The code reads text files from the 'Data Set' folder and preprocesses the documents. It removes stopwords, stems the words using the SnowballStemmer, and creates a preprocessed document corpus.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# set up stop words and stemmer
stop_words = set(stopwords.words('english'))
stemmer = SnowballStemmer('english')

# read all txt files from Data Set folder
folder_path = 'Data Set'
docs = []
for filename in os.listdir(folder_path):
    file_path = os.path.join(folder_path, filename)
    with open(file_path, 'r') as file:
        doc = file.read()
        docs.append(doc)

# pre-process the documents
preprocessed_docs = []
for doc in docs:
    preprocessed_doc = []
    for line in doc.split('\n'):
        if ':' in line:
            line = line.split(':')[1].strip()
        words = line.split()
        words = [word for word in words if word.lower() not in stop_words]
        words = [stemmer.stem(word) for word in words]
        preprocessed_doc.extend(words)
    preprocessed_doc = ' '.join(preprocessed_doc)
    preprocessed_docs.append(preprocessed_doc)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Generating the TF-IDF Matrix:&lt;/strong&gt;&lt;br&gt;
Using the preprocessed document corpus, the code employs the TfidfVectorizer from sklearn to generate a TF-IDF matrix. This matrix represents the importance of terms in each document.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# generate tf-idf matrix of the terms
vectorizer = TfidfVectorizer()
tfidf_matrix = vectorizer.fit_transform(preprocessed_docs)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;User Query Processing:&lt;/strong&gt;&lt;br&gt;
The code prompts the user to enter a query and preprocesses it by removing stopwords and stemming the words. This processed query is then used to calculate the cosine similarity between the query and each document.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;query = ''
while (query != 'quit'):
    # prompt the user to enter a query
    query = input('\nEnter your query: ')

    # pre-process the query
    preprocessed_query = []
    for word in query.split():
        if word.lower() not in stop_words:
            word = stemmer.stem(word)
            preprocessed_query.append(word)
    preprocessed_query = ' '.join(preprocessed_query)

    # calculate the cosine similarity between the query and each document
    cosine_similarities = tfidf_matrix.dot(
        vectorizer.transform([preprocessed_query]).T).toarray().flatten()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Retrieving Disease Information:&lt;/strong&gt;&lt;br&gt;
Based on the cosine similarity scores, the code identifies the most similar document and extracts disease-related information such as name, prevalence, risk factors, symptoms, treatments, and preventive measures.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    # find the index of the most similar document
    most_similar_doc_index = cosine_similarities.argsort()[::-1][0]

    # retrieve the disease information from the most similar document
    most_similar_doc = docs[most_similar_doc_index]
    disease_name = ''
    prevalence = ''
    risk_factors = ''
    symptoms = ''
    treatments = ''
    preventive_measures = ''

    for line in most_similar_doc.split('\n'):
        if line.startswith('Disease Name:'):
            disease_name = line.split(':')[1].strip()
        elif line.startswith('Prevalence:'):
            prevalence = line.split(':')[1].strip()
        elif line.startswith('Risk Factors:'):
            risk_factors = line.split(':')[1].strip()
        elif line.startswith('Symptoms:'):
            symptoms = line.split(':')[1].strip()
        elif line.startswith('Treatments:'):
            treatments = line.split(':')[1].strip()
        elif line.startswith('Preventive Measures:'):
            preventive_measures = line.split(':')[1].strip()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Displaying the Disease Information:&lt;/strong&gt;&lt;br&gt;
Finally, the code prints the retrieved disease information for the most similar document to the user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    # print the disease information
    print(f"\nDisease Name: {disease_name}\n")
    print(f"Prevalence: {prevalence}\n")
    print(f"Risk Factors: {risk_factors}\n")
    print(f"Symptoms: {symptoms}\n")
    print(f"Treatments: {treatments}\n")
    print(f"Preventive Measures: {preventive_measures}\n\n")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Implementation and Usage:&lt;/strong&gt;&lt;br&gt;
To implement and use the Disease Information Retrieval System, follow these steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data Preparation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a &lt;strong&gt;Data Set&lt;/strong&gt; folder and place text files containing disease information in this folder.&lt;br&gt;
Ensure the text files follow a specific format, such as starting each section with specific labels like 'Disease Name:', 'Prevalence:', etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install Required Libraries:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Install the required libraries by running &lt;code&gt;pip install nltk scikit-learn&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Preprocessing and TF-IDF Matrix Generation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Run the provided code, ensuring that the NLTK stopwords package is downloaded (uncomment the nltk.download('stopwords') line if necessary).&lt;br&gt;
The code will preprocess the documents and generate the TF-IDF matrix.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;User Query and Disease Information Retrieval:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Enter queries in the console when prompted.&lt;br&gt;
The system will process the query, calculate cosine similarity, and retrieve the most relevant disease information.&lt;/p&gt;

&lt;p&gt;The Disease Information Retrieval System is a powerful tool for retrieving disease-related information based on user queries. By leveraging NLP techniques and TF-IDF vectorization, the system can provide valuable insights into diseases, including their prevalence, risk factors, symptoms, treatments, and preventive measures. By following the implementation guide provided in this document, you can set up the system and retrieve disease information efficiently and accurately.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; It is essential to ensure the proper formatting and organization of disease-related documents in the 'Data Set' folder to achieve accurate results.&lt;/p&gt;

&lt;p&gt;Complete Code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import os
import nltk
from nltk.corpus import stopwords
from nltk.stem import SnowballStemmer
from sklearn.feature_extraction.text import TfidfVectorizer

# nltk.download('stopwords')

# set up stop words and stemmer
stop_words = set(stopwords.words('english'))
stemmer = SnowballStemmer('english')

# read all txt files from Data Set folder
folder_path = 'Data Set'
docs = []
for filename in os.listdir(folder_path):
    file_path = os.path.join(folder_path, filename)
    with open(file_path, 'r') as file:
        doc = file.read()
        docs.append(doc)

# pre-process the documents
preprocessed_docs = []
for doc in docs:
    preprocessed_doc = []
    for line in doc.split('\n'):
        if ':' in line:
            line = line.split(':')[1].strip()
        words = line.split()
        words = [word for word in words if word.lower() not in stop_words]
        words = [stemmer.stem(word) for word in words]
        preprocessed_doc.extend(words)
    preprocessed_doc = ' '.join(preprocessed_doc)
    preprocessed_docs.append(preprocessed_doc)

# generate tf-idf matrix of the terms
vectorizer = TfidfVectorizer()
tfidf_matrix = vectorizer.fit_transform(preprocessed_docs)

query = ''
while (query != 'quit'):
    # prompt the user to enter a query
    query = input('\nEnter your query: ')

    # pre-process the query
    preprocessed_query = []
    for word in query.split():
        if word.lower() not in stop_words:
            word = stemmer.stem(word)
            preprocessed_query.append(word)
    preprocessed_query = ' '.join(preprocessed_query)

    # calculate the cosine similarity between the query and each document
    cosine_similarities = tfidf_matrix.dot(
        vectorizer.transform([preprocessed_query]).T).toarray().flatten()

    # find the index of the most similar document
    most_similar_doc_index = cosine_similarities.argsort()[::-1][0]

    # retrieve the disease information from the most similar document
    most_similar_doc = docs[most_similar_doc_index]
    disease_name = ''
    prevalence = ''
    risk_factors = ''
    symptoms = ''
    treatments = ''
    preventive_measures = ''

    for line in most_similar_doc.split('\n'):
        if line.startswith('Disease Name:'):
            disease_name = line.split(':')[1].strip()
        elif line.startswith('Prevalence:'):
            prevalence = line.split(':')[1].strip()
        elif line.startswith('Risk Factors:'):
            risk_factors = line.split(':')[1].strip()
        elif line.startswith('Symptoms:'):
            symptoms = line.split(':')[1].strip()
        elif line.startswith('Treatments:'):
            treatments = line.split(':')[1].strip()
        elif line.startswith('Preventive Measures:'):
            preventive_measures = line.split(':')[1].strip()

    # print the disease information
    print(f"\nDisease Name: {disease_name}\n")
    print(f"Prevalence: {prevalence}\n")
    print(f"Risk Factors: {risk_factors}\n")
    print(f"Symptoms: {symptoms}\n")
    print(f"Treatments: {treatments}\n")
    print(f"Preventive Measures: {preventive_measures}\n\n")

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; It is not a perfect system so it is not recommended to rely only on it or follow it blindly, yet it is a good solution to help out people which doctor they should consult or take precautions which can help them to avoid further loss in health. These precautions are not harmful thought.&lt;/p&gt;

&lt;p&gt;For data set and more detailed GitHub Link: &lt;a href="https://github.com/muneebkhan4/Medical-Disease-Information-Retrival-System" rel="noopener noreferrer"&gt;https://github.com/muneebkhan4/Medical-Disease-Information-Retrival-System&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>datascience</category>
      <category>data</category>
      <category>nlp</category>
    </item>
    <item>
      <title>How to Query 1st, 2nd, or Nth Largest attribute in SQL Table</title>
      <dc:creator>Muhammad Muneeb Ur Rehman</dc:creator>
      <pubDate>Sat, 20 May 2023 10:05:47 +0000</pubDate>
      <link>https://dev.to/muneebkhan4/how-to-select-1st-2nd-or-nth-largest-attribute-in-sql-table-pdo</link>
      <guid>https://dev.to/muneebkhan4/how-to-select-1st-2nd-or-nth-largest-attribute-in-sql-table-pdo</guid>
      <description>&lt;p&gt;In SQL, selecting the first, second, or nth largest attribute from any table is a common requirement. In this article we will go through the steps to achieve this using SQL queries.&lt;br&gt;
Let's do it with an example, assume we have an &lt;code&gt;employee&lt;/code&gt; table and a &lt;code&gt;department&lt;/code&gt; table, with the employee table containing salary information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites:&lt;/strong&gt;&lt;br&gt;
Before proceeding, make sure you have a working knowledge of SQL and have access to a database management system (DBMS) such as MySQL, PostgreSQL, or Oracle.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Understand the Schema&lt;/strong&gt;&lt;br&gt;
To begin, let's assume we have two tables: &lt;code&gt;employee&lt;/code&gt; and &lt;code&gt;department&lt;/code&gt;. The &lt;code&gt;employee&lt;/code&gt; table contains columns such as &lt;code&gt;employee_id&lt;/code&gt;, &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;salary&lt;/code&gt;, and &lt;code&gt;department_id&lt;/code&gt;. The &lt;code&gt;department&lt;/code&gt; table contains columns like &lt;code&gt;department_id&lt;/code&gt; and &lt;code&gt;department_name&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Select 1st Largest Salary&lt;/strong&gt;&lt;br&gt;
To select the largest salary from the &lt;code&gt;employee&lt;/code&gt; table, you can use the following SQL query:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;SELECT MAX(salary) AS largest_salary&lt;br&gt;
FROM employee&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is pretty much simple query, and we get the largest salary easily.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Select 2nd Largest Salary&lt;/strong&gt;&lt;br&gt;
To select the second-largest salary, you can modify the previous query by adding a condition:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;SELECT MAX(salary) AS second_largest_salary&lt;br&gt;
FROM employee&lt;br&gt;
WHERE salary &amp;lt; (&lt;br&gt;
  SELECT MAX(salary)&lt;br&gt;
  FROM employee&lt;br&gt;
)&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
This query uses a subquery to find the maximum salary and then selects the maximum salary that is less than the maximum salary found in the subquery.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Select Nth Largest Salary&lt;/strong&gt;&lt;br&gt;
To select the Nth largest salary, you can generalize the previous approach by introducing a variable or parameter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SET @n = 4; -- Specify the desired Nth largest value

SELECT MAX(salary) AS nth_largest_salary
FROM employee
WHERE salary &amp;lt; (
  SELECT MAX(salary)
  FROM employee
  WHERE salary &amp;lt; (
    SELECT MAX(salary)
    FROM employee
    WHERE salary &amp;lt; (
      SELECT MAX(salary)
      FROM employee
      WHERE salary &amp;lt; (
        -- Continue this pattern until N - 1 subqueries are added
        SELECT MAX(salary)
        FROM employee
      )
    )
  )
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we use a variable &lt;code&gt;@n&lt;/code&gt; to represent the desired Nth largest value. You can adjust this variable as needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is it Horrible to query 8th largest salary?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Definitely, Not. We have &lt;code&gt;OFFSET&lt;/code&gt; and &lt;code&gt;FETCH&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Select 2nd Largest Salary&lt;/strong&gt;&lt;br&gt;
To select the second-largest salary from the "employee" table in PostgreSQL, you can use the following SQL query:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;SELECT salary&lt;br&gt;
FROM employee&lt;br&gt;
ORDER BY salary DESC&lt;br&gt;
OFFSET 1&lt;br&gt;
FETCH FIRST 1 ROW ONLY;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This query orders the salaries in descending order and skips the first row (highest salary) using the &lt;code&gt;OFFSET&lt;/code&gt; clause. Then, it &lt;code&gt;fetches&lt;/code&gt; the first row only, giving us the second-largest salary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Select 3rd Largest Salary&lt;/strong&gt;&lt;br&gt;
To select the third-largest salary, you can modify the previous query by changing the &lt;code&gt;OFFSET&lt;/code&gt; value:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;SELECT salary&lt;br&gt;
FROM employee&lt;br&gt;
ORDER BY salary DESC&lt;br&gt;
OFFSET 2&lt;br&gt;
FETCH FIRST 1 ROW ONLY;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here, we set the OFFSET to 2, skipping the first two rows (two highest salaries), and fetching the first row, which corresponds to the third-largest salary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Select Nth Largest Salary&lt;/strong&gt;&lt;br&gt;
To select the Nth largest salary, you can generalize the previous approach by introducing a variable or parameter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DECLARE @n INT = 4; -- Specify the desired Nth largest value

SELECT salary
FROM employee
ORDER BY salary DESC
OFFSET (@n - 1)
FETCH FIRST 1 ROW ONLY;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we introduce a variable &lt;code&gt;@n&lt;/code&gt; to represent the desired Nth largest value. You can adjust this variable as needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;br&gt;
Using the &lt;code&gt;OFFSET&lt;/code&gt; and &lt;code&gt;FETCH&lt;/code&gt; clauses in PostgreSQL allows for an efficient and concise way to select the second, third, and Nth largest salaries from an employee table.&lt;/p&gt;

</description>
      <category>sql</category>
      <category>postgres</category>
      <category>backend</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How React Preserve and Reset State</title>
      <dc:creator>Muhammad Muneeb Ur Rehman</dc:creator>
      <pubDate>Fri, 19 May 2023 12:55:43 +0000</pubDate>
      <link>https://dev.to/muneebkhan4/how-react-preserve-and-reset-state-38la</link>
      <guid>https://dev.to/muneebkhan4/how-react-preserve-and-reset-state-38la</guid>
      <description>&lt;p&gt;State is isolated between components. React keeps track of which state belongs to which component based on their place in the UI tree. You can control when to preserve state and when to reset it between re-renders.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The UI tree&lt;/strong&gt;&lt;br&gt;
Browsers use many tree structures to model UI. The DOM represents HTML elements, the CSSOM does the same for CSS. There’s even an Accessibility tree!&lt;/p&gt;

&lt;p&gt;React also uses tree structures to manage and model the UI you make. React makes UI trees from your JSX. Then React DOM updates the browser DOM elements to match that UI tree. (React Native translates these trees into elements specific to mobile platforms.)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc92kdqtrrgwo4my3c8pz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc92kdqtrrgwo4my3c8pz.png" alt="From components, React creates a UI tree which React DOM uses to render the DOM" width="800" height="177"&gt;&lt;/a&gt;&lt;br&gt;
Note: Open Image for Best View and Understanding.&lt;/p&gt;

&lt;p&gt;From components, React creates a UI tree which React DOM uses to render the DOM&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;State is tied to a position in the tree&lt;/strong&gt;&lt;br&gt;
When you give a component state, you might think the state “lives” inside the component. But the state is actually held inside React. React associates each piece of state it’s holding with the correct component by where that component sits in the UI tree.&lt;/p&gt;

&lt;p&gt;Let's see it with the help of an example. Assume, we have a &lt;code&gt;&amp;lt;Counter /&amp;gt;&lt;/code&gt; JSX tag, but it’s rendered at two different positions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from 'react';

export default function App() {
  const counter = &amp;lt;Counter /&amp;gt;;
  return (
    &amp;lt;div&amp;gt;
      {counter}
      {counter}
    &amp;lt;/div&amp;gt;
  );
}

function Counter() {
  const [score, setScore] = useState(0);
  const [hover, setHover] = useState(false);

  let className = 'counter';
  if (hover) {
    className += ' hover';
  }

  return (
    &amp;lt;div
      className={className}
      onPointerEnter={() =&amp;gt; setHover(true)}
      onPointerLeave={() =&amp;gt; setHover(false)}
    &amp;gt;
      &amp;lt;h1&amp;gt;{score}&amp;lt;/h1&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; setScore(score + 1)}&amp;gt;
        Add one
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fisdogl9tu5schrd6299t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fisdogl9tu5schrd6299t.png" alt="React tree" width="640" height="402"&gt;&lt;/a&gt;&lt;br&gt;
Note: Open Image for Best View and Understanding.&lt;/p&gt;

&lt;p&gt;These are two separate counters because each is rendered at its own position in the tree. You don’t usually have to think about these positions to use React, but it can be useful to understand how it works.&lt;/p&gt;

&lt;p&gt;In React, each component on the screen has fully isolated state. For example, if you render two Counter components side by side, each of them will get its own, independent, score and hover states.&lt;/p&gt;

&lt;p&gt;Try running the code and clicking both counters and notice they don’t affect each other:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from 'react';

export default function App() {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;Counter /&amp;gt;
      &amp;lt;Counter /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

function Counter() {
  const [score, setScore] = useState(0);
  const [hover, setHover] = useState(false);

  let className = 'counter';
  if (hover) {
    className += ' hover';
  }

  return (
    &amp;lt;div
      className={className}
      onPointerEnter={() =&amp;gt; setHover(true)}
      onPointerLeave={() =&amp;gt; setHover(false)}
    &amp;gt;
      &amp;lt;h1&amp;gt;{score}&amp;lt;/h1&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; setScore(score + 1)}&amp;gt;
        Add one
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, when one counter is updated, only the state for that component is updated:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxam380k0m8k0lp3na344.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxam380k0m8k0lp3na344.png" alt="Updating state" width="640" height="360"&gt;&lt;/a&gt;&lt;br&gt;
Note: Open Image for Best View and Understanding.&lt;/p&gt;

&lt;p&gt;React will keep the state around for as long as you render the same component at the same position. To see this, increment the counter, then remove it by unchecking “Render the counter” checkbox, and then add it back by ticking it again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from 'react';

export default function App() {
  const [showB, setShowB] = useState(true);
  return (
    &amp;lt;div&amp;gt;
      {showB &amp;amp;&amp;amp; &amp;lt;Counter /&amp;gt;} 
      &amp;lt;label&amp;gt;
        &amp;lt;input
          type="checkbox"
          checked={showB}
          onChange={e =&amp;gt; {
            setShowB(e.target.checked)
          }}
        /&amp;gt;
        Render the counter
      &amp;lt;/label&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

function Counter() {
  const [score, setScore] = useState(0);
  const [hover, setHover] = useState(false);

  let className = 'counter';
  if (hover) {
    className += ' hover';
  }

  return (
    &amp;lt;div
      className={className}
      onPointerEnter={() =&amp;gt; setHover(true)}
      onPointerLeave={() =&amp;gt; setHover(false)}
    &amp;gt;
      &amp;lt;h1&amp;gt;{score}&amp;lt;/h1&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; setScore(score + 1)}&amp;gt;
        Add one
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6l6h5zi6amovengk3zo4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6l6h5zi6amovengk3zo4.png" alt="Deleting a component" width="640" height="384"&gt;&lt;/a&gt;&lt;br&gt;
Note: Open Image for Best View and Understanding.&lt;/p&gt;

&lt;p&gt;When you tick “Render the counter”, a new Counter and its state are initialized from scratch (score = 0) and added to the DOM.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2opqtky0z6muaka15u4a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2opqtky0z6muaka15u4a.png" alt="Adding a component" width="640" height="330"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: Open Image for Best View and Understanding.&lt;br&gt;
React preserves a component’s state for as long as it’s being rendered at its position in the UI tree. If it gets removed, or a different component gets rendered at the same position, React discards its state.&lt;/p&gt;

&lt;p&gt;Source: &lt;a href="https://react.dev/learn/preserving-and-resetting-state" rel="noopener noreferrer"&gt;https://react.dev/learn/preserving-and-resetting-state&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>frontend</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>University Management System in Apache AGE - Part-3</title>
      <dc:creator>Muhammad Muneeb Ur Rehman</dc:creator>
      <pubDate>Wed, 17 May 2023 11:24:20 +0000</pubDate>
      <link>https://dev.to/muneebkhan4/university-management-system-in-apache-age-part-3-27dl</link>
      <guid>https://dev.to/muneebkhan4/university-management-system-in-apache-age-part-3-27dl</guid>
      <description>&lt;p&gt;Now we will see the relations (edges) in our University Management System with the help of some dummy data insertion and in the end, we will see how it will look like in Apache AGE Viewer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enrolled_In relation:&lt;/strong&gt;&lt;br&gt;
The students get enrolled in different courses. Here is an example with some dummy data where I have created five enrollment relations between students and courses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enrollment-1:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT *&lt;br&gt;
FROM cypher('university', $$&lt;br&gt;
    MATCH (s:student), (c:course)&lt;br&gt;
    WHERE s.name = 'std1' AND c.name = 'Database'                                                                        CREATE (s)-[e:enrolled_in]-&amp;gt;(c)&lt;br&gt;
    RETURN e&lt;br&gt;
$$) as (e agtype);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enrollment-2:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT *&lt;br&gt;
FROM cypher('university', $$&lt;br&gt;
    MATCH (s:student), (c:course)&lt;br&gt;
    WHERE s.name = 'std2' AND c.name = 'Database'                                                                        CREATE (s)-[e:enrolled_in]-&amp;gt;(c)&lt;br&gt;
    RETURN e&lt;br&gt;
$$) as (e agtype);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enrollment-3:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT *&lt;br&gt;
FROM cypher('university', $$&lt;br&gt;
    MATCH (s:student), (c:course)&lt;br&gt;
    WHERE s.name = 'std3' AND c.name = 'Programming'                                                                        CREATE (s)-[e:enrolled_in]-&amp;gt;(c)&lt;br&gt;
    RETURN e&lt;br&gt;
$$) as (e agtype);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enrollment-4:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT *&lt;br&gt;
FROM cypher('university', $$&lt;br&gt;
    MATCH (s:student), (c:course)&lt;br&gt;
    WHERE s.name = 'std4' AND c.name = 'Programming'                                                                        CREATE (s)-[e:enrolled_in]-&amp;gt;(c)&lt;br&gt;
    RETURN e&lt;br&gt;
$$) as (e agtype);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enrollment-5:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT *&lt;br&gt;
FROM cypher('university', $$&lt;br&gt;
    MATCH (s:student), (c:course)&lt;br&gt;
    WHERE s.name = 'std5' AND c.name = 'Programming'                                                                        CREATE (s)-[e:enrolled_in]-&amp;gt;(c)&lt;br&gt;
    RETURN e&lt;br&gt;
$$) as (e agtype);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Taught_By Relation:&lt;/strong&gt;&lt;br&gt;
The courses are taught by different teachers. Here I have created two taught by relations between courses and teachers with dummy data:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Taught_By Relation-1:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT *&lt;br&gt;
FROM cypher('university', $$&lt;br&gt;
    MATCH (c:course), (t:teacher)&lt;br&gt;
    WHERE c.name = 'Programming' AND t.name = 'Muneeb'&lt;br&gt;
    CREATE (c)-[e:taught_by]-&amp;gt;(t)&lt;br&gt;
    RETURN e&lt;br&gt;
$$) as (e agtype);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Taught_By Relation-2:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT *&lt;br&gt;
FROM cypher('university', $$&lt;br&gt;
    MATCH (c:course), (t:teacher)&lt;br&gt;
    WHERE c.name = 'Programming' AND t.name = 'Muneeb'&lt;br&gt;
    CREATE (c)-[e:taught_by]-&amp;gt;(t)&lt;br&gt;
    RETURN e&lt;br&gt;
$$) as (e agtype);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Offered_By Relation:&lt;/strong&gt;&lt;br&gt;
The couses are offered by different departments. Here I have created two offered by relations between courses and department with dummy data:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Offered_By Relation-1:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT *&lt;br&gt;
FROM cypher('university', $$&lt;br&gt;
    MATCH (c:course), (d:Department)&lt;br&gt;
    WHERE c.name = 'Database' AND d.name = 'Computer Science'&lt;br&gt;
    CREATE (c)-[e:offered_by]-&amp;gt;(d)&lt;br&gt;
    RETURN e&lt;br&gt;
$$) as (e agtype);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Offered_By Relation-2:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT *&lt;br&gt;
FROM cypher('university', $$&lt;br&gt;
    MATCH (c:course), (d:Department)&lt;br&gt;
    WHERE c.name = 'Programming' AND d.name = 'Computer Science'                                                            CREATE (c)-[e:offered_by]-&amp;gt;(d)&lt;br&gt;
    RETURN e&lt;br&gt;
$$) as (e agtype);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Affiliated_With Raltion-1:&lt;/strong&gt;&lt;br&gt;
Every teacher is affiliated with any Department. Here I have created two affiliated with relations between teachers and department with some dummy data:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Affiliated_With Relation-1:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT *&lt;br&gt;
FROM cypher('university', $$&lt;br&gt;
    MATCH (t:teacher), (d:Department)&lt;br&gt;
    WHERE t.name = 'Muneeb' AND d.name = 'Computer Science'&lt;br&gt;
    CREATE (t)-[e:affiliated_with]-&amp;gt;(d)&lt;br&gt;
    RETURN e&lt;br&gt;
$$) as (e agtype);&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Affliated_With Raltion-2:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT *&lt;br&gt;
FROM cypher('university', $$&lt;br&gt;
    MATCH (t:teacher), (d:Department)&lt;br&gt;
    WHERE t.name = 'Micheal' AND d.name = 'Computer Science'                                                                CREATE (t)-[e:affliated_with]-&amp;gt;(d)&lt;br&gt;
    RETURN e&lt;br&gt;
$$) as (e agtype);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftj8o5gbfxkxv5szez8kk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftj8o5gbfxkxv5szez8kk.png" alt="University Management System in Age Viewer" width="800" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For more details visit: &lt;a href="https://age.apache.org/overview/" rel="noopener noreferrer"&gt;https://age.apache.org/overview/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AGE Github Link:&lt;/strong&gt; &lt;a href="https://github.com/apache/age" rel="noopener noreferrer"&gt;https://github.com/apache/age&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AGE Viewer Github Link:&lt;/strong&gt; &lt;a href="https://github.com/apache/age-viewer" rel="noopener noreferrer"&gt;https://github.com/apache/age-viewer&lt;/a&gt;&lt;/p&gt;

</description>
      <category>apacheage</category>
      <category>graphdatabase</category>
      <category>database</category>
      <category>postgres</category>
    </item>
    <item>
      <title>University Management System in Apache AGE - Part-2</title>
      <dc:creator>Muhammad Muneeb Ur Rehman</dc:creator>
      <pubDate>Wed, 17 May 2023 09:16:20 +0000</pubDate>
      <link>https://dev.to/muneebkhan4/university-management-system-in-apache-age-part-2-hgg</link>
      <guid>https://dev.to/muneebkhan4/university-management-system-in-apache-age-part-2-hgg</guid>
      <description>&lt;p&gt;Here is a sample database documentation that includes the necessary Nodes and their attributes:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Student&lt;/strong&gt;&lt;br&gt;
id: unique identifier for the student&lt;br&gt;
name: name of the student&lt;br&gt;
email: email address of the student&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Teacher&lt;/strong&gt;&lt;br&gt;
id: unique identifier for the professor&lt;br&gt;
name: name of the professor&lt;br&gt;
email: email address of the professor&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Course&lt;/strong&gt;&lt;br&gt;
id: unique identifier for the course&lt;br&gt;
name: name of the course&lt;br&gt;
credits: number of credits assigned to the course&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Department&lt;/strong&gt;&lt;br&gt;
id: unique identifier for the department&lt;br&gt;
name: name of the department&lt;/p&gt;

&lt;p&gt;Let's now create some dummy data to see how our system will work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Department&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT * FROM cypher('university', $$&lt;br&gt;
create(:Department{name:'Computer Science', rooms:30})&lt;br&gt;
$$) as (v agtype);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Student&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT * FROM cypher('university', $$&lt;br&gt;
create(:student{name:'std1', rollNo:1})&lt;br&gt;
$$) as (v agtype);&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;SELECT * FROM cypher('university', $$&lt;br&gt;
create(:student{name:'std2', rollNo:2})&lt;br&gt;
$$) as (v agtype);&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;SELECT * FROM cypher('university', $$&lt;br&gt;
create(:student{name:'std3', rollNo:3})&lt;br&gt;
$$) as (v agtype);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;SELECT * FROM cypher('university', $$&lt;br&gt;
create(:student{name:'std4', rollNo:4})&lt;br&gt;
$$) as (v agtype);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;SELECT * FROM cypher('university', $$&lt;br&gt;
create(:student{name:'std5', rollNo:5})&lt;br&gt;
$$) as (v agtype);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Teacher&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT * FROM cypher('university', $$&lt;br&gt;
create(:teacher{name:'Micheal', role:'Assistant Prof'})&lt;br&gt;
$$) as (v agtype);&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;code&gt;SELECT * FROM cypher('university', $$&lt;br&gt;
create(:teacher{name:'Muneeb', role:'Professor'})&lt;br&gt;
$$) as (v agtype);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Course&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT * FROM cypher('university', $$&lt;br&gt;
create(:course{name:'Programming', creditHours:3})&lt;br&gt;
$$) as (v agtype);&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;code&gt;SELECT * FROM cypher('university', $$&lt;br&gt;
create(:course{name:'Database', creditHours:3})&lt;br&gt;
$$) as (v agtype);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For more details visit: &lt;a href="https://age.apache.org/overview/" rel="noopener noreferrer"&gt;https://age.apache.org/overview/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AGE Github Link:&lt;/strong&gt; &lt;a href="https://github.com/apache/age" rel="noopener noreferrer"&gt;https://github.com/apache/age&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AGE Viewer Github Link:&lt;/strong&gt; &lt;a href="https://github.com/apache/age-viewer" rel="noopener noreferrer"&gt;https://github.com/apache/age-viewer&lt;/a&gt;&lt;/p&gt;

</description>
      <category>apacheage</category>
      <category>graphdatabase</category>
      <category>database</category>
      <category>postgres</category>
    </item>
    <item>
      <title>University Management System in Apache AGE - Part-1</title>
      <dc:creator>Muhammad Muneeb Ur Rehman</dc:creator>
      <pubDate>Wed, 17 May 2023 09:08:46 +0000</pubDate>
      <link>https://dev.to/muneebkhan4/university-management-system-in-apache-age-part-1-1d3n</link>
      <guid>https://dev.to/muneebkhan4/university-management-system-in-apache-age-part-1-1d3n</guid>
      <description>&lt;p&gt;First, let's define the entities involved in the university management system. Some of the entities that come to mind are:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Entities:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;Students&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Teachers&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Courses&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Departments&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Next, we need to define the relationships between these entities. Here are some of the relationships that exist in a university management system:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Relations:&lt;/strong&gt;&lt;br&gt;
A student can enroll in multiple courses.&lt;br&gt;
A course can have multiple students enrolled in it.&lt;br&gt;
A course is taught by one or more teacher.&lt;br&gt;
A teacher can teach one or more courses.&lt;br&gt;
A course is offered by one department.&lt;br&gt;
A department can offer multiple courses.&lt;br&gt;
A department can have multiple teachers.&lt;br&gt;
A teacher can be affiliated with one department.&lt;/p&gt;

&lt;p&gt;Based on the above entities and relationships, we can create an ER diagram for the university management system using a graph database.&lt;br&gt;
The ER diagram will have the following entities:&lt;br&gt;
&lt;strong&gt;Entities:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;Student&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Teacher&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Course&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Department&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The ER diagram will have the following relationships:&lt;br&gt;
&lt;strong&gt;Relations:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;Enrolled in (Student -&amp;gt; Course)&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Taught by (Course -&amp;gt; Teacher)&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Offered by (Course -&amp;gt; Department)&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Affiliated with (Teacher -&amp;gt; Department)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once the ER diagram is created, we can use it to create the necessary Nodes and Edges in the graph (Apache AGE) database.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5bhqiyvht6kzjf8zgid2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5bhqiyvht6kzjf8zgid2.png" alt="University Management System" width="800" height="1131"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For more details visit: &lt;a href="https://age.apache.org/overview/" rel="noopener noreferrer"&gt;https://age.apache.org/overview/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AGE Github Link:&lt;/strong&gt; &lt;a href="https://github.com/apache/age" rel="noopener noreferrer"&gt;https://github.com/apache/age&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AGE Viewer Github Link:&lt;/strong&gt; &lt;a href="https://github.com/apache/age-viewer" rel="noopener noreferrer"&gt;https://github.com/apache/age-viewer&lt;/a&gt;&lt;/p&gt;

</description>
      <category>apacheage</category>
      <category>graphdatabase</category>
      <category>database</category>
      <category>postgres</category>
    </item>
    <item>
      <title>Load Edges Data from CSV file to Apache AGE</title>
      <dc:creator>Muhammad Muneeb Ur Rehman</dc:creator>
      <pubDate>Wed, 03 May 2023 16:48:35 +0000</pubDate>
      <link>https://dev.to/muneebkhan4/load-edges-data-from-csv-file-to-apache-age-2ho0</link>
      <guid>https://dev.to/muneebkhan4/load-edges-data-from-csv-file-to-apache-age-2ho0</guid>
      <description>&lt;p&gt;In Apache AGE, we can load edges data from CSV file. A CSV file for edges should be formatted as follows:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;start_id:&lt;/strong&gt;&lt;br&gt;
It is node id of the node from where the edge is stated. This id should be valid i.e., node with such id should exist.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;start_vertex_type:&lt;/strong&gt;&lt;br&gt;
It should contain &lt;code&gt;class/ label&lt;/code&gt; name of the node. This &lt;code&gt;label&lt;/code&gt; should be valid.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;end_id:&lt;/strong&gt;&lt;br&gt;
The end id of the node at which the edge shall be terminated. This id should also be valid i.e., node with such id should exist.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;end_vertex_type:&lt;/strong&gt;&lt;br&gt;
It should contain &lt;code&gt;class/ label&lt;/code&gt; name of the node. This &lt;code&gt;label&lt;/code&gt; should be valid.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;properties:&lt;/strong&gt;&lt;br&gt;
The properties of the edge. The header (1st Row) shall contain the property name. 2nd Row and onward rows contains data (values).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create Edge Label:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT create_elabel('GraphName','EdgeLabelName');&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Load Edge Data from csv File:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT load_edges_from_file('GraphName', 'EdgeLabelName',&lt;br&gt;
     'Path/to/file.csv');&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For more details visit: &lt;a href="https://age.apache.org/overview/" rel="noopener noreferrer"&gt;https://age.apache.org/overview/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AGE Github Link:&lt;/strong&gt; &lt;a href="https://github.com/apache/age" rel="noopener noreferrer"&gt;https://github.com/apache/age&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AGE Viewer Github Link:&lt;/strong&gt; &lt;a href="https://github.com/apache/age-viewer" rel="noopener noreferrer"&gt;https://github.com/apache/age-viewer&lt;/a&gt;&lt;/p&gt;

</description>
      <category>apacheage</category>
      <category>graphdatabase</category>
      <category>database</category>
      <category>postgres</category>
    </item>
    <item>
      <title>Load Vertices (Nodes) data from CSV file to Apache AGE</title>
      <dc:creator>Muhammad Muneeb Ur Rehman</dc:creator>
      <pubDate>Tue, 18 Apr 2023 19:27:28 +0000</pubDate>
      <link>https://dev.to/muneebkhan4/load-vertices-nodes-data-from-csv-file-to-apache-age-1clh</link>
      <guid>https://dev.to/muneebkhan4/load-vertices-nodes-data-from-csv-file-to-apache-age-1clh</guid>
      <description>&lt;p&gt;In Apache AGE, we can load the data of nodes/ vertices from CSV file as well.&lt;br&gt;
A CSV file containing nodes' data should be formatted as following:&lt;br&gt;
&lt;strong&gt;id:&lt;/strong&gt;&lt;br&gt;
It should be the first column of the file and all values should be a positive integer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;br&gt;
All other columns should contain the properties for the nodes. Header row should contain the name of properties and rows below Header row should contain data. One row as a whole should be treated as one vertex.&lt;/p&gt;

&lt;p&gt;First step is to create a label for the vertex.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create Vertex Lable:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT create_vlabel('GraphName','LabelName');&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Second step is to get data from CSV file and create vertices.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Load Data from CSV:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT load_labels_from_file('GraphName',&lt;br&gt;
                             'LabelName',&lt;br&gt;
                             'Path/to/file.csv');&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For more details visit: &lt;a href="https://age.apache.org/overview/" rel="noopener noreferrer"&gt;https://age.apache.org/overview/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AGE Github Link:&lt;/strong&gt; &lt;a href="https://github.com/apache/age" rel="noopener noreferrer"&gt;https://github.com/apache/age&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AGE Viewer Github Link:&lt;/strong&gt; &lt;a href="https://github.com/apache/age-viewer" rel="noopener noreferrer"&gt;https://github.com/apache/age-viewer&lt;/a&gt;&lt;/p&gt;

</description>
      <category>apacheage</category>
      <category>graphdatabase</category>
      <category>database</category>
      <category>postgres</category>
    </item>
    <item>
      <title>Delete Edges from Apache AGE</title>
      <dc:creator>Muhammad Muneeb Ur Rehman</dc:creator>
      <pubDate>Tue, 18 Apr 2023 19:20:11 +0000</pubDate>
      <link>https://dev.to/muneebkhan4/delete-edges-from-apache-age-jop</link>
      <guid>https://dev.to/muneebkhan4/delete-edges-from-apache-age-jop</guid>
      <description>&lt;p&gt;In Apache AGE, we can delete any edge by using &lt;code&gt;DELETE&lt;/code&gt; command. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Query:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT * &lt;br&gt;
FROM cypher('graph_name', $$&lt;br&gt;
    MATCH (n {name: 'Andres'})-[r:KNOWS]-&amp;gt;()&lt;br&gt;
    DELETE r&lt;br&gt;
$$) as (v agtype);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Explanation:&lt;br&gt;
Firstly, we find the edge we want to delete by using &lt;code&gt;MATCH&lt;/code&gt; for instance, &lt;code&gt;MATCH (n {name: 'Andres'})-[r:KNOWS]-&amp;gt;()&lt;/code&gt;. Then, we delete that edge by using, &lt;code&gt;DELETE r&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For more details visit: &lt;a href="https://age.apache.org/overview/" rel="noopener noreferrer"&gt;https://age.apache.org/overview/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AGE Github Link:&lt;/strong&gt; &lt;a href="https://github.com/apache/age" rel="noopener noreferrer"&gt;https://github.com/apache/age&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AGE Viewer Github Link:&lt;/strong&gt; &lt;a href="https://github.com/apache/age-viewer" rel="noopener noreferrer"&gt;https://github.com/apache/age-viewer&lt;/a&gt;&lt;/p&gt;

</description>
      <category>apacheage</category>
      <category>graphdatabase</category>
      <category>database</category>
      <category>postgres</category>
    </item>
  </channel>
</rss>
