Go to file
kingecg 284689cb60 chore: update module path to git.kingecg.top 2025-06-26 00:48:10 +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 chore: update module path to git.kingecg.top 2025-06-26 00:48:10 +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 feat(coperator): 添加逻辑运算符支持 2025-06-19 21:08:13 +08:00
coperator_test.go refactor(coperator): 将 Filter 类型断言改为 map[string]interface{} 类型 2025-06-19 21:01:26 +08:00
go.mod chore: update module path to git.kingecg.top 2025-06-25 21:35:08 +08:00
logic.go feat(coperator): 添加逻辑运算符支持 2025-06-19 21:08:13 +08:00

README.md

COperator

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

安装

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

核心功能

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

使用示例

package main

import (
	"fmt"
	"git.kingecg.top/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