Skip to content

Commit 7732c29

Browse files
committed
feature: 实现查询功能
0 parents  commit 7732c29

26 files changed

+15353
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
dist
3+
ormconfig.js

README.md

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# ApiJson Node版
2+
3+
> ### A ApiJson Server build with Nest.js and TypeORM
4+
5+
----------
6+
7+
# 起步
8+
9+
## 安装依赖
10+
11+
12+
```bash
13+
$ npm install
14+
```
15+
16+
----------
17+
18+
## Database数据库配置
19+
20+
修改 `ormconfig.js` 参照 `ormconfig.js.example`
21+
22+
{
23+
"type": "mysql",
24+
"host": "localhost",
25+
"port": 3306,
26+
"username": "",
27+
"password": "",
28+
"database": "",
29+
"entities": ["src/**/**.entity{.ts,.js}"],
30+
"synchronize": false
31+
}
32+
33+
----------
34+
35+
## NPM 命令
36+
37+
- `npm run dev` - 开发模式
38+
- `npm start` - 启动应用
39+
- `npm run start:prod` - 生产模式
40+
41+
----------
42+
43+
## 启动应用
44+
45+
- `npm start`
46+
- 健康检查 `http://localhost:3000/test` 正常情况下会返回 `ok`
47+
48+
----------
49+
50+
# Swagger API 文档
51+
52+
This example repo uses the NestJS swagger module for API documentation. [NestJS Swagger](https://github.com/nestjs/swagger) - [www.swagger.io](https://swagger.io/)
53+
54+
# 使用文档
55+
56+
> 以下例子中 默认存在两张表(Comment, User)
57+
58+
59+
已经实现的操作符
60+
61+
- 单条记录查询
62+
63+
```json
64+
{
65+
"Comment": {
66+
"User": {}
67+
}
68+
}
69+
```
70+
71+
- []
72+
73+
操作符名称: 列表查询
74+
75+
例子:
76+
77+
```json
78+
{
79+
"XXX[]": { // 这里[]前的字符串将作为response的字段名
80+
"Comment": {}
81+
}
82+
}
83+
```
84+
85+
- \#
86+
87+
操作符名称: 别名
88+
89+
例子:
90+
91+
```json
92+
{
93+
"SingleComment#": {
94+
"Comment": {}
95+
}
96+
}
97+
```
98+
99+
- @column
100+
101+
操作符名称: 字段筛选
102+
103+
例子:
104+
105+
```json
106+
{
107+
"User": {
108+
"@column": "role,nickname"
109+
}
110+
}
111+
```
112+
113+
114+
- 联表查询
115+
116+
例子:
117+
```json
118+
// 查询叫tony的User
119+
// 查询一条userId为User中id的Comment
120+
{
121+
"User": {
122+
"user": "tony"
123+
},
124+
"Comment": {
125+
"userId@": "User/id"
126+
}
127+
}
128+
129+
// 查询所有符合条件的comment 显示 第1页 每页2条
130+
// (因为默认page = 1 count = 10 所以默认最多为10条)
131+
{
132+
"User": {
133+
"user": "tony"
134+
},
135+
"msgList[]": {
136+
"Comment": {
137+
"userId@": "User/id"
138+
},
139+
"count": 2,
140+
"page": 1
141+
}
142+
}
143+
144+
```
145+
146+
147+
- 综合例子
148+
149+
```json
150+
{
151+
"userInfo#": {
152+
"User": {
153+
"user": "tony"
154+
}
155+
},
156+
"testAlias#": {
157+
"msgList[]": {
158+
"Comment": {
159+
"userId@": "userInfo#/User/id"
160+
},
161+
"count": 2,
162+
"page": 1
163+
}
164+
}
165+
}
166+
```

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require('ts-node/register')
2+
require('./src/http/main')

jest.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"moduleFileExtensions": [
3+
"ts",
4+
"tsx",
5+
"js",
6+
"json"
7+
],
8+
"transform": {
9+
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
10+
},
11+
"testRegex": "/src/.*\\.(test|spec).(ts|tsx|js)$",
12+
"collectCoverageFrom" : ["src/**/*.{js,jsx,tsx,ts}", "!**/node_modules/**", "!**/vendor/**"],
13+
"coverageReporters": ["json", "lcov"]
14+
}

nestconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"language": "ts",
3+
"entryFile": "src/main.ts"
4+
}

nodemon.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"watch": ["src"],
3+
"ext": "ts",
4+
"ignore": ["src/**/*.spec.ts"],
5+
"exec": "node ./index"
6+
}

ormconfig.js.example

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const SOURCE_PATH = process.env.NODE_ENV === 'production' ? 'dist' : 'src'
2+
3+
module.exports = {
4+
"type": "mysql",
5+
"host": "localhost",
6+
"port": 3306,
7+
"username": "",
8+
"password": "",
9+
"database": "",
10+
"entities": [`${SOURCE_PATH}/**/**.entity{.ts,.js}`],
11+
"synchronize": false
12+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy