typespeed 0.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +34 -0
  3. package/dist/core.decorator.d.ts +18 -0
  4. package/dist/core.decorator.js +185 -0
  5. package/dist/core.decorator.js.map +1 -0
  6. package/dist/database.decorator.d.ts +24 -0
  7. package/dist/database.decorator.js +335 -0
  8. package/dist/database.decorator.js.map +1 -0
  9. package/dist/default/express-server.class.d.ts +15 -0
  10. package/dist/default/express-server.class.js +148 -0
  11. package/dist/default/express-server.class.js.map +1 -0
  12. package/dist/default/log-default.class.d.ts +6 -0
  13. package/dist/default/log-default.class.js +32 -0
  14. package/dist/default/log-default.class.js.map +1 -0
  15. package/dist/default/node-cache.class.d.ts +13 -0
  16. package/dist/default/node-cache.class.js +51 -0
  17. package/dist/default/node-cache.class.js.map +1 -0
  18. package/dist/default/pages/404.html +226 -0
  19. package/dist/default/pages/500.html +713 -0
  20. package/dist/default/read-write-db.class.d.ts +10 -0
  21. package/dist/default/read-write-db.class.js +66 -0
  22. package/dist/default/read-write-db.class.js.map +1 -0
  23. package/dist/default/redis.class.d.ts +5 -0
  24. package/dist/default/redis.class.js +32 -0
  25. package/dist/default/redis.class.js.map +1 -0
  26. package/dist/factory/cache-factory.class.d.ts +7 -0
  27. package/dist/factory/cache-factory.class.js +6 -0
  28. package/dist/factory/cache-factory.class.js.map +1 -0
  29. package/dist/factory/data-source-factory.class.d.ts +4 -0
  30. package/dist/factory/data-source-factory.class.js +6 -0
  31. package/dist/factory/data-source-factory.class.js.map +1 -0
  32. package/dist/factory/log-factory.class.d.ts +4 -0
  33. package/dist/factory/log-factory.class.js +6 -0
  34. package/dist/factory/log-factory.class.js.map +1 -0
  35. package/dist/factory/server-factory.class.d.ts +6 -0
  36. package/dist/factory/server-factory.class.js +9 -0
  37. package/dist/factory/server-factory.class.js.map +1 -0
  38. package/dist/route.decorator.d.ts +8 -0
  39. package/dist/route.decorator.js +87 -0
  40. package/dist/route.decorator.js.map +1 -0
  41. package/dist/typespeed.d.ts +12 -0
  42. package/dist/typespeed.js +39 -0
  43. package/dist/typespeed.js.map +1 -0
  44. package/package.json +39 -6
  45. package/src/core.decorator.ts +183 -0
  46. package/src/database.decorator.ts +342 -0
  47. package/src/default/express-server.class.ts +133 -0
  48. package/src/default/log-default.class.ts +19 -0
  49. package/src/default/node-cache.class.ts +39 -0
  50. package/src/default/pages/404.html +226 -0
  51. package/src/default/pages/500.html +713 -0
  52. package/src/default/read-write-db.class.ts +53 -0
  53. package/src/default/redis.class.ts +18 -0
  54. package/src/factory/cache-factory.class.ts +7 -0
  55. package/src/factory/data-source-factory.class.ts +4 -0
  56. package/src/factory/log-factory.class.ts +4 -0
  57. package/src/factory/server-factory.class.ts +6 -0
  58. package/src/route.decorator.ts +82 -0
  59. package/src/typespeed.ts +15 -0
  60. package/test/nodemon.json +6 -0
  61. package/test/package.json +18 -0
  62. package/test/src/aop-test.class.ts +29 -0
  63. package/test/src/config-development.json +15 -0
  64. package/test/src/config-production.json +15 -0
  65. package/test/src/config.json +46 -0
  66. package/test/src/custom-log.class.ts +26 -0
  67. package/test/src/entities/user-dto.class.ts +3 -0
  68. package/test/src/first-page.class.ts +46 -0
  69. package/test/src/main.ts +17 -0
  70. package/test/src/second-page.class.ts +43 -0
  71. package/test/src/test-database.class.ts +85 -0
  72. package/test/src/test-log.class.ts +9 -0
  73. package/test/src/test-orm.class.ts +74 -0
  74. package/test/src/user-model.class.ts +45 -0
  75. package/test/src/views/index.html +1 -0
  76. package/test/src/views/upload.html +14 -0
  77. package/test/static/favicon.ico +0 -0
  78. package/test/static/k.jpg +0 -0
  79. package/test/tsconfig.json +20 -0
  80. package/tsconfig.json +25 -0
