我从SailsJS
和MySQL
开始,我的数据库中有很多表。所以,我不知道在SailsJS
中有一个工具可以从Database First
Entity Framework
ASP
中的sDefaultAttribNameToSemanticMap["ciPosition"] = geom::Attrib::POSITION;
sDefaultAttribNameToSemanticMap["ciNormal"] = geom::Attrib::NORMAL;
sDefaultAttribNameToSemanticMap["ciTangent"] = geom::Attrib::TANGENT;
sDefaultAttribNameToSemanticMap["ciBitangent"] = geom::Attrib::BITANGENT;
sDefaultAttribNameToSemanticMap["ciTexCoord0"] = geom::Attrib::TEX_COORD_0;
sDefaultAttribNameToSemanticMap["ciTexCoord1"] = geom::Attrib::TEX_COORD_1;
sDefaultAttribNameToSemanticMap["ciTexCoord2"] = geom::Attrib::TEX_COORD_2;
sDefaultAttribNameToSemanticMap["ciTexCoord3"] = geom::Attrib::TEX_COORD_3;
sDefaultAttribNameToSemanticMap["ciColor"] = geom::Attrib::COLOR;
sDefaultAttribNameToSemanticMap["ciBoneIndex"] = geom::Attrib::BONE_INDEX;
sDefaultAttribNameToSemanticMap["ciBoneWeight"] = geom::Attrib::BONE_WEIGHT;
数据库生成模型
答案 0 :(得分:3)
您应该使用,自动生成现有的模型库DB非常好 https://www.npmjs.com/package/sails-generate-models
答案 1 :(得分:2)
SailsJS没有实施这样的工具。
尽管如此,自从MySQL SHOW COLUMNS FROM table
运行良好以来,自己创建它并不难。然后,您只需要创建.js模型文件。
警惕config/models.js
中的配置并将迁移设置为安全,因为如果您尚未经过测试,可能会删除某些列确定你是否正确生成了模型。
答案 2 :(得分:0)
Sails Inverse Model可帮助您从任何数据库构建模型,控制器和视图JS Sails。此外,您可以同时快速,单独地生成每个模型,视图,控制器或所有三个。
使用命令安装
npm install sails-inverse-model -g
了解工具
sails-inverse-model --help
Example:
$ mkdir sails-output
$ cd sails-output
$ sails-inverse-model -u postgres -p root -d almacen -t pg -m -v -c
User : postgres
Password : root
Database : almacen
Host : localhost
Models : /home/julian/Documents/sails-output/models
Views : /home/julian/Documents/sails-output/views
Controllers : /home/julian/Documents/sails-output/controllers
DB : pg
Schema (pg) : public
=====================================
Views [OK]
=====================================
Models [OK]
=====================================
Controllers [OK]
Note: Copy models => your/project_sails/api
Copy controllers => your/project_sails/api
Copy views/* => your/project_sails/views/
Then:
$ cd your/project_sails/
$ sails lift
More info: https://github.com/juliandavidmr/sails-inverse-model
---------------------------------------------------------------
Options:
-u, --user User of database
-p, --pass Password of database
-d, --database Database name
-h, --host Host server Default: localhost
-m, --models Folder output models Default: Folder actual
-c, --controllers Folder output controllers Default: Folder actual
-v, --views Folder output views Default: Folder actual
(Experimental)
-t, --type Type gestor database: mysql|postgres|mongodb Default: mysql
-s, --schema (Only PostgreSQL) Schema database postgres: Default: public
-f, --file (Only MySQL) .sql file path entry (Experimental)
====================== Individual generation ==================
You can quickly generate a model, a controller, a view or these three at the same time.
# Generate model
$ sails-inverse-model -g model --name Pet -a "name:string:r:u owner:string"
# Generate Controller
$ sails-inverse-model -g controller --name Pet -a "name:string:r:u owner:string"
# Generate View
$ sails-inverse-model -g view --name Pet -a "name:string:r owner:string"
# Generate all (Model, View and Controller)
$ sails-inverse-model -g all --name Pet -a "name:string:r:k owner:string"
Where:
--------------------------------------------
|Param | Description | Example |
|------|---------------|-------------------|
| r | Required | catname:string:r |
| u | Unique | catname:string:u |
| a | Autoincrement | index:integer:a |
| k | Primary Key | index:integer:k |
--------------------------------------------
You can also set all three parameters at the same time, for example: index:integer:a:u:r