Socket
Book a DemoInstallSign in
Socket

mysql-model-router

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mysql-model-router

Generative API Creation using mysql2 and express libraries in node js

0.1.9
latest
Source
npmnpm
Version published
Weekly downloads
14
-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

mysql-model-router

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 };

Keywords

mysql2

FAQs

Package last updated on 21 Apr 2025

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.