Sobes.tech
Junior — Middle

Describe your experience with SQL-based database management systems, specify the technologies used and preferred practices.

sobes.tech AI

Answer from AI

In working with SQL databases, I have used technologies such as PostgreSQL, MySQL, and SQLite. To interact with them in Node.js, I employed ORMs (e.g., Sequelize) and native drivers (e.g., pg for PostgreSQL).

Preferred practices:

  • Using parameterized queries to prevent SQL injection.
  • Normalizing the database to reduce data redundancy.
  • Indexing columns to speed up queries.
  • Separating data access logic into separate layers (repositories).
  • Using migrations to manage schema changes.

An example of a simple 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 * FROM users WHERE active = $1', [true]);
  await client.end();
  return res.rows;
}

This approach ensures security and ease of working with the database.