Skip to content

Commit 8d29ab1

Browse files
committed
feat: 查询
0 parents  commit 8d29ab1

File tree

20 files changed

+1992
-0
lines changed

20 files changed

+1992
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
*.exe

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 glennliao
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# apijson-go [WIP]
2+
基于 go + goframe 实现的 apijson
3+
4+
> 暂仍处于前期开发探索中, 请仅使用在 个人探索项目
5+
6+
# 功能实现
7+
8+
- [x] 单表查询、单表数组查询
9+
- [x] 双表一对一关联查询、数组关联查询
10+
- [x] 双表一对多关联查询、数组关联查询
11+
- [x] @column, @order, @group, page, count
12+
- [x] 单表单条新增
13+
- [x] 单表单条修改
14+
- [x] 单表单条、批量删除
15+
- [x] Request表的tag校验
16+
- [x] MUST
17+
- [x] REFUSE
18+
- [ ] 可用的权限方案
19+
20+
## 查询实现
21+
1. 根据json构造节点树, 并检查节点结构(不符合直接返回)
22+
2. parse 节点树内容, 并分析关联关系(不要求json的key顺序, 因为go的原生map不支持顺序遍历)
23+
3. 从依赖关系中逐步fetch数据
24+
4. 构造响应数据
25+
26+
27+
# 列表查询限制
28+
29+
[//]: # (1. page,count 最大值)
30+
- []下只能有一个主查询表 (不依赖于列表中其他表)
31+
32+
33+
# 开发指南
34+
35+
1. go >= 1.18
36+
2. 创建mysql数据库
37+
3. 导入test.sql文件
38+
4. 修改配置文件config.yaml中数据库连接
39+
5. 运行go run main.go
40+
6. 查看测试test.http
41+
42+
43+
# 感谢
44+
- [GoFrame](https://github.com/gogf/gf)
45+
- [APIJSON](https://github.com/Tencent/APIJSON)
46+
47+
# 参考链接
48+
1. [详细的说明文档.md](https://github.com/Tencent/APIJSON/blob/master/%E8%AF%A6%E7%BB%86%E7%9A%84%E8%AF%B4%E6%98%8E%E6%96%87%E6%A1%A3.md)
49+
2. [最新规范文档](https://github.com/Tencent/APIJSON/blob/master/Document.md)
50+
3. [todo demo doc](https://github.com/jerrylususu/apijson_todo_demo/blob/master/FULLTEXT.md)
51+
4. [如何实现其它语言的APIJSON?](https://github.com/Tencent/APIJSON/issues/38)

README.zh-CN.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# apijson-go [WIP]
2+
基于 go + goframe 实现的 apijson
3+
4+
> 暂仍处于前期开发探索中, 请仅使用在 个人探索项目
5+
6+
# 功能实现
7+
8+
- [x] 单表查询、单表数组查询
9+
- [x] 双表一对一关联查询、数组关联查询
10+
- [x] 双表一对多关联查询、数组关联查询
11+
- [x] @column, @order, @group, page, count
12+
- [x] 单表单条新增
13+
- [x] 单表单条修改
14+
- [x] 单表单条、批量删除
15+
- [x] Request表的tag校验
16+
- [x] MUST
17+
- [x] REFUSE
18+
- [ ] 可用的权限方案
19+
20+
## 查询实现
21+
1. 根据json构造节点树, 并检查节点结构(不符合直接返回)
22+
2. parse 节点树内容, 并分析关联关系(不要求json的key顺序, 因为go的原生map不支持顺序遍历)
23+
3. 从依赖关系中逐步fetch数据
24+
4. 构造响应数据
25+
26+
27+
# 列表查询限制
28+
29+
[//]: # (1. page,count 最大值)
30+
- []下只能有一个主查询表 (不依赖于列表中其他表)
31+
32+
33+
# 开发指南
34+
35+
1. go >= 1.18
36+
2. 创建mysql数据库
37+
3. 导入test.sql文件
38+
4. 修改配置文件config.yaml中数据库连接
39+
5. 运行go run main.go
40+
6. 查看测试test.http
41+
42+
43+
# 感谢
44+
- [GoFrame](https://gitee.com/johng/gf)
45+
- [APIJSON](https://gitee.com/Tencent/APIJSON)
46+
47+
# 参考链接
48+
1. [详细的说明文档.md](https://github.com/Tencent/APIJSON/blob/master/%E8%AF%A6%E7%BB%86%E7%9A%84%E8%AF%B4%E6%98%8E%E6%96%87%E6%A1%A3.md)
49+
2. [最新规范文档](https://github.com/Tencent/APIJSON/blob/master/Document.md)
50+
3. [todo demo doc](https://github.com/jerrylususu/apijson_todo_demo/blob/master/FULLTEXT.md)
51+
4. [如何实现其它语言的APIJSON?](https://github.com/Tencent/APIJSON/issues/38)

apijson/access.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package apijson
2+
3+
// getRolesByTable
4+
// 1. 基本角色 UNKNOW, OWNER, ADMIN
5+
func getRolesByTable() {
6+
7+
}
8+
9+
// 1. 读取access 中对于表的 get操作的角色列表
10+
11+
// 资源 ->
12+
// 用户
13+
// role
14+
// 操作方式
15+
16+
// 1. 获取用户的角色
17+
// 2. 判断该角色是否可访问 (adm)
18+
// 3. 用户端( 获取 owner 的数据)
19+
// 4. dept端( 获取 dept id 的数据 )

apijson/db/data.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package db
2+
3+
import (
4+
"github.com/gogf/gf/v2/frame/g"
5+
"github.com/gogf/gf/v2/os/gtime"
6+
"strings"
7+
)
8+
9+
var RowKeyMap = map[string]string{
10+
"user": "userId",
11+
"todo": "id",
12+
} // 从数据库中读入
13+
14+
var AccessMap = map[string]Access{}
15+
16+
type Access struct {
17+
Debug int8
18+
Name string
19+
Alias string
20+
Get []string
21+
Head []string
22+
Gets []string
23+
Heads []string
24+
Post []string
25+
Put []string
26+
Delete []string
27+
Date *gtime.Time
28+
Detail string
29+
}
30+
31+
var RequestMap = map[string]Request{}
32+
33+
type Request struct {
34+
Debug int8
35+
Version int16
36+
Method string
37+
Tag string
38+
// https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/Operation.java
39+
Structure g.Map
40+
Detail string
41+
Date *gtime.Time
42+
}
43+
44+
func Init() {
45+
getAccessMap()
46+
getRequestMap()
47+
}
48+
49+
func getAccessMap() {
50+
accessMap := make(map[string]Access)
51+
52+
var accessList []Access
53+
g.DB().Model("Access").Scan(&accessList)
54+
55+
for _, access := range accessList {
56+
accessMap[access.Name] = access
57+
}
58+
59+
AccessMap = accessMap
60+
}
61+
62+
func getRequestMap() {
63+
requestMap := make(map[string]Request)
64+
65+
var requestList []Request
66+
g.DB().Model("Request").Scan(&requestList)
67+
68+
for _, item := range requestList {
69+
70+
tag := item.Tag
71+
if strings.ToLower(tag) != tag {
72+
// 本身大写, 如果没有外层, 则套一层
73+
// https://github.com/Tencent/APIJSON/issues/115#issuecomment-565733254
74+
if _, ok := item.Structure[tag]; !ok {
75+
item.Structure = g.Map{
76+
tag: item.Structure,
77+
}
78+
}
79+
}
80+
81+
requestMap[item.Method+"@"+item.Tag] = item
82+
}
83+
84+
RequestMap = requestMap
85+
}

0 commit comments

Comments
 (0)