
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
mysql-model-router
Advanced tools
Generative API Creation using mysql2 and express libraries in node js
Generative API Creation using mysql2 and express libraries in node js
const { db, model,route } = require("mysql-model-router");
db.connect({
connectionLimit: 100,
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
port: process.env.DB_PORT,
charset: "utf8mb4",
});
let test = model( db,
"test", //table name
{//table data structure
test_id: "required|integer",
user_id: "required|integer",
name: "required|string",
description: "required|string",
type: "required|integer",
info: "required|object",
is_deleted: "boolean"
},
"test_id",//primary key/ auto increment key
[],//array of columns which makes the row unique
{ safeDelete: "is_deleted" }//column used to declare safe delete option
)
app.use("/test", route(test),{"user_id":"session.user.user_id"}); // create 8 endpoints with overides to filter data based on user_id,tenant_id from request session
Induvidual
GET /:id
POST /:id
PUT /:id
DELETE /:id
Bulk
GET /
POST /
PUT /
DELETE /
/* filter=[[["column_name",condition","value],["column_name","condition","value"]],[["column_name",condition","value],["column_name","condition","value]]] conditions to support =,like,in,<,>,<=,>=,!=
1st Array is OR 2nd Array is AND 3rd Array is Conditional
*/
/module/test.js
const {route,model} = require("./index.js");
const testModel = model(db,
"test",
{
test_id: "INTEGER",
name: "STRING",
description: "STRING",
type: "INTEGER",
info: "JSON",
},
"test_id",
"name",
[],
{
session: ["user"]["user_id"],
});
model["customFunction"] = async (a,b,c) =>{
};
const testRoute =route(db,
"test",
{
test_id: "INTEGER",
name: "STRING",
description: "STRING",
type: "INTEGER",
info: "JSON",
},
"test_id",
"name",
[],
{
session: ["user"]["user_id"],
});
testRoute.post("/",(req,res)=>{
})
module.exports = {route:testRoute,model:testModel };
FAQs
Generative API Creation using mysql2 and express libraries in node js
The npm package mysql-model-router receives a total of 13 weekly downloads. As such, mysql-model-router popularity was classified as not popular.
We found that mysql-model-router demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.