{"id":15138490,"url":"https://github.com/colinzhu/sql-template-builder","last_synced_at":"2026-01-20T02:46:51.566Z","repository":{"id":162857301,"uuid":"618689757","full_name":"colinzhu/sql-template-builder","owner":"colinzhu","description":"Dynamically generate Vert.x SQL template and parameters","archived":false,"fork":false,"pushed_at":"2023-04-16T08:54:04.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-06T09:18:49.289Z","etag":null,"topics":["builder","dynamic","sql","sqltemplate","template","vertx"],"latest_commit_sha":null,"homepage":"","language":"Java","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/colinzhu.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}},"created_at":"2023-03-25T03:58:38.000Z","updated_at":"2023-03-25T04:05:01.000Z","dependencies_parsed_at":"2023-06-27T18:02:00.571Z","dependency_job_id":null,"html_url":"https://github.com/colinzhu/sql-template-builder","commit_stats":{"total_commits":7,"total_committers":1,"mean_commits":7.0,"dds":0.0,"last_synced_commit":"bfdeee9a98fa469e7f76f54effffcb35eb35da4c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/colinzhu/sql-template-builder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colinzhu%2Fsql-template-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colinzhu%2Fsql-template-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colinzhu%2Fsql-template-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colinzhu%2Fsql-template-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/colinzhu","download_url":"https://codeload.github.com/colinzhu/sql-template-builder/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/colinzhu%2Fsql-template-builder/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28594958,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T02:08:49.799Z","status":"ssl_error","status_checked_at":"2026-01-20T02:08:44.148Z","response_time":117,"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":["builder","dynamic","sql","sqltemplate","template","vertx"],"created_at":"2024-09-26T07:40:19.809Z","updated_at":"2026-01-20T02:46:51.547Z","avatar_url":"https://github.com/colinzhu.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SqlTemplateBuilder\n\n## Overview\n\n`SqlTemplateBuilder` is a Java class that allows you to easily build SQL SELECT or UPDATE statements with dynamic criteria, ORDER BY clauses, and FETCH FIRST clauses. This can be especially useful when working with database systems that require dynamic queries with user-defined criteria.\n\n## Usage\n\nTo use `SqlTemplateBuilder`, simply create a new instance of the class and set the `select`, `update`, `set` and `table` properties using the `select`, `update`, `set` and `table` methods, respectively. You can then chain together various criteria methods such as `eq`, `in`, `gtEq`, and `ltEq` to build up your WHERE clause. You can also set an ORDER BY clause using the `orderBy` method and a FETCH FIRST clause using the `fetchFirstX` method. Finally, you can call the `buildTemplate` method to get the resulting SQL statement and the `buildParams` method to get the parameter values to be used with the statement.\n\nHere's an example usage:\n\n```java\nSqlTemplateBuilder builder = new SqlTemplateBuilder()\n        .select(\"*\")\n        .table(\"employees\")\n        .eq(\"last_name\", null)\n        .in(\"department\", Set.of(\"Sales\", \"Marketing\"))\n        .gtEq(\"salary\", 5000)\n        .orderBy(\"last_name ASC\")\n        .fetchFirstX(10);\nString sql = builder.buildTemplate();\nMap\u003cString, Object\u003e params = builder.buildParams();\n```\n\nThe resulting SQL statement would be:\n```oracle-sql\nSELECT * FROM employees\nWHERE department IN (#{departmentin0},#{departmentin1})\nORDER BY #{orderBy} ASC FETCH FIRST #{fetchFirstX} ROWS ONLY\n```\n\nAnd the params map would contain the following key-value pairs:\n```\n{departmentin0=Marketing, departmentin1=Sales, fetchFirstX=10, orderBy=last_name ASC, salarygtEq=5000}\n```\n\n\n```java\nSqlTemplateBuilder builder = new SqlTemplateBuilder()\n        .update(true)\n        .table(\"employees\")\n        .set(\"last_name\", \"Flower\")\n        .set(\"first_name\", null)\n        .eq(\"last_name\", null)\n        .in(\"department\", Set.of(\"Sales\", \"Marketing\"))\n        .gtEq(\"salary\", 5000);\nString sql = builder.buildTemplate();\nMap\u003cString, Object\u003e params = builder.buildParams();\n```\n\nThe resulting SQL statement would be:\n```oracle-sql\nUPDATE employees SET last_name = #{last_nameset}\nWHERE department IN (#{departmentin0},#{departmentin1})\n```\n\nAnd the params map would contain the following key-value pairs:\n```\n{last_nameset=Flower, departmentin0=Marketing, departmentin1=Sales, salarygtEq=5000}\n```\n\nExample with Vert.x SqlTemplate:\n```java\n\nSqlTemplateBuilder builder = new SqlTemplateBuilder()\n        .select(\"*\")\n        .table(\"employees\")\n        .eq(\"last_name\", \"Smith\")\n        .in(\"department\", Set.of(\"Sales\", \"Marketing\"))\n        .gtEq(\"salary\", 50000)\n        .orderBy(\"last_name ASC\")\n        .fetchFirstX(10);\n\nSqlTemplate\n        .forQuery(client, builder.buildTemplate())\n        .execute(builder.buildParams())\n        .onSuccess(employees -\u003e {\n            employees.forEach(row -\u003e {\n                System.out.println(row.getString(\"last_name\") + \" \" + row.getString(\"last_name\"));\n            });\n        });\n  ```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcolinzhu%2Fsql-template-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcolinzhu%2Fsql-template-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcolinzhu%2Fsql-template-builder/lists"}