@@ -0,0 +1,53 @@
1
+ import { createConnection, createPool } from "mysql2";
2
+ import DataSourceFactory from "../factory/data-source-factory.class";
3
+ import { bean, config } from "../core.decorator";
4
+
5
+ export default class ReadWriteDb extends DataSourceFactory {
6
+ private readonly readSession;
7
+ private readonly writeSession;
8
+
9
+ @bean
10
+ public getDataSource(): DataSourceFactory {
11
+ if (!config("mysql")) {
12
+ return null;
13
+ }
14
+ return new ReadWriteDb();
15
+ }
16
+
17
+ constructor() {
18
+ super();
19
+ const dbConfig = config("mysql");
20
+ if (dbConfig["master"] && dbConfig["slave"]) {
21
+ this.writeSession = this.getConnectionByConfig(dbConfig["master"]);
22
+ if (Array.isArray(dbConfig["slave"])) {
23
+ this.readSession = dbConfig["slave"].map(config => this.getConnectionByConfig(config));
24
+ } else {
25
+ this.readSession = [this.getConnectionByConfig(dbConfig["slave"])];
26
+ }
27
+ } else {
28
+ this.writeSession = this.getConnectionByConfig(dbConfig);
29
+ this.readSession = [this.writeSession];
30
+ }
31
+ }
32
+
33
+ private getConnectionByConfig(config: object) {
34
+ if (config["PoolOptions"] !== undefined) {
35
+ // we need pool
36
+ if (Object.keys(config["PoolOptions"]).length !== 0) {
37
+ config = Object.assign(config, config["PoolOptions"]);
38
+ }
39
+ return createPool(config).promise();
40
+ } else {
41
+ // only connection
42
+ return createConnection(config).promise();
43
+ }
44
+ }
45
+
46
+ public readConnection() {
47
+ return this.readSession[Math.floor(Math.random() * this.readSession.length)];
48
+ }
49
+
50
+ public writeConnection() {
51
+ return this.writeSession;
52
+ }
53
+ }
@@ -0,0 +1,18 @@
1
+ import { bean, config, log } from "../core.decorator";
2
+ import IoRedis from "ioredis";
3
+
4
+ export default class Redis extends IoRedis {
5
+
6
+ @bean
7
+ public getRedis(): Redis {
8
+ if (!config("redis")) {
9
+ return null;
10
+ }
11
+ return new Redis(config("redis"));
12
+ }
13
+
14
+ constructor(config: any) {
15
+ super(config);
16
+ }
17
+
18
+ }
@@ -0,0 +1,7 @@
1
+ export default abstract class CacheFactory {
2
+ public abstract get(key: string): any;
3
+ public abstract set(key: string, value: any, expire?: number): void;
4
+ public abstract del(key: string): void;
5
+ public abstract has(key: string): boolean;
6
+ public abstract flush(): void;
7
+ }
@@ -0,0 +1,4 @@
1
+ export default abstract class DataSourceFactory {
2
+ public abstract readConnection();
3
+ public abstract writeConnection();
4
+ }
@@ -0,0 +1,4 @@
1
+ export default abstract class LogFactory {
2
+ abstract log(message?: any, ...optionalParams: any[]) : void;
3
+ abstract error(message?: any, ...optionalParams: any[]) : void;
4
+ }
@@ -0,0 +1,6 @@
1
+ export default abstract class ServerFactory {
2
+ public app;
3
+ protected middlewareList: Array<any> = [];
4
+ public abstract setMiddleware(middleware: any);
5
+ public abstract start(port: number);
6
+ }
@@ -0,0 +1,82 @@
1
+ import * as express from "express";
2
+ import * as multiparty from "multiparty";
3
+ import { expressjwt } from "express-jwt";
4
+ import { getComponent } from "./core.decorator";
5
+
6
+ const routerMapper = {
7
+ "get": {},
8
+ "post": {},
9
+ "all": {}
10
+ };
11
+
12
+ const routerMiddleware = {};
13
+ function setRouter(app: express.Application) {
14
+ ["get", "post", "all"].forEach(method => {
15
+ for (let key in routerMapper[method]) {
16
+ let rounterFunction = routerMapper[method][key];
17
+ if (routerMiddleware[rounterFunction["name"]]) {
18
+ let args: Array<any> = [key, ...routerMiddleware[rounterFunction["name"]], rounterFunction["invoker"]];
19
+ app[method].apply(app, args);
20
+ } else {
21
+ app[method](key, rounterFunction["invoker"]);
22
+ }
23
+ }
24
+ });
25
+ }
26
+
27
+ function mapperFunction(method: string, value: string) {
28
+ return (target: any, propertyKey: string) => {
29
+ routerMapper[method][value] = {
30
+ "path": value,
31
+ "name": [target.constructor.name, propertyKey].toString(),
32
+ "invoker": async (req, res, next) => {
33
+ const routerBean = getComponent(target.constructor);
34
+ try {
35
+ const testResult = await routerBean[propertyKey](req, res);
36
+ if (typeof testResult === "object") {
37
+ res.json(testResult);
38
+ } else if (typeof testResult !== "undefined") {
39
+ res.send(testResult);
40
+ }
41
+ return testResult;
42
+ } catch (err) {
43
+ next(err)
44
+ }
45
+ }
46
+ }
47
+ }
48
+ }
49
+
50
+ function upload(target: any, propertyKey: string) {
51
+ const key = [target.constructor.name, propertyKey].toString();
52
+ if (routerMiddleware[key]) {
53
+ routerMiddleware[key].push(uploadMiddleware);
54
+ } else {
55
+ routerMiddleware[key] = [uploadMiddleware];
56
+ }
57
+ }
58
+
59
+ function uploadMiddleware(req, res, next) {
60
+ const form = new multiparty.Form();
61
+ form.parse(req, (err, fields, files) => {
62
+ req.files = files || undefined;
63
+ next();
64
+ });
65
+ }
66
+
67
+ function jwt(jwtConfig) {
68
+ return (target: any, propertyKey: string) => {
69
+ const key = [target.constructor.name, propertyKey].toString();
70
+ if (routerMiddleware[key]) {
71
+ routerMiddleware[key].push(expressjwt(jwtConfig));
72
+ } else {
73
+ routerMiddleware[key] = [expressjwt(jwtConfig)];
74
+ }
75
+ }
76
+ }
77
+
78
+ const getMapping = (value: string) => mapperFunction("get", value);
79
+ const postMapping = (value: string) => mapperFunction("post", value);
80
+ const requestMapping = (value: string) => mapperFunction("all", value);
81
+
82
+ export { getMapping, postMapping, requestMapping, setRouter, upload, jwt };
@@ -0,0 +1,15 @@
1
+ export * from "./core.decorator";
2
+ export * from "./route.decorator";
3
+ export * from "./database.decorator";
4
+
5
+
6
+ export { default as LogFactory} from "./factory/log-factory.class";
7
+ export { default as CacheFactory} from "./factory/cache-factory.class";
8
+ export { default as DataSourceFactory} from "./factory/data-source-factory.class";
9
+ export { default as ServerFactory} from "./factory/server-factory.class";
10
+
11
+ export { default as ExpressServer} from "./default/express-server.class";
12
+ export { default as LogDefault} from "./default/log-default.class";
13
+ export { default as NodeCache} from "./default/node-cache.class";
14
+ export { default as Redis} from "./default/redis.class";
15
+ export { default as ReadWriteDb} from "./default/read-write-db.class";
@@ -0,0 +1,6 @@
1
+ {
2
+ "watch": ["src", "test"],
3
+ "ext": "ts,json",
4
+ "ignore": ["src/**/*.spec.ts"],
5
+ "exec": "npm run test"
6
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "test-typespeed",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "scripts": {
6
+ "watch": "nodemon",
7
+ "test": "ts-node src/main.ts",
8
+ "start": "ts-node --transpile-only src/main.ts",
9
+ "build": "tsc -p ."
10
+ },
11
+ "author": "",
12
+ "license": "ISC",
13
+ "dependencies": {
14
+ "@types/node": "^18.0.6",
15
+ "tracer": "^1.1.6"
16
+ }
17
+ }
18
+
@@ -0,0 +1,29 @@
1
+ import { before, log, component, after } from "../../";
2
+ import FirstPage from "./first-page.class";
3
+
4
+ @component
5
+ export default class AopTest {
6
+
7
+ @before(FirstPage, "index")
8
+ public FirstIndex() {
9
+ log("Before FirstPage index run, at AopTest FirstIndex.");
10
+ log("AopTest FirstIndex run over." + this.getWordsFromAopTest());
11
+ return "FirstIndex";
12
+ }
13
+
14
+ public getWordsFromAopTest() {
15
+ return "getWordsFromAopTest";
16
+ }
17
+
18
+ @before(FirstPage, "getTestFromFirstPage")
19
+ public testGetTestFromFirstPage() {
20
+ log("AopTest testGetTestFromFirstPage run over.");
21
+ }
22
+
23
+ @after(FirstPage, "index")
24
+ public testFirstIndexAfter(result) {
25
+ log("AopTest testFirstIndexAfter run over, result: " + result);
26
+ log(result);
27
+ }
28
+
29
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "server": {
3
+ "port": "8081"
4
+ },
5
+ "database": {
6
+ "host": "localhost",
7
+ "port": "4455",
8
+ "name": "test"
9
+ },
10
+ "view": {
11
+ "engine": "mustache",
12
+ "path": "/test/views",
13
+ "suffix": "html"
14
+ }
15
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "server": {
3
+ "port": "8081"
4
+ },
5
+ "database": {
6
+ "host": "localhost",
7
+ "port": "27017",
8
+ "name": "test"
9
+ },
10
+ "view": {
11
+ "engine": "mustache",
12
+ "path": "./views",
13
+ "suffix": "html"
14
+ }
15
+ }
@@ -0,0 +1,46 @@
1
+ {
2
+ "view": {
3
+ "engine": "pug",
4
+ "path": "./views",
5
+ "suffix": "html"
6
+ },
7
+ "static": "/static",
8
+ "favicon": "/static/favicon.ico",
9
+ "compression": {
10
+ "level": 9
11
+ },
12
+ "cookie": {
13
+ "secret": "catme",
14
+ "options": {}
15
+ },
16
+ "session": {
17
+ "trust proxy": false,
18
+ "secret": "keyboard cat",
19
+ "resave": false,
20
+ "saveUninitialized": true,
21
+ "cookie": {
22
+ "secure": false
23
+ }
24
+ },
25
+ "mysql": {
26
+ "master": {
27
+ "host": "localhost",
28
+ "user": "root",
29
+ "password": "123456",
30
+ "database": "test"
31
+ },
32
+ "slave": [
33
+ {
34
+ "host": "localhost",
35
+ "user": "root",
36
+ "password": "123456",
37
+ "database": "test"
38
+ }
39
+ ]
40
+ },
41
+ "redis": {
42
+ "host": "localhost",
43
+ "port": "6379",
44
+ "db": 0
45
+ }
46
+ }
@@ -0,0 +1,26 @@
1
+ import * as tracer from "tracer";
2
+ import { bean, LogFactory } from "../../";
3
+
4
+ export default class CustomLog extends LogFactory {
5
+ private logger = tracer.console({
6
+ format: "[{{title}}] {{timestamp}} {{file}}:{{line}} ({{method}}) {{message}}",
7
+ dateformat: "yyyy-mm-dd HH:MM:ss",
8
+ stackIndex: 2,
9
+ preprocess: function (data) {
10
+ data.title = data.title.toUpperCase();
11
+ }
12
+ });
13
+
14
+ @bean
15
+ public createLog(): LogFactory {
16
+ return new CustomLog();
17
+ }
18
+
19
+ public log(message?: any, ...optionalParams: any[]) : void{
20
+ this.logger.log(message, ...optionalParams);
21
+ }
22
+
23
+ public error(message?: any, ...optionalParams: any[]) : void {
24
+ this.logger.error(message, ...optionalParams);
25
+ }
26
+ }
@@ -0,0 +1,3 @@
1
+ export default class UserDto {
2
+ constructor(public id: number, public name: string){}
3
+ }
@@ -0,0 +1,46 @@
1
+ //import * as jwttoken from "jsonwebtoken";
2
+ import { log, component, getMapping } from "../../";
3
+
4
+ @component
5
+ export default class FirstPage {
6
+
7
+ @getMapping("/first")
8
+ public index(req: any, res: any) {
9
+ log("FirstPage index running" + this.getTestFromFirstPage());
10
+ res.send("FirstPage index running");
11
+ }
12
+
13
+ @getMapping("/first/sendJson")
14
+ public sendJson() {
15
+ log("FirstPage sendJson running");
16
+ return {
17
+ "from": "sendJson",
18
+ "to": "Browser"
19
+ }
20
+ }
21
+
22
+ @getMapping("/first/sendResult")
23
+ public sendResult() {
24
+ log("FirstPage sendResult running");
25
+ return "sendResult";
26
+ }
27
+
28
+ @getMapping("/first/renderTest")
29
+ public renderTest(req: any, res: any) {
30
+ res.render("index", { name: "zzz" });
31
+ }
32
+
33
+ // @getMapping("/login")
34
+ // login() {
35
+ // const token = jwttoken.sign({ foo: 'bar' }, 'shhhhhhared-secret');
36
+ // /**
37
+ // * 将这里获得的token,放到header的Authorization中。
38
+ // * 值是:Bearer + token
39
+ // */
40
+ // return token;
41
+ // }
42
+
43
+ public getTestFromFirstPage() {
44
+ return "getTestFromFirstPage";
45
+ }
46
+ }
@@ -0,0 +1,17 @@
1
+ import { app, log, autoware, ServerFactory } from "../../";
2
+ //import * as basicAuth from "express-basic-auth"
3
+
4
+ @app
5
+ class Main {
6
+
7
+ @autoware
8
+ public server : ServerFactory;
9
+
10
+ public main(){
11
+ // this.server.setMiddleware(basicAuth({
12
+ // users: { 'admin': 'supersecret' }
13
+ // }));
14
+ this.server.start(8081);
15
+ log('start application');
16
+ }
17
+ }
@@ -0,0 +1,43 @@
1
+ import { getMapping, postMapping, upload, jwt, log, component } from "../../";
2
+
3
+ @component
4
+ export default class SecondPage {
5
+
6
+ @getMapping("/second/setCookie")
7
+ setCookiePage(req, res) {
8
+ res.cookie("name", "zzz");
9
+ return "setCookie";
10
+ }
11
+
12
+ @getMapping("/second/getCookie")
13
+ getCookiePage(req, res) {
14
+ const cookieName = req.cookies.name;
15
+ return "getCookie: " + cookieName;
16
+ }
17
+
18
+ @getMapping("/second/testSession")
19
+ testForSession(req, res) {
20
+ req.session.view = req.session.view ? req.session.view + 1 : 1;
21
+ return "testForSession: " + req.session.view;
22
+ }
23
+
24
+ @postMapping("/upload")
25
+ @upload
26
+ public upload(req, res) {
27
+ const files = req.files;
28
+ log(files);
29
+ log("uploaded");
30
+ res.send("upload success");
31
+ }
32
+
33
+ @jwt({ secret: "shhhhhhared-secret", algorithms: ["HS256"] })
34
+ @postMapping("/form")
35
+ form(req, res) {
36
+ res.render("upload");
37
+ }
38
+
39
+ @getMapping("/second/testError")
40
+ testError(req, res) {
41
+ throw new Error('Test Error');
42
+ }
43
+ }
@@ -0,0 +1,85 @@
1
+ import { insert, update, select, param, resultType, cache, CacheFactory, getMapping, component, log, autoware } from "../../";
2
+ import UserDto from "./entities/user-dto.class";
3
+
4
+ @component
5
+ export default class TestDatabase {
6
+
7
+ @autoware
8
+ private cacheBean: CacheFactory;
9
+
10
+ @getMapping("/db/insert")
11
+ async insert(req, res) {
12
+ const id = req.query.id || 1;
13
+ const newId = await this.addRow("new name " + id, id);
14
+ log("Insert newId: " + newId);
15
+ res.send("Insert success");
16
+ }
17
+
18
+ @getMapping("/db/insert2")
19
+ async insertByObject(req, res) {
20
+ const newId = await this.addRowByObject({
21
+ "id": 25, "name": "new name 25"
22
+ });
23
+ log("Insert newId: " + newId);
24
+ res.send("Insert success");
25
+ }
26
+
27
+ @getMapping("/db/update")
28
+ async update(req, res) {
29
+ const affectedRows = await this.editRow();
30
+ log("Update rows: " + affectedRows);
31
+ res.send("update success");
32
+ }
33
+
34
+ @getMapping("/db/select")
35
+ async select(req, res) {
36
+ const rows = await this.selectRow();
37
+ log("select rows: " + rows);
38
+ res.send(rows);
39
+ }
40
+
41
+ @getMapping("/db/select1")
42
+ async selectById(req, res) {
43
+ const row = await this.findRow(req.query.id || 1);
44
+ log("select rows: " + row);
45
+ res.send(row);
46
+ }
47
+
48
+ @getMapping("/db/select-user")
49
+ async selectUser(req, res) {
50
+ const users: UserDto[] = await this.findUsers();
51
+ log("select users: " + users);
52
+ res.send(users);
53
+ }
54
+
55
+ @getMapping("/db/set-cache")
56
+ testCache(req, res) {
57
+ this.cacheBean.set("test", req.query.value || "test");
58
+ res.send("set cache success");
59
+ }
60
+
61
+ @getMapping("/db/get-cache")
62
+ displayCache(req, res) {
63
+ res.send(this.cacheBean.get("test"));
64
+ }
65
+
66
+ @insert("Insert into `user` (id, name) values (#{id}, #{name})")
67
+ private async addRow(@param("name") newName: string, @param("id") id: number) { }
68
+
69
+ @insert("Insert into `user` (id, name) values (#{id}, #{name})")
70
+ private async addRowByObject(myParams: object) { }
71
+
72
+ @update("Update `user` set `name` = 'test5' where id = 5")
73
+ private async editRow() { }
74
+
75
+ @select("Select * from `user`")
76
+ private async selectRow() { }
77
+
78
+ @cache(1800)
79
+ @select("Select * from `user` where id = #{id}")
80
+ private async findRow(@param("id") id: number) { }
81
+
82
+ @resultType(UserDto)
83
+ @select("Select * from `user`")
84
+ private findUsers(): UserDto[] { return; }
85
+ }
@@ -0,0 +1,9 @@
1
+ import { component } from "../../";
2
+
3
+ @component
4
+ export default class TestLog {
5
+
6
+ constructor() {
7
+ //log("TestLog constructor");
8
+ }
9
+ }
@@ -0,0 +1,74 @@
1
+ import { resource, component, log, autoware, schedule, getMapping, postMapping, Redis } from "../../";
2
+ import UserModel from "./user-model.class";
3
+
4
+ @component
5
+ export default class TestOrm {
6
+
7
+ @resource("user")
8
+ private userModel: UserModel;
9
+
10
+ @autoware
11
+ private redisObj: Redis;
12
+
13
+ @getMapping("/redis")
14
+ async redisTest() {
15
+ await this.redisObj.set("redisKey", "Hello World");
16
+ const value = await this.redisObj.get("redisKey");
17
+ log(value)
18
+ return "get from redis: " + value;
19
+ }
20
+
21
+ @getMapping("/orm/first")
22
+ async firstTest(req, res) {
23
+ const results = await this.userModel.getUsers();
24
+ res.send("first test, to " + results);
25
+ }
26
+
27
+ @getMapping("/orm/one")
28
+ async findOneTest(req, res) {
29
+ const results = await this.userModel.getUser(req.query.id || 0);
30
+ res.send("find one test, to " + results);
31
+ }
32
+
33
+ @getMapping("/orm/delete")
34
+ async deleteTest(req, res) {
35
+ const results = await this.userModel.remove(req.query.id || 0);
36
+ res.send("remove user, results: " + results);
37
+ }
38
+
39
+ @getMapping("/orm/count")
40
+ async countTest(req, res) {
41
+ const results = await this.userModel.count();
42
+ res.send(results);
43
+ }
44
+
45
+ @getMapping("/orm/new")
46
+ async newUserTest(req, res) {
47
+ const results = await this.userModel.newUsers();
48
+ res.send("new user test, to " + results);
49
+ }
50
+
51
+ @getMapping("/orm/page/calculate")
52
+ async calculatePage(req, res) {
53
+ const pages = this.userModel.pager(15, 376);
54
+ res.send("pages calculate result: " + JSON.stringify(pages));
55
+ }
56
+
57
+ @getMapping("/orm/pages/:id")
58
+ async findPage(req, res) {
59
+ const results = await this.userModel.findAll("1", { id: -1 }, "*", { page: req.params.id, pageSize: 3 });
60
+ log(this.userModel.page);
61
+ res.send("pages find result: " + JSON.stringify(results));
62
+ }
63
+
64
+ @postMapping("/orm/edit")
65
+ async updateTest(req, res) {
66
+ const results = await this.userModel.editUser(req.body.id, req.body.name);
67
+ res.send(results);
68
+ }
69
+
70
+ //@schedule("* * * * * *")
71
+ myTimer() {
72
+ log("myTimer running");
73
+ }
74
+ }