my-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 MyAwesomeSql in your project.

pnpm install my-awesome-sql

Examples

Create Connection

Create a connection with your database.

// database.ts
import myAwesomeSql from "my-awesome-sql";

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

Select

Selecting is the amazing fact of MyAwesomeSql.

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 myAwesomeSql 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 MyAwesomeSql 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 my-awesome-sql

Weekly Downloads

1

Version

0.0.3

License

MIT

Unpacked Size

35.7 kB

Total Files

8

Last publish

Collaborators

  • mdmahikaishar001