JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q44654F
  • License MIT

Query Easy: Simple SQL helper like Mongoose for MySQL/MariaDB

Package Exports

  • qeasy
  • qeasy/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (qeasy) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

πŸš€ QEasy (Query Easy)

npm version npm downloads license

πŸš€ QEasy (Query Easy)

A lightweight SQL helper for Node.js Easily perform CRUD operations, joins, where clauses, ordering, limits, and offsets without writing raw SQL.

πŸ“¦ Installation

npm install qeasy

⚑ Quick Start

const qeasy = require("qeasy");

// 1️⃣ Connect to Database
qeasy.connectDB({
  host: "localhost",
  user: "root",
  password: "password",
  database: "mydb",
  port: 3306,
});

// 2️⃣ Check Connection
qeasy.checkConnection()
  .then(() => console.log("βœ… Database connected"))
  .catch(err => console.error("❌ Connection error:", err));

πŸ”‘ Basic CRUD Examples

Insert Data (Table name , dataObj)

await qeasy.insert("users", {
  name: "John Doe",
  email: "john@example.com",
  age: 25,
});

Find All (Table name)

const users = await qeasy.findAll("users");
console.log(users);

Find By ID (Table name , Field name , id )

const user = await qeasy.findById("users", "id", 1);
console.log(user);

Update By ID (Table name , Field name , id , dataObj)

await qeasy.findByIdAndUpdate("users", "id", 1, { age: 26 });

Delete By ID (Table name , Field name , id)

await qeasy.findByIdAndDelete("users", "id", 1);

πŸ”— Joins Made Easy

const results = await qeasy.findWithJoins({
  table: "orders",
  as: "o",
  selectedColumns: ["o.id", "o.total", "u.name"],
  joins: [
    {
      table: "users",
      as: "u",
      type: "INNER",
      on: { "u.id": "o.user_id" },
    },
  ],
  where: [
    { column: "u.age", operator: ">", value: 18 },
  ],
  orderBy: [
    { column: "o.total", direction: "DESC" },
  ],
  limit: 10,
  offset: 0,
});

console.log(results);

🎯 Options Explained

## Joins
interface JoinOption {
  table: string;      // table name
  as?: string;        // alias
  type?: "INNER" | "LEFT" | "RIGHT";
  on: { [key: string]: string }; // join condition
}

Where Condition

interface WhereCondition {
  column: string;  // e.g., "u.id"
  operator?: string; // '=', '>', '<', 'LIKE'
  value: any;
}

Order By

interface OrderByOption {
  column: string; // e.g., "u.name"
  direction?: "ASC" | "DESC";
}

πŸ§‘β€πŸ’» Example Project

const qeasy = require("qeasy");

async function run() {
  qeasy.connectDB({
    host: "localhost",
    user: "root",
    password: "password",
    database: "shopdb",
  });

  // Insert a product
  await qeasy.insert("products", { name: "Laptop", price: 50000 });

  // Get all products
  const products = await qeasy.findAll("products");
  console.log(products);

  // Join example: Orders + Users
  const orders = await qeasy.findWithJoins({
    table: "orders",
    as: "o",
    selectedColumns: ["o.id", "u.name", "o.total"],
    joins: [{ table: "users", as: "u", on: { "u.id": "o.user_id" } }],
  });
  console.log(orders);
}

run();

πŸ“Œ Why QEasy?

βœ… Simple, mongoose-like syntax βœ… No need to write raw SQL queries βœ… Supports CRUD + complex joins βœ… Beginner-friendly

✨ That’s it! With just npm i qeasy, you can start querying your SQL DB easily.