node.js---sails项目开发(5)---用户表的建立
1、 ctrl+c 暂停sails项目 ,输入如下命令,创建一个user表
sails generate api user
2、在api目录分别建立了两个文件 api/controllers/UserController.js api/modes/User.js
修改文件 api/modes/User.js
/**
* User.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs :: http://sailsjs.org/documentation/concepts/models-and-orm/models
*/ module.exports = { attributes: {
// 站点名称
siteName: {
type: 'string',
required: true,
minLength:1,
maxLength:10
},
// 邮箱
email: {
type: 'email',
unique: true,
required: true
},
// 密码
password: {
type: 'string',
required: true
},
// 站点简介
siteDesc: {
type: 'string',
defaultsTo: '暂无简介',
maxLength:40
},
// 是否管理员(默认为非管理员)
isAdmin: {
type: 'boolean',
defaultsTo: false
}
}
};
3、打开如下连接向User表中插入一条数据
http://localhost:1337/user/create?siteName=lishenggen&email=275606870@qq.com&password=123456&siteDesc=description&isAdmin=true
页面将出入如下信息
{
"siteName": "lishenggen",
"email": "275606870@qq.com",
"password": "123456",
"siteDesc": "description",
"isAdmin": true,
"createdAt": "2016-04-26T09:19:53.600Z",
"updatedAt": "2016-04-26T09:19:53.600Z",
"id": "571f32b9b9d7e6e7041ad738"
}
4、接下来我们打开数据库看看,依次输入如下命令 step1 连接数据库 step2 检索当前库中所有的表,step3 查询user表中所有记录,加了pretty()的意思是格式化输出,pretty()可加,可不加
mongo 127.0.0.1/sails -u test -p test
show tables
db.user.find({}).pretty()
这时我们在终端可以看到可以打印出如下信息
{
"_id" : ObjectId("571f32b9b9d7e6e7041ad738"),
"siteName" : "lishenggen",
"email" : "275606870@qq.com",
"password" : "123456",
"siteDesc" : "description",
"isAdmin" : true,
"createdAt" : ISODate("2016-04-26T09:19:53.600Z"),
"updatedAt" : ISODate("2016-04-26T09:19:53.600Z")
}
好了,我们成功写入一条数据进去,是不是很方便???
node.js---sails项目开发(5)---用户表的建立的更多相关文章
- Node JS后端项目开发与生产环境总结
原文地址:Node JS后端项目开发与生产环境总结 Node JS常用后端框架有express.koa.sails.国产框架有个egg js,已经在cnode投入生产了,还有个think js,类似t ...
- 前端(Node.js)(3)-- Node.js实战项目开发:“技术问答”
1.Web 与 Node.js 相关技术介绍 1.1.Web应用的基本组件 web应用的三大部分 brower(GUI)<==>webserver(business logic.data ...
- Node.js 从零开发 web server博客项目[安全]
web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...
- Node.js 从零开发 web server博客项目[登录]
web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...
- Node.js 从零开发 web server博客项目[项目介绍]
web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...
- Node.js 从零开发 web server博客项目[express重构博客项目]
web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...
- Node.js 从零开发 web server博客项目[数据存储]
web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...
- Node.js 从零开发 web server博客项目[koa2重构博客项目]
web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...
- Node.js 从零开发 web server博客项目[日志]
web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...
- Node.js 从零开发 web server博客项目[接口]
web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...
随机推荐
- PHP学习笔记(12)分页技术
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- python from import 自定义模块
from douban250.items import Douban250Item python import 自定义模块 (1)主程序与模块程序在同一目录下: 如下面程序结构: `-- src ...
- springboot查找配置文件路径的过程
spring加载配置文件是通过listener监视器实现的,在springboot启动时: 在容器启动完成后会广播一个SpringApplicationEvent事件,而SpringApplicati ...
- jfinal_BLOG v1.0
http://git.oschina.net/fleam/jfinal_AmazeUI
- 安装loadrunner时出现”命令行选项语法错误键入命令 \?获得帮助“的解决方法
安装LR11 时,安装Microsoft Visual c++2005 sp1运行时组件,就会提示命令行选项语法错误,键入“命令/?”可获取帮肋信息1.进入loadrunner-11\Addition ...
- Install EPEL repo on CentOS 7 / RHEL 7
On CentOS 7, we have found without downloading the epel-release RPM package(as we used to do on prev ...
- websphere web.xml
解决WAS更新web.xml文件不生效的问题(web_merged.xml是罪魁祸首) 问题原因分析 近日碰到更新web.xml文件到WAS服务器(WebSphere Application Se ...
- vim 命令大全(写的非常全和好)http://blog.csdn.net/woshixiaosimao/article/details/54312738
下文转自链接.由原作者陈皓译自<Learn ViM Progressively>,非常不错. ——————————正文开始—————————— 你想以最快的速度学习人类史上最好的文本编辑器 ...
- JVM命令行工具&垃圾收集器&垃圾收集策略思维导图
1.JVM命令行工具 2.垃圾回收算法 3.垃圾收集器
- 【C语言天天练(二)】预处理
引言: 学C语言之初.一提到预处理,脑子里想到的就是#define的宏定义以及#include包括的头文件.后来随着对C的深入学习发现.预处理不止这些.比方条件编译.提前定义的宏等等.以下对此进行总结 ...