{"id":15890577,"url":"https://github.com/dimfeld/sqlweld","last_synced_at":"2025-04-02T17:20:57.128Z","repository":{"id":208518491,"uuid":"721834483","full_name":"dimfeld/sqlweld","owner":"dimfeld","description":"Piece together SQL query files from templates and partials","archived":false,"fork":false,"pushed_at":"2023-12-28T21:12:03.000Z","size":155,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-08T22:03:08.850Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://sqlweld.vercel.app","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dimfeld.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","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":"2023-11-21T21:41:53.000Z","updated_at":"2023-11-29T07:13:51.000Z","dependencies_parsed_at":"2023-11-24T08:24:52.085Z","dependency_job_id":"1a5af8ab-ad3c-48e7-82ba-ebe1412f697c","html_url":"https://github.com/dimfeld/sqlweld","commit_stats":null,"previous_names":["dimfeld/sqlweld"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dimfeld%2Fsqlweld","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dimfeld%2Fsqlweld/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dimfeld%2Fsqlweld/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dimfeld%2Fsqlweld/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dimfeld","download_url":"https://codeload.github.com/dimfeld/sqlweld/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246856583,"owners_count":20844974,"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":[],"created_at":"2024-10-06T07:06:49.021Z","updated_at":"2025-04-02T17:20:57.099Z","avatar_url":"https://github.com/dimfeld.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sqlweld\n\nsqlweld is a CLI tool designed to help manage large libraries of SQL statements that need to reuse the same SQL clauses.\n\n- Permissions checks often look very similar between queries, and updating these clauses is both tedious and a potential\n    source of security bugs.\n- Some queries need a number of slight variations, and while they can be formatted at runtime, this loses the benefits\n    that come from your queries being statically defined, especially with tools that do compile-time checking like\n    [sqlx](https://github.com/launchbadge/sqlx).\n\nsqlweld is designed to help solve these problems. Query files are [Tera](https://https://keats.github.io/tera/docs) templates ending in the\n`.sql.tera` extension. The Tera syntax is similar, though not exactly the same as, Jinja.\n\nPartials and macro files can end with `.macros.sql.tera` or `.partial.sql.tera`. The tool will render a `.sql` file for each\nnon-partial template it finds.\n\nsqlweld is also a Rust library and can used from a `build.rs` file. By setting the `print_rerun_if_changed` option,\nit will automatically print the appropriate statements to rerun if the queries change.\n\n# Installation\n\nCheck the [releases page](https://github.com/dimfeld/sqlweld/releases) for Homebrew, npm, curl, and other options. Of course, `cargo install sqlweld` also works if you already have Rust installed.\n\n# Watch Mode\n\nWatch mode is not directly supported yet. Until it is, a tool such as [watchexec](https://watchexec.github.io/) can\naccomplish the same functionality.\n\n```shell\nwatchexec --exts tera -- sqlweld -v\n```\n\n# Example\n\nThis example shows a simple use of the tool, with two queries that share a permissions check partial.\n\n## Input\n\n### get_some_objects.sql.tera\n\n```sql\n{% import \"perm_check\" as macros %}\nSELECT * FROM some_objects\nWHERE id=$[obj_id] AND team = $[team_id]\nAND {{ macros::perm_check(table=\"'some_objects'\") }}\n```\n\n### update_some_objects.sql.tera\n\n```sql\n{% import \"perm_check\" as macros %}\nUPDATE some_objects\nSET value = 'a' \nWHERE id=$[obj_id] AND team = $[team_id]\nAND {{ macros::perm_check(action=\"'write'\", table=\"'some_objects'\") }}\n```\n\n### perm_check.partial.sql.tera\n\n```sql\n{%- macro perm_check(user=\"$[user_id]\", team=\"$[team_id]\", action=\"'read'\", table) -%}\nEXISTS (\n  SELECT 1\n  FROM permissions\n  WHERE user_id = {{ user }}\n  AND team_id = {{ team }}\n  AND action = {{ action }}\n  AND object_type = {{table}}\n)\n{%- endmacro perm_check %}\n```\n\n## Output\n\n### get_some_objects.sql\n\n```sql\nSELECT * FROM some_objects\nWHERE id=$[obj_id] AND team = $[team_id]\nAND EXISTS (\n  SELECT 1\n  FROM permissions\n  WHERE user_id = $[user_id]\n  AND team_id = $[team_id]\n  AND action = 'read'\n  AND object_type = 'some_objects'\n)\n```\n\n### update_some_objects.sql\n\n```sql\nUPDATE some_objects\nSET value = 'a' \nWHERE id=$[obj_id] AND team = $[team_id]\nAND EXISTS (\n  SELECT 1\n  FROM permissions\n  WHERE user_id = $[user_id]\n  AND team_id = $[team_id]\n  AND action = 'write'\n  AND object_type = 'some_objects'\n)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdimfeld%2Fsqlweld","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdimfeld%2Fsqlweld","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdimfeld%2Fsqlweld/lists"}