A versatile SQL ORM library for JavaScript/TypeScript that simplifies database interactions and enables seamless mapping between SQL databases and object-oriented programming.
- Install sqluminator and mysql driver packages for nodejs using npm or yarn.
The current version of the sqluminator library only supports the MySQL driver for Node.js. However, we want to assure you that we are committed to expanding our support to include other SQL drivers as well.
npm i sqluminator mysql
const { SQL } = require("sqluminator");
SQL.createConnection("mysql", {
// Change the values depending on your target connection
user: "root",
host: "localhost",
database: "orm",
password: "",
port: 3306,
});
const { SQL } = require("sqluminator");
/**
*
* constructor(tableName: string, schema?: any)
*/
const User = new Model("user"); // the sql table would be 'users'
Inserts a new record.
data
(Object
): The data object containing the record information.
Returns a Promise
that resolves when the record is successfully inserted.
const user = await User.save({ name: "Anthony Stark" });
console.log({ user });
const users = await User.find({ name: "Anthony Stark" }, { lean: true });
console.log(users);
await User.findByIdAndUpdate(15, { name: "mart" });
- Delete single record by id
await User.findByIdAndDelete(4);
- or delete many records using a condition
await User.deleteMany({ age: 15 });