定义两个model,一个给get的,一个给post的

var Sequelize = require('sequelize');

const DeviceNos = sequelize.define('DeviceDetail',
{
DeviceNo: {
type: Sequelize.INTEGER
}
},
{
tableName: 'DeviceDetail',
timestamps: false,
freezeTableName: true
}) const Device = sequelize.define('DeviceDetail',
{
DeviceNo: {
type: Sequelize.INTEGER
},
Tem: {
type: Sequelize.FLOAT,
get() {
return this.getDataValue("Tem").toFixed(2);
}
},
Hum: {
type: Sequelize.FLOAT,
get() {
return this.getDataValue("Hum").toFixed(2);
}
},
Lng: {
type: Sequelize.FLOAT,
get() {
return this.getDataValue("Lng").toFixed(2);
}
},
Lat: {
type: Sequelize.FLOAT,
get() {
return this.getDataValue("Lat").toFixed(2);
}
}, ServiceTime: {
type: Sequelize.DATE,
get() {
return moment(this.getDataValue('ServiceTime')).format('YYYY-MM-DD HH:mm:ss');
}
}
}, {
tableName: 'DeviceDetail',
timestamps: false,
freezeTableName: true
});

定义运算符

const Op = Sequelize.Op;

定义get/Post方法

router.post('/searchDeviceRecord', async function (ctx, next) {
let deviceNo = ctx.request.body.deviceNo;
let st = ctx.request.body.st;
let et = ctx.request.body.et;
console.log(st);
try {
var data = await Device.findAll({
attributes: ['DeviceNo', 'Tem', 'Hum', 'Lng', 'Lat', 'ServiceTime'],
where: {
deviceNo: deviceNo,
serviceTime: {
[Op.lte]: et,
[Op.gte]: st
}
},
order: [['ServiceTime', 'ASC']]
})
ctx.body = JSON.stringify(data);
} catch (e) {
console.log(e);
}
}); router.get('/getDeviceList', async function (ctx, next) {
try {
var data = await DeviceNos.findAll({
attributes: [[sequelize.literal('distinct DeviceNo'), 'DeviceNo']], order: [['DeviceNo', 'ASC']]
})
ctx.body = JSON.stringify(data);
} catch (e) {
console.log(e);
} });

sequelize的get/post方法例子的更多相关文章

  1. Try finally的一个实验和为什么避免重载 finalize()方法--例子

    public class TryFinallTest { public TryFinallTest(){ } public void runSomething(String str){ System. ...

  2. 2种实现CXF方法例子

    转载自:http://www.blogjava.net/sai5201314vicky/articles/353078.html 大家好,今天我要介绍的现实webservice的一种技术——CXF 由 ...

  3. sequelize常见操作使用方法

    关于sequelize的准备工作这里不再赘述. 一.引入sequelize模块 var Sequelize = require('sequelize'); 二.连接数据库 var sequelize  ...

  4. HTML5 API—无刷新更新地址 history.pushState/replaceState方法(例子) (转)

    尽管是上面讲到的<JavaScript高级程序设计>(第二版)中提到,BOM中的location.path/query…… (window.location)在通过JavaScript更改 ...

  5. Appium 定位方法例子(4)

    有朋友留言反应定位不到元素,没错,船长也为这个一直在头疼,我用的App是原生安卓+webService+h5类型的,定位虽然没问题,但是在进行操作的时候各种不通过……真的很头疼啊……我这里说的“操作” ...

  6. JQuery调用iframe子页面函数/对象的方法例子

    父页面有个ID为mainfrm.name为Iframe1的iframe,iframe连接b.html,该页面有个函数test 在父页面调用b.html的test方法为: $("#mainfr ...

  7. python_103_属性方法例子

    class Flight(object): def __init__(self,name): self.flight_name = name def checking_status(self): pr ...

  8. pyqt 动态显示时间方法例子学习

    # -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' import sys,datetime from PyQt4.QtC ...

  9. VHDL设计时参数定义的方法 例子

    -- SPtb LIBRARY ieee; USE ieee.std_logic_1164.ALL; USE IEEE.STD_LOGIC_ARITH.ALL; USE IEEE.STD_LOGIC_ ...

随机推荐

  1. Otto.de:我为什么选择分布式垂直架构

    Otto.de:我为什么选择分布式垂直架构 http://cloud.51cto.com/art/201510/493867.htm

  2. Windows 独立启动方式安装 Archiva

    在 Windows 中以独立启动方式安装. 你可以将安装文件拷贝到任何你希望运行的目录中,下面的步骤中.我们没有将 Archiva 安装成服务,所以你需要通过控制台的方式来进行启动. Windows ...

  3. regex-ways

    regex的分组与捕获:分组就是用小括号(str)括起来的东西,就是一个分组.要想得到这些分组的信息,就要想办法捕获.每个分组都有编号,编号规则是从外向内,从左至右. .例如,在表达式 (A)(B(C ...

  4. 3. Longest Substring Without Repeating Characters无重复字符的最长子串

    网址:https://leetcode.com/problems/longest-substring-without-repeating-characters/ 显然采用sliding window滑 ...

  5. IIS+NGINX 负载web服务器

    Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行.其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在 ...

  6. Qt使用std::sort进行排序

    参考: https://blog.csdn.net/u013346007/article/details/81877755 https://www.linuxidc.com/Linux/2017-01 ...

  7. unity中将多个图片进行椭圆排序

    //保存需要排序的精灵容器 public GameObject[] Sprites; public Transform centrePoint;//椭圆的中心点 ;//每个方块间的角度偏移 //保存位 ...

  8. Python *Mix_w

    Python的历史起源: 1989年圣诞节期间,由吉多.范罗苏姆创始. Python的优点"优美""明确""简单" python是一门解释型 ...

  9. Xcode10 library not found for -lstdc++ 找不到问题

    在Xcode9上正常编译的项目,在Xcode10上编译可能会遇到如下错误: library not found library not found library not found for -lst ...

  10. squid代理

    概念    高性能dialing服务软件,作为前置缓存服务,用于替代用户向网站服务器请求页面数据并进行缓存.    默认占用端口3128.3401.4827    分类    从作用分类       ...