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 ...
随机推荐
- NPOI 导出Excel图片 (网络)
导出网络图片,需要将网络图片下载到本地或者内存流中,建议下载的时候使用缩略图: 高清图片效率慢: Uri uri = new Uri(imgPath); //imgPath :网络图片地址 WebRe ...
- 查看和修改Oracle数据库服务器端的字符集
Oracle数据库查看和修改服务器端的字符集的方法是本文主要要介绍的内容,接下来救让我们一起来了解一下这部分内容. A.oracle server 端字符集查询 select userenv('lan ...
- Android CoordinatorLayout 入门介绍
Android CoordinatorLayout 入门介绍 CoordinatorLayout View 知道如何表现 在 2015 年的 I/O 开发者大会上,Google 介绍了一个新的 And ...
- Retrofit--官网2.1.0
Retrofit--官网2.1.0 android Retrofit 介绍 API 描述 请求方法 URL 处理 请求体 表单的 ENCODED 和 MULTIPART HEADER 处理 同步 VS ...
- jQuery 实战读书笔记之第二章:选择元素
基本选择器 html 代码如下,后面的 js 使用的 html 基本大同小异. <!doctype html> <html> <head> <title> ...
- 【转】Python 第三方 http 库-Requests 学习
原文地址:http://www.itwhy.org/%E8%BD%AF%E4%BB%B6%E5%B7%A5%E7%A8%8B/python/python-%E7%AC%AC%E4%B8%89%E6%9 ...
- Enterprise Architect UML建模
UML建模 前言 UML建模资料已经很多了,有人想用有人不用,有人会用也有人不会用,本文只是作者的一篇UML建模总结,不想去写太细,因为真正的你去用下,去画下就基本都会了.工具毕竟是工具,设计和思想才 ...
- 【BZOJ】3432: [Usaco2014 Jan]Cross Country Skiing (bfs+二分)
http://www.lydsy.com/JudgeOnline/problem.php?id=3432 题目说要相互可达,但是只需要从某个点做bfs然后判断其它点是否可达即可. 原因太简单了.... ...
- datagrid带查询带分页
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=&qu ...
- nginx已经启动 无法访问页面
通过IP访问,可以看到 welcome nginx 的提示 下面我重启linux服务器,重启后通过ip访问,死活连接不上了?没办法了,只有在百度和google 最后发现问题不是出在nginx上,而是 ...