1.0.13 • Published 2 years ago

tiny-mysql-orm v1.0.13

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

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

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago