0.0.3 • Published 2 years ago
my-awesome-sql v0.0.3
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-sqlExamples
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.