awesome-sql
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

My Awesome Sql

A light weight awesome sql sdk with promises and typescript.



Getting Started

To tnstall AwesomeSql in your project.

pnpm install awesome-sql

Examples

Create Connection

Create a connection with your database.

// database.ts
import awesomeSql from "awesome-sql";

export const sql = await awesomeSql.getInstance({
  host: "127.0.0.1",
  port: 3306,
  database: "awesome-sql",
  user: "root",
  password: "2023",
});

Select

Selecting is the amazing fact of AwesomeSql.

Select a single data

import { sql } from "./database";

await sql.select({
  model: "posts",
  columns: ["id", "title", "createdAt"],
  where: {
    id: 1,
  },
});

Join tables

Unbelivealbe things of awesomeSql with awesome joining.

import { sql } from "./database";

await sql.select({
  model: "posts",
  columns: ["id", "title", "createdAt"],
  where: {
    id: 1,
  },
  joins: [
    {
      model: "users",
      as: "user",
      columns: ["name", "email"],
      on: { id: "userId" },
    },
  ],
});

Insert

Inserting on awesomeSql is so easy.

Insert single data

import { sql } from "./database";

await sql.insert({
  model: "users",
  data: [{ name: "mahi", email: "mahi@gamil.com", password: "mahi" }],
});

Insert multiple data

import { sql } from "./database";

await sql.insert({
  model: "users",
  data: [
    { name: "mahi", email: "mahi@gamil.com", password: "mahi" },
    { name: "koishor", email: "koishor@gamil.com", password: "koishor" },
  ],
});

Update

Update a data existing data

import { sql } from "./database";

await sql.update({
  model: "users",
  data: { name: "name updated" },
  where: {
    name: "mahi",
  },
});

Delete

Delete a data with the easiest way

import { sql } from "./database";

await sql.delete({
  model: "users",
  where: {
    name: "name updated",
  },
});

Inspiration

We get the inspiration of this project from Mongoose, Sequlize. There are an awesome ORM. They have a tungs of features to manupulate data.

Package Sidebar

Install

npm i awesome-sql

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

36.1 kB

Total Files

7

Last publish

Collaborators

  • mahikaishar