up
This commit is contained in:
+44
-2
@@ -1,14 +1,56 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
doc : "",
|
||||
doc : "默认页面",
|
||||
path : "/",
|
||||
method : ["get", "post"],
|
||||
middleware: [],
|
||||
params : {},
|
||||
return : {},
|
||||
controller: async (ctx, app) => {
|
||||
// app.err.ParameterException()
|
||||
app.event.emit('test.event2')
|
||||
const where = {
|
||||
// id: 4
|
||||
}
|
||||
const data = {
|
||||
// id: 1,
|
||||
uid: "77",
|
||||
}
|
||||
|
||||
ctx.body = 'index,xe:' + app.utils.VERSION
|
||||
// const User = await app.table("User").where(where).findAll()
|
||||
// const User = await app.table("User").time(["2022-04-9", "2022-04-10"]).findAll()
|
||||
// const User = await app.table("User").where(where).findOrCreate(data)
|
||||
// const {count, rows} = await app.table("User").where(where).findAndCountAll()
|
||||
// const User = await app.table("User").save(data)
|
||||
// const res = {
|
||||
// "创建单个数据" : await app.table("User").data({uid: "6666"}).save(),
|
||||
// "查询单个数据" : await app.table("User").where({id: 2}).find(),
|
||||
// "查询单个数据,不存在就创建" : await app.table("User").where({id: 999}).data({uid: "6666"}).findOrCreate(),
|
||||
// "查询所有数据" : await app.table("User").where({uid: "6666"}).findAll(),
|
||||
// "查询所有数据(时间区间)" : await app.table("User").time(['2022-04-09', '2022-04-10']).findAll(),
|
||||
// "查询所有数据(当月数据)" : await app.table("User").time('month').findAll(),
|
||||
// "查询所有数据(30分钟内的数据)": await app.table("User").time(30).findAll(),
|
||||
// "查询所有数据(分页)" : await app.table("User").where({uid: "6666"}).page(1).limit(1).findAll(),
|
||||
// "查询所有数据+总行数(分页)" : await app.table("User").where({uid: "6666"}).page(1).limit(1).findAndCountAll(),
|
||||
// }
|
||||
|
||||
/*
|
||||
await app.setTransaction() // 设置事务
|
||||
await app.table("User").data({uid: "6666"}).save()
|
||||
await app.table("User").where({id: 2}).find()
|
||||
await app.table("User").data({uid: "6666"}).save()
|
||||
await app.table("User").where({id: 2}).find()
|
||||
await app.commitTransaction() //提交事务,如果设置了事务不提交,任务不会执行
|
||||
*/
|
||||
|
||||
// await app.table("User").where({id: 1032}).data({age: 1}).setInc() // 字段值+1
|
||||
// await app.table("User").where({id: 1032}).data({age: 2}).setInc() // 字段值+2
|
||||
// const {res, value} = await app.table("User").where({id: 1032}).data({age: 2}).setDec(0) // 字段值-2,不能低于0,如果低于0返回false
|
||||
// const {res, value} = await app.table("User").where({id: 1032}).data({age: 2}).setDec(0,10) // 字段值-2,不能低于0,如果低于0设置为10
|
||||
const {res, value} = await app.table("User").where({id: 1032}).data({age: 2}).setInc(20, 10) // 字段值+2,不能大于20,如果大于20设置为10
|
||||
|
||||
|
||||
ctx.body = {res, value}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user