{"id":46423334,"url":"https://github.com/fndome/xb","last_synced_at":"2026-04-15T07:16:37.958Z","repository":{"id":37690018,"uuid":"496892526","full_name":"fndome/xb","owner":"fndome","description":"query builder of golang, build sql for go framework: sqlx, gorp... build json for Qdrant vectordb, custom for any database .... the AI-First vector db builder for rag","archived":false,"fork":false,"pushed_at":"2026-02-21T15:27:22.000Z","size":1040,"stargazers_count":23,"open_issues_count":34,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-05T18:50:40.993Z","etag":null,"topics":["golang","json","query-builder","vector-database","vectordb","xb"],"latest_commit_sha":null,"homepage":"https://fndome.github.io/xb/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fndome.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-05-27T06:50:25.000Z","updated_at":"2026-02-26T11:23:19.000Z","dependencies_parsed_at":"2023-11-25T03:19:45.176Z","dependency_job_id":"1c035a55-b9c3-4a76-93af-01c26ce8c65b","html_url":"https://github.com/fndome/xb","commit_stats":null,"previous_names":["x-ream/xb"],"tags_count":63,"template":false,"template_full_name":null,"purl":"pkg:github/fndome/xb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fndome%2Fxb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fndome%2Fxb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fndome%2Fxb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fndome%2Fxb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fndome","download_url":"https://codeload.github.com/fndome/xb/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fndome%2Fxb/sbom","scorecard":{"id":441820,"data":{"date":"2025-07-07","repo":{"name":"github.com/x-ream/sqlxb","commit":"b691cbbd34767e7e83a6c853c5f690ed95b53c1b"},"scorecard":{"version":"v5.2.1-18-gbb9c347d","commit":"bb9c347dff6349d986baab6578a46d68a5524c62"},"score":3.4,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#maintained"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#sast"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/go.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/x-ream/sqlxb/go.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/x-ream/sqlxb/go.yml/main?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#branch-protection"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/bb9c347dff6349d986baab6578a46d68a5524c62/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T05:45:42.114Z","repository_id":37690018,"created_at":"2025-08-19T05:45:42.114Z","updated_at":"2025-08-19T05:45:42.114Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31830475,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T18:05:02.291Z","status":"online","status_checked_at":"2026-04-15T02:00:06.175Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["golang","json","query-builder","vector-database","vectordb","xb"],"created_at":"2026-03-05T17:17:55.058Z","updated_at":"2026-04-15T07:16:37.950Z","avatar_url":"https://github.com/fndome.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# xb (eXtensible Builder)\n[![OSCS Status](https://www.oscs1024.com/platform/badge/fndome/xb.svg?size=small)](https://www.oscs1024.com/project/fndome/xb?ref=badge_small)\n![workflow build](https://github.com/fndome/xb/actions/workflows/go.yml/badge.svg)\n[![GitHub tag](https://img.shields.io/github/tag/fndome/xb.svg?style=flat)](https://github.com/fndome/xb/tags)\n[![Go Report Card](https://goreportcard.com/badge/github.com/fndome/xb)](https://goreportcard.com/report/github.com/fndome/xb)\n\n\u003e Languages: **English** | [中文](./doc/cn/README.md)\n\n`xb` is an AI-first SQL/JSON builder for relational + vector databases. One fluent API builds:\n\n- SQL for `database/sql`, `sqlx`, `gorm`, any raw driver\n- JSON for Qdrant (Recommend / Discover / Scroll) and other vector stores\n- Hybrid pipelines that mix SQL tables with vector similarity\n\nEverything flows through `Custom()` + `Build()` so the surface stays tiny even as capabilities grow.\n\n\u003e **Notes**\n\u003e - Persistence structs mirror the database schema, so numeric primary keys can stay as plain values.\n\u003e - Request/filter DTOs should declare non-primary numeric and boolean fields as pointers to distinguish “unset” from “0/false” and to leverage autobypass logic.\n\u003e - Need to bypass optimizations? Use `X(\"...\")` to inject raw SQL (the clause will never be auto-skipped), and pick explicit JOIN helpers (e.g., `JOIN(NON_JOIN)` or custom builders) when you want to keep every JOIN even if it looks redundant. For `BuilderX`, call `WithoutOptimization()` to disable the JOIN/CTE optimizer entirely.\n\u003e - For non-functional control flow inside fluent chains, use `Any(func(*BuilderX))` to run loops or helper functions without breaking chaining, and `Bool(func() bool, func(*CondBuilder))` to conditionally add blocks while reusing the auto-filtered DSL.\n\n---\n\n## Highlights\n\n- **Unified vector entry** — `JsonOfSelect()` now covers all Qdrant search/recommend/discover/scroll flows. Legacy `ToQdrant*JSON()` methods were retired.\n- **Composable SQL** — `With/WithRecursive` and `UNION(kind, fn)` let you express ClickHouse-style analytics directly in Go.\n- **Smart condition DSL** — auto-filter nil/zero, guard rails via `InRequired`, raw expressions via `X()`, reusable subqueries via `CondBuilderX.Sub()`, and inline conditional blocks.\n- **Adaptive JOIN planner** — `FromX` + `JOIN(kind)` skip meaningless joins automatically (e.g., empty ON blocks), keeping SQL lean.\n- **Observability-first** — `Meta(func)` plus interceptors carry TraceID/UserID across builder stages.\n- **AI-assisted maintenance** — code, tests, docs co-authored by AI and reviewed by humans every release.\n\n---\n\n## Quickstart\n\n### Build SQL\n```go\npackage main\n\nimport \"github.com/fndome/xb\"\n\ntype Cat struct {\n    ID    uint64   `db:\"id\"`\n    Name  string   `db:\"name\"`\n    Age   *uint    `db:\"age\"`\n    Price *float64 `db:\"price\"`\n}\n\nfunc main() {\n    built := xb.Of(\u0026Cat{}).\n        Eq(\"status\", 1).\n        Gte(\"age\", 3).\n        Build()\n\n    sql, args, _ := built.SqlOfSelect()\n    // SELECT * FROM t_cat WHERE status = ? AND age \u003e= ?\n    _ = sql\n    _ = args\n}\n```\n\n### Qdrant vector search\n```go\nqueryVector := xb.Vector{0.1, 0.2, 0.3}\n\njson, err := xb.Of(\u0026CodeVector{}).\n    Custom(\n        xb.NewQdrantBuilder().\n            Recommend(func(rb *xb.RecommendBuilder) {\n                rb.Positive(123, 456).Negative(789).Limit(20)\n            }).\n            Build(),\n    ).\n    Eq(\"language\", \"golang\").\n    VectorSearch(\"embedding\", queryVector, 10).\n    Build().\n    JsonOfSelect()\n\nif err != nil {\n    panic(err)\n}\n// POST json to /collections/{name}/points/recommend\n```\n\n---\n\n## Advanced Capabilities\n\n### CTE + UNION pipelines\n```go\nreport := xb.Of(\"recent_orders\").\n    With(\"recent_orders\", func(sb *xb.BuilderX) {\n        sb.From(\"orders o\").\n            Select(\"o.id\", \"o.user_id\").\n            Gt(\"o.created_at\", since30Days)\n    }).\n    WithRecursive(\"team_hierarchy\", func(sb *xb.BuilderX) {\n        sb.From(\"users u\").\n            Select(\"u.id\", \"u.manager_id\").\n            Eq(\"u.active\", true)\n    }).\n    UNION(xb.ALL, func(sb *xb.BuilderX) {\n        sb.From(\"archived_orders ao\").\n            Select(\"ao.id\", \"ao.user_id\")\n    }).\n    Meta(func(meta *interceptor.Metadata) {\n        meta.TraceID = traceID\n        meta.Set(\"source\", \"dashboard\")\n    }).\n    Build()\n\nsql, args, _ := report.SqlOfSelect()\n```\n\n### JOIN builder with subqueries\n```go\nbuilder := xb.X().\n    Select(\"p.id\", \"p.weight\").\n    FromX(func(fb *xb.FromBuilder) {\n        fb.Sub(func(sb *xb.BuilderX) {\n            sb.Select(\"id\", \"type\").\n                From(\"t_pet\").\n                Gt(\"id\", 10000)\n        }).As(\"p\").\n            JOIN(xb.INNER).Of(\"t_dog\").As(\"d\").On(\"d.pet_id = p.id\").\n            JOIN(xb.LEFT).Of(\"t_cat\").As(\"c\").On(\"c.pet_id = p.id\").\n            Cond(func(on *xb.ON) {\n\t\t\t\t\ton.Gt(\"p.weight\", 10)\n\t\t\t\t})\n    }).\n    Ne(\"p.type\", \"PIG\")\n\nsql, args, _ := builder.Build().SqlOfSelect()\n```\n\n### Qdrant Recommend / Discover / Scroll\n- Configure via `NewQdrantBuilder().Recommend(...).Build()` / `Discover(...)` / `ScrollID(...)`.\n- `JsonOfSelect()` inspects builder state and emits the correct JSON schema.\n- Compatible with diversity helpers (`WithHashDiversity`, `WithMinDistance`) and standard filters.\n\n### Interceptors \u0026 Metadata\n- Register global `BeforeBuild` / `AfterBuild` hooks (see `xb/interceptor`).\n- `Meta(func)` injects metadata before hooks run — perfect for tracing, tenancy, or experiments.\n\n### Dialect \u0026 Custom\n- Dialects (`dialect.go`) let you swap quoting rules, placeholder styles, and vendor-specific predicates without rewriting builders — see [`doc/en/DIALECT_CUSTOM_DESIGN.md`](./doc/en/DIALECT_CUSTOM_DESIGN.md) / [`doc/cn/DIALECT_CUSTOM_DESIGN.md`](./doc/cn/DIALECT_CUSTOM_DESIGN.md).\n- `Custom()` is the escape hatch for vector DBs and bespoke backends: plug in `Custom` implementations, emit JSON via `JsonOfSelect()`, or mix SQL + vector calls in one fluent chain. Deep dives live in [`doc/en/CUSTOM_VECTOR_DB_GUIDE.md`](./doc/en/CUSTOM_VECTOR_DB_GUIDE.md) / [`doc/cn/CUSTOM_VECTOR_DB_GUIDE.md`](./doc/cn/CUSTOM_VECTOR_DB_GUIDE.md).\n- Need Oracle/Milvus/other dialects? Implement a tiny interface `Custom`, register it once, and the fluent chains instantly start outputting those drivers’ SQL/JSON schemas without forking the builder core.\n\n---\n\n## Documentation\n\n| Topic | English | Chinese |\n|-------|---------|---------|\n| Overview \u0026 Index | [doc/en/README.md](./doc/en/README.md) | [doc/cn/README.md](./doc/cn/README.md) |\n| Quickstart | [doc/en/QUICKSTART.md](./doc/en/QUICKSTART.md) | [doc/cn/QUICKSTART.md](./doc/cn/QUICKSTART.md) |\n| Qdrant Guide | [doc/en/QDRANT_GUIDE.md](./doc/en/QDRANT_GUIDE.md) | [doc/cn/QDRANT_GUIDE.md](./doc/cn/QDRANT_GUIDE.md) |\n| Vector Guide | [doc/en/VECTOR_GUIDE.md](./doc/en/VECTOR_GUIDE.md) | [doc/cn/VECTOR_GUIDE.md](./doc/cn/VECTOR_GUIDE.md) |\n| Custom Interface | [doc/en/CUSTOM_INTERFACE.md](./doc/en/CUSTOM_INTERFACE.md) | [doc/cn/CUSTOM_INTERFACE.md](./doc/cn/CUSTOM_INTERFACE.md) |\n| Auto-filter (nil/0 skip) | [doc/en/ALL_FILTERING_MECHANISMS.md](./doc/en/ALL_FILTERING_MECHANISMS.md) | [doc/cn/FILTERING.md](./doc/cn/FILTERING.md) |\n| Join optimization | [doc/en/CUSTOM_JOINS_GUIDE.md](./doc/en/CUSTOM_JOINS_GUIDE.md) | _(coming soon)_ |\n| AI Application Starter | [doc/en/AI_APPLICATION.md](./doc/en/AI_APPLICATION.md) | [doc/cn/AI_APPLICATION.md](./doc/cn/AI_APPLICATION.md) |\n\n\u003e We are migrating docs into `doc/en/` + `doc/cn/`. Legacy files remain under `doc/` until the move completes.\n\n---\n\n## Contributing\n\nWe welcome issues, discussions, PRs!\n\n- Issues \u0026 features: [GitHub Issues](https://github.com/fndome/xb/issues)\n- Roadmap \u0026 ideas: [GitHub Discussions](https://github.com/fndome/xb/discussions)\n- Contribution steps: [CONTRIBUTING](./doc/CONTRIBUTING.md)\n- Vision \u0026 philosophy: [VISION.md](./VISION.md)\n\nBefore opening a PR:\n1. Run `go test ./...`\n2. Update docs/tests related to your change\n3. Describe behavior changes clearly in the PR template\n\n---\n\n## License\n\nApache License 2.0 — see [LICENSE](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffndome%2Fxb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffndome%2Fxb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffndome%2Fxb/lists"}