Sure! You can do CRUD operations in Node.js without using a special tool called an ORM. Here’s how I usually do it:
Using Built-in Drivers: For MongoDB, I use the regular mongodb
driver. For PostgreSQL, I choose pg
. These tools let you run commands directly.
Writing Your Own Queries: Instead of using an ORM, I write my own SQL or MongoDB commands. This gives me better control and makes it easier to fix problems.
Example: If I want to add a new user, I might write something like this:
const { MongoClient } = require('mongodb');
const client = new MongoClient(uri);
await client.connect();
await client.db("test").collection("users").insertOne({ name: "John Doe" });
It's simple and a great way to learn how things really work!
Sure! You can do CRUD operations in Node.js without using a special tool called an ORM. Here’s how I usually do it:
Using Built-in Drivers: For MongoDB, I use the regular mongodb
driver. For PostgreSQL, I choose pg
. These tools let you run commands directly.
Writing Your Own Queries: Instead of using an ORM, I write my own SQL or MongoDB commands. This gives me better control and makes it easier to fix problems.
Example: If I want to add a new user, I might write something like this:
const { MongoClient } = require('mongodb');
const client = new MongoClient(uri);
await client.connect();
await client.db("test").collection("users").insertOne({ name: "John Doe" });
It's simple and a great way to learn how things really work!