sails怎么把数据导入到mysql

sails怎么把数据导入到mysql,第1张

sails怎么把数据导入到mysql

Node.js非常适用于Web开发,但是现在无论是一个网站,还是Web App都已经成为包括很多不同部分,如前端、数据库、业务模块、功能模块等等的大型项目,使用Node.js从零开始进行Web开发,也许大中型团队能够 胜任,但对于个人和小型团队来说是不现实的。这时候框架就成为Web开发利器,对于个人开发来说几乎是必不可少。

一、安装时:

先装nodejs,成功标志 node -v

安装sails 全局安装 node install sails@version -g 安装成功 sails -v

创建 项目 sails new projectname

安装grunt : npm install grunt@version --save-dev(在项目的目录中)

启动sails服务:sails lift

在启动时提示的错误,可以用 npm install 在当前的项目下进行安装。

在创建api时用命令:sails generate api book(在安装后很可能sails lift时会出现错误,此次的处理是npm install sails-config --save-dev

测试浏览:http://localhost:1337/user 创建http://localhost:1337/user/create?name=xy&password=fc12345

note:to avoid the migration warning from sails when generating the book api,add the following to config/env/development.js

models:{

migrate:"alter"

}

二、文件夹:

assets下可以放直接被url调用的网页,图片,js,等文件,url http://localhost:1337/在assets下的路径。

三、路由

config/routes.js

'/':{view:'homepage'} localhost:1337

'/about':{view:'about'} localhost:1337/about 在views下创建 about.ejs

路由蓝图包括以下三种:

restful路由

These routes always have the path of /:modelName or /:modelName/:id

and send the request to the appropriate action by using the HTTP "verb".Middleware policies should be used in a production environment to protect these routes fromuauthorized access.

shortcut路由

these routes only respod to "get" requests and determine which action to send the request to by decoding the path.An example path would look like

/:modelName/<action>and data would be passed to the controller action using query parameters. While great for development work o a prototype,these routes should be disabled in production.

action路由

Thes routes create shortcut routes for custom actions tat don't come for free as part of the restful routes.So for any custom action on a controller,a corresponding path followingthe format /:controllerName/:actionName whill respond to get requests and send the request to the controller.

Blueprit Actions

The Blueprint API creates a number of generic actions tohandleall of the standard behaviour of a restful JSON API to match the BluePrint routes.The following default controller actions,which can be overridden,are provided by the Blueprint api:

find findOne create update destory populate add remove

如何使用 http verb?

'get /posts':{

controller:'postsController',

actio:'list'

}

这个配置告诉应用对get 的请求做出回应,在url处理方式为postscontroller下的list *** 作。

‘put /posts/:id':{

controller: 'postsController',

action:'update'

}

这个配置对put请求做出回应,更新一个已存在的用户,其中id为参数,update是postsController中的一个 *** 作。

如何更改模板?

1.用jade 代替 Ejs

npm install jade --save

更改config/views.js文件:

module.exports.views={

engine:'jade',

layout:fasle,这个只有ejs支持,所以换成jade后,要把layout设为false

locals:{//any options you would like to pass to the jade parser}

}

最后从package.json中移走ejs

样式文件的替换用sass 替换 less

1.把grunt-contrib-less从age.json中移走,npm install grunt-contrib-sass --save

2.改变所有Grunt task 中的less 引用为 sass.(需要改变的有如下文件)

tasks/cofig/copy.js

tasks/register/compileAssets.js

tasks/register/syncAssets.js

其实如果是新项目了只需更改 tasks/importer.less为importer.sass,其它的都由Sass自动适配。

用postgres 代替LocalDB

waterline (与许多流行的数据库一起工作)(如:Postgresql,MongoDB,Redis.)


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/9996868.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-04
下一篇 2023-05-04

发表评论

登录后才能评论

评论列表(0条)

保存