定义两个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. html网页如何使用哪种浏览器内核渲染的选择

    众所周知,国内的浏览器基本都是双内核的(ie(Trident)+webkit):而且基本默认时都是用webkit内核.尽管IE浏览器体验差,但是有时也会需要用IE内核来渲染的(比如银行网站). 如果要 ...

  2. MySQL三层循环

    begindeclare i int;  #定义i变量declare j int;  #定义j变量declare k int;  #定义k变量set i=1;set j=1;set k=1;while ...

  3. 牛客网多校第3场C-shuffle card 平衡树或stl(rope)

    链接:https://www.nowcoder.com/acm/contest/141/C 来源:牛客网 题目描述 Eddy likes to play cards game since there ...

  4. debug makefile 及 lint 软件质量软件

    make -d should give you more than enough information to debug your makefile. Be warned: it will take ...

  5. Database Administration Statements

    MySQL 5.5 Reference Manual  /  SQL Statement Syntax  /  Database Administration Statements  /  Table ...

  6. golang结构体、接口、反射

    struct结构体 struct用来自定义复杂数据结构,可以包含多个字段属性,可以嵌套; go中的struct类型理解为类,可以定义方法,和函数定义有些许区别; struct类型是值类型. struc ...

  7. L2-016. 愿天下有情人都是失散多年的兄妹(深搜)*

    L2-016. 愿天下有情人都是失散多年的兄妹 参考博客 #include<iostream> #include<cstdio> #include<cstring> ...

  8. [转]腾讯研发类笔试面试试题(C++方向)

     https://blog.csdn.net/Xiongchao99/article/details/73381280 1.C和C++的特点与区别? 答:(1)C语言特点:1.作为一种面向过程的结构化 ...

  9. 使用pip命令自动生成项目安装依赖清单

    Python项目中经常会带requirements.txt文件,里面是项目所依赖的包的列表,也就是依赖关系清单,这个清单也可以使用pip命令自动生成. pip命令: 1 pip freeze > ...

  10. 未能加载或程序集“XXXX,Version=0.0.0.0,Culter=neutral,PublicKeyToken=null”或它的某一个依赖项。试图加载格式不正确的程序。

    问题描述:在VS中运行一个C#程序,出现错误: 未能加载或程序集“XXXX,Version=0.0.0.0,Culter=neutral,PublicKeyToken=null”或它的某一个依赖项.试 ...