Go to file
kingecg 0772d8e2fe refactor(coperator): 将 Filter 类型断言改为 map[string]interface{} 类型
- 修改了 DocumentOperator 和 FieldOperator 函数中的 Filter 类型断言
- 将其改为 map[string]interface{} 类型,以提高灵活性和兼容性
- 更新了相关测试文件中的 Filter 类型为 map[string]interface{}
2025-06-19 21:01:26 +08:00
.gitignore Initial commit 2025-06-19 10:16:42 +08:00
LICENSE Initial commit 2025-06-19 10:16:42 +08:00
README.md docs(README): 更新项目文档 2025-06-19 20:33:43 +08:00
case.md feat: 实现了一个基本的文档过滤器 2025-06-19 17:56:05 +08:00
compare.go feat(coperator): 实现比较运算符功能 2025-06-19 20:22:04 +08:00
compare_test.go feat(coperator): 实现比较运算符功能 2025-06-19 20:22:04 +08:00
coperator.go refactor(coperator): 将 Filter 类型断言改为 map[string]interface{} 类型 2025-06-19 21:01:26 +08:00
coperator_test.go refactor(coperator): 将 Filter 类型断言改为 map[string]interface{} 类型 2025-06-19 21:01:26 +08:00
go.mod feat: 实现了一个基本的文档过滤器 2025-06-19 17:56:05 +08:00

README.md

COperator

实现MongoDB风格查询操作符的文档过滤库提供灵活的条件匹配功能

安装

# 确保已安装Go环境1.23.1+
go get git.pyer.club/kingecg/coperator

核心功能

  • Document过滤:通过DocumentOperator检查文档是否满足过滤条件
  • 支持操作符$gt$ge$lt$le$eq$ne$in$nin
  • 嵌套查询:支持嵌套文档和数组的路径访问(.分隔路径)
  • 链式条件:支持$and$or等组合条件查询

使用示例

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
}

测试

# 运行单元测试
go test -v ./...

贡献

欢迎提交PR或Issue

  1. Fork仓库
  2. 创建新分支
  3. 提交代码
  4. 创建Pull Request

许可证

MIT License