Sobes.tech
Junior — Middle

Do you have experience working directly with SQL without using ORM or additional abstractions?

sobes.tech AI

Answer from AI

Yes, experience working directly with SQL without ORM is common, especially when high performance or precise control over queries is needed. In Node.js, this is usually done using database drivers, such as mysql2 or pg for PostgreSQL.

Here's an example of a simple query to a MySQL database without ORM:

const mysql = require('mysql2/promise');

async function getUsers() {
  const connection = await mysql.createConnection({host: 'localhost', user: 'root', database: 'test'});
  const [rows] = await connection.execute('SELECT id, name FROM users WHERE active = ?', [1]);
  await connection.end();
  return rows;
}

getUsers().then(users => console.log(users));

This approach allows writing precise SQL queries and controlling their execution directly.

Do you have experience working directly with SQL… - sobes.tech