code-auto v1.2.9
��# Code-auto
�Ǐ}T�NL�ꁨR9hncꁚ[IN!jgub�Nx�e�N
Install
*./codeAuto.js*
npm install code-auto
var codeAuto=require("code-auto");
const config = {
dialect: "mysql", penc�^{|�W�mysql�Postgres�Sqlite3�MSSQL �
port: '3306', �z�S��Nmysql�TPostgres �
host: "127.0.0.1", penc�^
g�RhV0W@W username: "root", penc�^&��S pwd: "password", penc�^�[x storage: "database", penc�^ T Templates: './codetpl', !jg�e�N9Y_ (!jg�[IN:N*.ct) codetype: "js" �Nx{|�W��Q�[columns�Sϑ-NCodeType � � c# || java || js � } codeAuto.run(config,function(err){ if(err){ throw new Error(err); } console.log("�[b") })
$node node codeAuto.js
�OV�
(WO(uCode-auto O���(WhQ@\�[ňcknx
OO(u�vpenc�^
Example for MySQL/MariaDB
npm install -g mysql
Example for Postgres
npm install -g pg pg-hstore
Example for Sqlite3
npm install -g sqlite
Example for MSSQL
npm install -g mssql
!jg�Qn�Sϑ
tableName�h�
T
columns�S_MRh��v@b gR
columns item:
name R
T type penc{|�W CodeType �Nx�QO(u�vpenc{|�W�9hncM�n�Nx{|�Wub� c# || java || js � � primaryKey (false || true) /f&T;N.� allowNull (false || true) /f&T�S�N:NNULL defaultValue ؞��<P
!jg�[IN
!jg�{�S+T(Wtemplate�Q�T�e(Wtemplate N�[INoutput^\'`ZP:Nub���Q
�O
<template output='./model'>
/* jshint indent: 2 */
module.exports = app => {
const sequelize = app.Sequelize;
const entity = {
{{#columns.forEach(function(column,index){ }}
{{column.name}}: {
type: {{column.CodeType}},
allowNull: {{column.allowNull}},
{{column.primaryKey?"primaryKey:"+column.primaryKey+",":""}}
{{column.autoIncrement?"autoIncrement:"+column.autoIncrement:""}}
}{{index==(columns.length-1)?'':','}}
{{# }); }}
}
const nav_cat = app.model.define('{{tableName}}', entity, {
tableName: '{{tableName}}'
});
{{tableName}}.getModel=model=>{
if(typeof model!=="object"){
throw new Error("��Bl�Spe���");
return false;
}
let newobj={};
for (var key in model) {
if (entity.hasOwnProperty(key)) {
newobj[key]=model[key];
}
}
return newobj;
}
return {{tableName}};
};
</template>