docs(README): 更新项目文档
- 添加项目简介、安装方法、核心功能说明 - 提供使用示例代码 - 增加测试和贡献指南 - 附上许可证信息
This commit is contained in:
parent
9c2512ea96
commit
32250ddaaa
69
README.md
69
README.md
|
@ -1,2 +1,69 @@
|
||||||
# coperator
|
# COperator
|
||||||
|
|
||||||
|
实现MongoDB风格查询操作符的文档过滤库,提供灵活的条件匹配功能
|
||||||
|
|
||||||
|
## 安装
|
||||||
|
```bash
|
||||||
|
# 确保已安装Go环境(1.23.1+)
|
||||||
|
go get git.pyer.club/kingecg/coperator
|
||||||
|
```
|
||||||
|
|
||||||
|
## 核心功能
|
||||||
|
- **Document过滤**:通过`DocumentOperator`检查文档是否满足过滤条件
|
||||||
|
- **支持操作符**:`$gt`、`$ge`、`$lt`、`$le`、`$eq`、`$ne`、`$in`、`$nin`
|
||||||
|
- **嵌套查询**:支持嵌套文档和数组的路径访问(`.`分隔路径)
|
||||||
|
- **链式条件**:支持`$and`、`$or`等组合条件查询
|
||||||
|
|
||||||
|
## 使用示例
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"git.pyer.club/kingecg/coperator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// 创建测试文档
|
||||||
|
doc := &coperator.Document{
|
||||||
|
"name": "Alice",
|
||||||
|
"age": 30,
|
||||||
|
"address": map[string]interface{}{
|
||||||
|
"city": "Beijing",
|
||||||
|
"zip": 100000,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// 定义过滤条件
|
||||||
|
filter := coperator.Filter{
|
||||||
|
"age": map[string]interface{}{
|
||||||
|
"$gt": 25,
|
||||||
|
},
|
||||||
|
"address.city": "Beijing",
|
||||||
|
}
|
||||||
|
|
||||||
|
// 执行查询
|
||||||
|
result, err := coperator.DocumentOperator(doc, filter, "", nil)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Printf("Document matches filter: %v\n", result) // 输出: Document matches filter: true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 测试
|
||||||
|
```bash
|
||||||
|
# 运行单元测试
|
||||||
|
go test -v ./...
|
||||||
|
```
|
||||||
|
|
||||||
|
## 贡献
|
||||||
|
欢迎提交PR或Issue
|
||||||
|
1. Fork仓库
|
||||||
|
2. 创建新分支
|
||||||
|
3. 提交代码
|
||||||
|
4. 创建Pull Request
|
||||||
|
|
||||||
|
## 许可证
|
||||||
|
MIT License
|
Loading…
Reference in New Issue