Tool mysql
Mysql용 쿼리 빌더입니다. npm으로 배포 되고 있습니다.
Feature
Install
npm install tool-mysql
Quick start
const toolMysql = require('./tool-mysql');
const tableConfig = {
tableName: "product_order",
reference: [
{
tableName: "product",
keyColumns: ["product_category", "product_id"],
columns: ["category", "id"],
options: [
{
actionName: "update",
optionValue: "cascade"
},
{
actionName: "delete",
optionValue: "restrict"
}
]
},
{
tableName: "customer",
keyColumns: ["customer_id"],
columns: ["id"]
}
],
columnData: [
{
name: "no",
ai: 1,
primaryKey: 1
},
{
name: "product_category",
},
{
name: "product_id",
index: 1,
},
{
name: "customer_id",
index: 1,
}
]
}
let query = toolMysql.createTable(tableConfig);
Return Values
CREATE TABLE IF NOT EXISTS `product_order` (
`no` INT NOT NULL AUTO_INCREMENT ,
`product_category` INT NOT NULL ,
`product_id` INT NOT NULL ,
`customer_id` INT NOT NULL ,
PRIMARY KEY (`no`),
KEY `index_product_id` (`product_id`),
KEY `index_customer_id` (`customer_id`),
FOREIGN KEY (`product_category`, `product_id`)
REFERENCES `product`(`category`, `id`)
ON UPDATE CASCADE ON DELETE RESTRICT,
FOREIGN KEY (`customer_id`)
REFERENCES `customer`(`id`)
) ENGINE = innoDB
Input table config
{
"tableName": {table_name},
"character": {
"set": {table default charset},
"collate": {table collate}
},
"engine": {your table engine}
"comment": {your table comment},
"reference": [
{
"tableName": {reference_table_name},
"columns": [{reference_column_name1}, {reference_column_name2}...],
"keyColumns": [{key_column_name1}, {key_column_name2}...],
"options": [
{
"actionName": {action name},
"optionValue": {option value}
}
]
}
],
"columnData": [
{
"name": {column name},
"type": {
"name": {type},
"size": {type size}
},
"character": {
"set": {column charset},
"collate": {column collate}
},
"primaryKey": {primary key flag},
"default": {default value},
"null": {default null flag},
"ai": {auto increment flag},
"index": {column index flag},
"comment": {your column comment}
}
]
}