Sobes.tech
Junior — Middle

What is your experience with writing native SQL queries?

sobes.tech AI

Answer from AI

Working with native SQL queries typically involves writing queries directly to the database without using an ORM. In Node.js, this is often implemented through libraries such as pg for PostgreSQL or mysql2 for MySQL. Here's an example of a simple native query using pg:

const { Client } = require('pg');
const client = new Client({ connectionString: process.env.DATABASE_URL });

async function getUsers() {
  await client.connect();
  const res = await client.query('SELECT id, name FROM users WHERE active = $1', [true]);
  await client.end();
  return res.rows;
}

This approach gives full control over SQL queries, allows for optimization, and enables the use of database-specific features.

What is your experience with writing native SQL… - sobes.tech