DEV Community

Avinash Maurya
Avinash Maurya

Posted on

GraphQL, MongoDB, and PostgreSQL (pgsql)

GraphQL, MongoDB, and PostgreSQL (pgsql) using the given SQL query:

GraphQL:

In GraphQL, the equivalent query might look like this:

query {
  employees(where: { department: "IT" }, orderBy: { hireDate: "DESC" }, limit: 10) {
    id
    name
    // Include other fields as needed
  }
}
Enter fullscreen mode Exit fullscreen mode

This is just an example, and the actual query structure would depend on your GraphQL schema and the way your server is set up.

MongoDB:

In MongoDB, you would typically use the find method with sort and limit:

db.employees.find({ department: "IT" }).sort({ hireDate: -1 }).limit(10);
Enter fullscreen mode Exit fullscreen mode

This assumes that your MongoDB collection is named employees. Adjust the collection name and fields as needed.

PostgreSQL (pg-promise library in Node.js):

In PostgreSQL with Node.js using the pg-promise library, the equivalent might be:

const employees = await db.any(
  'SELECT * FROM employees WHERE department = $1 ORDER BY hire_date DESC LIMIT 10',
  ['IT']
);
Enter fullscreen mode Exit fullscreen mode

This assumes that you have a connection to your PostgreSQL database through the db object. Adjust the table name, field names, and connection details based on your setup.

Remember that the exact syntax and method of querying can vary based on your specific GraphQL schema, MongoDB setup, or PostgreSQL configuration. Please adapt these examples to fit your actual data structure and environment.

Tiger Data image

🐯 🚀 Timescale is now TigerData

Building the modern PostgreSQL for the analytical and agentic era.

Read more

Top comments (0)

Image of Timescale

PostgreSQL for Agentic AI — Build Autonomous Apps on One Stack ☝️

pgai turns PostgreSQL into an AI-native database for building RAG pipelines and intelligent agents. Run vector search, embeddings, and LLMs—all in SQL

Build Today

👋 Kindness is contagious

Explore this insightful piece, celebrated by the caring DEV Community. Programmers from all walks of life are invited to contribute and expand our shared wisdom.

A simple "thank you" can make someone’s day—leave your kudos in the comments below!

On DEV, spreading knowledge paves the way and fortifies our camaraderie. Found this helpful? A brief note of appreciation to the author truly matters.

Let’s Go!