Socket
Socket
Sign inDemoInstall

tiny-mysql-orm

Package Overview
Dependencies
12
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    tiny-mysql-orm

A Module for handling mysql queries.


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
1.24 MB
Created
Weekly downloads
 

Readme

Source

In the name of ALLAH

This is a simple module that connecto to mysql and handle mysql queries. for now this module support creating database and tables and insert query.

How to use:

just import to your project and create an object like this:

const MysqlHandler = require("tiny-mysql-orm").MysqlHandler;
const mysql_handler = new MysqlHandler(host_info, create_db, tables, dev_status);//have 4 arguments, 
				//argument 1- a json obj {host: host_address, user:db_user, password: user_password, database: database_name}
			 	//argument 2- a boolean, default is false, if your turn it to true, mysql handler module create your database
			 	//argument 3- an array of json like this [{name:"", columns:[{name:"", type:""}]}] for creating your tables, you can find more info about this argument below, for now if you don't want to module create your tables just send an empty array like this []
			 	//argument 4- a boolean, default is false, this set developer mode for showing some logs

A real example of arguments:

var host_info = {host: "localhost", user: "db_user", password: "my_user_password", database: "user"};
var create_db = true;
var tables = [
	{
		name:"user", 
		columns:
		[
			{name: "id", type:"INT NOT NULL AUTO_INCREMENT"}, 
			{name: "mobile", type:"VARCHAR(16)"},
			{name: "presenter", type:"VARCHAR(16)"},
			{name: "name", type:"VARCHAR(128)"},
			{name: "creation", type: "TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP"},
			{name: "about_me", type:"TINYTEXT"},
			{name: "birthday", type:"DATE"},
			{name: "profile_img", type:"VARCHAR(128)"}
		],
		unique: ["mobile"]
	}
];

note: if you turn true creation of tables, module add id column to all of tables and make it auto increament.

var dev_status = true;

tiny-mysql-orm for now have one async methods, insert().

insert method get an argument { table:"", columns: ["",], values:[[{type:"", value:""},],]} like this example:

var query = {
	database_name: "database_name",
	table:"user", 
	columns: ["mobile"], 
	values:[
		[
			{type:"varchar", value: "user_mobile"}
		]
	]
};
mysql_handler.insert(query).then((val)=>{console.log(val);}).catch((err)=>{console.log(err)});


Keywords

FAQs

Last updated on 03 Aug 2022

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc