{"id":21674508,"url":"https://github.com/j2gg0s/celfilter","last_synced_at":"2025-03-20T08:47:48.684Z","repository":{"id":223818775,"uuid":"761632972","full_name":"j2gg0s/celfilter","owner":"j2gg0s","description":"Translate CEL to SQL for filter","archived":false,"fork":false,"pushed_at":"2024-02-27T15:14:55.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-25T09:44:40.794Z","etag":null,"topics":["filter","golang","sql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/j2gg0s.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-22T07:39:07.000Z","updated_at":"2025-01-11T20:38:52.000Z","dependencies_parsed_at":"2024-06-21T12:53:37.222Z","dependency_job_id":"d3de93bb-c924-429f-99d7-9d8be621eb60","html_url":"https://github.com/j2gg0s/celfilter","commit_stats":null,"previous_names":["j2gg0s/celfilter"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j2gg0s%2Fcelfilter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j2gg0s%2Fcelfilter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j2gg0s%2Fcelfilter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j2gg0s%2Fcelfilter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/j2gg0s","download_url":"https://codeload.github.com/j2gg0s/celfilter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244583196,"owners_count":20476233,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["filter","golang","sql"],"created_at":"2024-11-25T13:47:59.854Z","updated_at":"2025-03-20T08:47:48.659Z","avatar_url":"https://github.com/j2gg0s.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# celfilter\n使用 [CEL](https://github.com/google/cel-spec/blob/master/doc/intro.md) 的子集表达过滤条件, 并支持转化到对应的数据库查询条件.\n\n当前支持的语言子集包括:\n- 基础的数据类型, 包括 `int`, `double`, `bool`, `string`, `bytes`\n- 算术运算符, `+`, `-`, `*`, `/`, `%`\n- 逻辑运算符, `\u0026\u0026`, `||`, `!`\n- 比较运算符, `==`, `!=`, `\u003e`, `\u003e=`, `\u003c`, `\u003c=`\n- 使用 `()` 控制优先级\n- startsWith 和 endsWith\n- 时间转换函数 timestamp\n\n转换案例:\n```go\npackage celfilter\n\nimport \"fmt\"\n\nfunc ExampleConvert() {\n\tmustPrint := func(s string, err error) {\n\t\tif err != nil {\n\t\t\tpanic(nil)\n\t\t}\n\t\tfmt.Println(s)\n\t}\n\n\t// i 为默认前缀\n\tmustPrint(Convert(`i.name == \"j2gg0s\"`))\n\tmustPrint(Convert(`i.age \u003e 25`))\n\tmustPrint(Convert(`i.name == \"j2gg0s\" \u0026\u0026 i.age \u003e 25`))\n\tmustPrint(Convert(`i.name == \"j2gg0s\" \u0026\u0026 (i.city == \"Shanghai\" || i.city == \"SuZhou\")`))\n\tmustPrint(Convert(`i.name.startsWith(\"j2\")`))\n\tmustPrint(Convert(`i.name.endsWith(\"0s\")`))\n\tmustPrint(Convert(`i.birthday == timestamp(\"2000-01-01T00:00:00.000Z\")`))\n\tmustPrint(Convert(`i.birthday == timestamp(1704067200)`))\n\n\t// Output: (name == \"j2gg0s\")\n\t// (age \u003e 25)\n\t// ((name == \"j2gg0s\") AND (age \u003e 25))\n\t// ((name == \"j2gg0s\") AND ((city == \"Shanghai\") OR (city == \"SuZhou\")))\n\t// (name LIKE \"j2%\")\n\t// (name LIKE \"%0s\")\n\t// (birthday == \"2000-01-01 08:00:00\")\n\t// (birthday == FROM_UNIXTIME(1704067200))\n}\n```\n\n## 限制及注意点\n### timestamp\n仅接受 string 和 int 做为参数.\n\n当参数为 string 时, 视作格式为 YYYY-MM-DDThh:mm:ssTZD 的时间字符串, 即 Go 中的 [time.RFC3339](https://pkg.go.dev/time#pkg-constants).\n其中:\n- YYYY  表示年份, 4 位数字\n- MM    表示月份, 2 位数字\n- DD    表示日期, 2 位数字\n- T     是日期和时间的分隔符\n- hh    表示小时, 2 位数字\n- mm    表示分钟, 2 位数字\n- ss    表示秒, 2 位数字\n- TZD   表示时区偏移, 可以是 \"Z\" 或者是 \"[+/-]hh\"\n\n此时, celfilter 会将其解析为时间后转换成用户指定的时区, 默认为系统时区.\n请结合数据库时区等因素指定正确时区.\n\n当参数位 int 时, 视作 UNIX 时间戳. 即自 1970-01-01T00:00:00Z 起经过的秒数.\n此时, celfilter 会将其转换为对数据 FROM_UNIXTIME 函数的调用.\n\n你也可以直接使用字符串而不实用 timestamp 做转换, 此时需要使用数据库对应的字符串格式.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj2gg0s%2Fcelfilter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fj2gg0s%2Fcelfilter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj2gg0s%2Fcelfilter/lists"}