A light weight awesome sql sdk with promises and typescript.
To tnstall AwesomeSql
in your project.
pnpm install awesome-sql
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",
});
Selecting is the amazing fact of AwesomeSql
.
import { sql } from "./database";
await sql.select({
model: "posts",
columns: ["id", "title", "createdAt"],
where: {
id: 1,
},
});
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" },
},
],
});
Inserting on awesomeSql
is so easy.
import { sql } from "./database";
await sql.insert({
model: "users",
data: [{ name: "mahi", email: "mahi@gamil.com", password: "mahi" }],
});
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 a data existing data
import { sql } from "./database";
await sql.update({
model: "users",
data: { name: "name updated" },
where: {
name: "mahi",
},
});
Delete a data with the easiest way
import { sql } from "./database";
await sql.delete({
model: "users",
where: {
name: "name updated",
},
});
We get the inspiration of this project from Mongoose, Sequlize. There are an awesome ORM. They have a tungs of features to manupulate data.