{"id":49312310,"url":"https://github.com/suboat/go-sql-kit","last_synced_at":"2026-04-26T13:31:01.590Z","repository":{"id":57524155,"uuid":"56678194","full_name":"suboat/go-sql-kit","owner":"suboat","description":"Very useful toolkit for SQL - WHERE \u0026 ORDER BY \u0026 LIMIT","archived":false,"fork":false,"pushed_at":"2016-10-17T01:32:32.000Z","size":82,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-20T08:10:13.642Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/suboat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-20T10:33:18.000Z","updated_at":"2021-10-09T03:57:27.000Z","dependencies_parsed_at":"2022-09-26T18:11:12.917Z","dependency_job_id":null,"html_url":"https://github.com/suboat/go-sql-kit","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/suboat/go-sql-kit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suboat%2Fgo-sql-kit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suboat%2Fgo-sql-kit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suboat%2Fgo-sql-kit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suboat%2Fgo-sql-kit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/suboat","download_url":"https://codeload.github.com/suboat/go-sql-kit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suboat%2Fgo-sql-kit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32299628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T09:34:17.070Z","status":"ssl_error","status_checked_at":"2026-04-26T09:34:00.993Z","response_time":129,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2026-04-26T13:31:00.227Z","updated_at":"2026-04-26T13:31:01.581Z","avatar_url":"https://github.com/suboat.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-sql-kit\n\n# v0.9.3\n\n## Overview\n\n* JSON格式\n* 只需通过字符串(string)，即可实现**条件筛选(WHERE)**/**结果排序(ORDER BY)**/**结果分页(LIMIT)**等常用功能\n* 提供快速便捷方案，对接开发前端(JS)模块(Developing...)，实现上述**筛选**/**排序**/**分页**功能\n\n## Usage\n\n```\ngo get -u github.com/suboat/go-sql-kit\n```\n\n## Reference\n\nsql-kit(https://github.com/axetroy/sql-kit)\n\n## Documents\n\n* 当前规则均基于JSON格式\n\n1. 独立模块\n    1. [Query](#query)(**条件筛选(WHERE)**)\n    1. [Order](#order)(**结果排序(ORDER BY)**)\n    1. [Limit](#limit)(**结果分页(LIMIT)**)\n    1. [Rule](#rule)\n1. 组合模块\n    1. [Protocol](#protocol)(**组合格式**)\n    1. [Demo](#demo)\n\n### Query\n\n[./query.go](https://github.com/suboat/go-sql-kit/blob/master/query.go)\n\n#### 关键字\n\n```golang\nQueryKeyAnd        string = \"%and\"  // 与\nQueryKeyOr                = \"%or\"   // 或\n\nQueryKeyEq         string = \"%eq\"   // 等于\nQueryKeyNe                = \"%ne\"   // 不等于\nQueryKeyLt                = \"%lt\"   // 小于\nQueryKeyLte               = \"%lte\"  // 小于等于\nQueryKeyGt                = \"%gt\"   // 大于\nQueryKeyGte               = \"%gte\"  // 大于等于\nQueryKeyLike              = \"%like\" // 模糊搜索\nQueryKeyIn                = \"%in\"   // 在...之中\nQueryKeyBetween           = \"%bt\"   // 在...之间\nQueryKeyNotBetween        = \"%nbt\"  // 不在...之间\n```\n\n* 关键字\"%and\"和\"%or\"需继续包含关键字\n\n#### 实例说明\n\n* 实例1:\n`key1 == \"A12\"`\n```json\n{\"%and\":{\"%eq\":{\"key1\":\"A12\"}}}\n// 或者简化为\n{\"%eq\":{\"key1\":\"A12\"}}\n```  \n\n* 实例2:\n`(key1 == \"A12\" \u0026\u0026 key2 == \"B23\") \u0026\u0026 (key3 != \"C34\" \u0026\u0026 key4 != \"D45\")`\n```json\n{\"%and\":{\"%eq\":{\"key1\":\"A12\",\"key2\":\"B23\"},\"%ne\":{\"key3\":\"C34\",\"key4\":\"D45\"}}}\n```\n\n* 实例3:\n`(key1 \u003c 12 \u0026\u0026 key2 \u003c 23) || (key3 \u003e= 34 \u0026\u0026 key4 \u003e= 45)`\n```json\n{\"%or\":{\"%lt\":{\"key1\":12,\"key2\":23},\"%gte\":{\"key3\":34,\"key4\":45}}}\n```\n\n* 实例4:\n`key1 == \"11\" \u0026\u0026 key2 = \"12\" \u0026\u0026 (key3 \u003e= 31 \u0026\u0026 key3 \u003c= 32) \u0026\u0026 !(key4 \u003c= 43 \u0026\u0026 key4 \u003e= 44) \u0026\u0026 (key5 == 51 || key5 == 52)`\n```json\n{\"%and\":{\"%eq\":{\"key1\":\"11\",\"key2\":12},\"%bt\":{\"key3\":[31,32]},\"%nbt\":{\"key4\":[43,44]},\"%in\":{\"key5\":[51,52]}}}\n```\n\n### Order\n\n[./order.go](https://github.com/suboat/go-sql-kit/blob/master/order.go)\n\n#### 关键字\n\n```golang\nOrderKey string = \"%o\"\n\nOrderKeyASC  string = \"+\" // 正序\nOrderKeyDESC        = \"-\" // 反序\n```\n\n* 正序缺省可以不加关键字\n* 正序: 例如对字段\"key1\"正向排序，可写为\"+key1\"，也可以\"key1\"\n* 反序: 例如对字段\"key4\"反向排序，需写为\"-key4\"\n\n#### 实例说明\n\n* 实例1:\n`正序(\"key1\", \"key2\", \"key3\")，反序(\"key4\", \"key5\")`\n```json\n{\"%o\":[\"key1\", \"+key2\", \"+key3\", \"-key4\", \"-key5\"]}\n```\n\n### Limit\n\n[./limit.go](https://github.com/suboat/go-sql-kit/blob/master/limit.go)\n\n#### 关键字\n\n```golang\nLimitKeyLimit string = \"%l\" // 数量限制\nLimitKeySkip         = \"%s\" // 位移数量\nLimitKeyPage         = \"%p\" // 页数，从0开始\n```\n\n* 若使用Limit，其中\"%l\"不允许缺省\n* 值必须为整型数字\n* (TODO: 后续计划可能允许缺省\"%l\"，允许值为字符串)\n\n#### 实例说明\n\n* 实例1:\n`忽略最前面的13个值，返回最多5个值` (`忽略最前面的3个，并返回第3页的值，每页最多5个值`)\n```json\n{\"%l\":5,\"%s\":3,\"%p\":2}\n```\n\n### Rule\n\n[./rule.go](https://github.com/suboat/go-sql-kit/blob/master/rule.go)\n\n### Protocol\n\n* 基于JSON格式\n* 格式: `[{Query},{Order},{Limit}]`\n* 参数: \n    - [{Query}](#query)\n    - [{Order}](#order)\n    - [{Limit}](#limit)\n\n### Demo\n\n* 实例1:\n```json\n[\n    {\n        \"%and\":{\n            \"%eq\":{\n                \"key1\":\"A12\",\n                \"key2\":\"B23\"\n            },\n            \"%ne\":{\n                \"key3\":\"C34\",\n                \"key4\":\"D45\"\n            }\n        }\n    },\n    {\n        \"%o\":[\n            \"+key1\",\n            \"-key2\"\n        ]\n    },\n    {\n        \"%l\":5,\n        \"%s\":12,\n        \"%p\":1\n    }\n]\n```\n\n## TODO\n\n* 开发前端(JS)模块\n* 不断完善文档说明\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuboat%2Fgo-sql-kit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuboat%2Fgo-sql-kit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuboat%2Fgo-sql-kit/lists"}