{"id":20704136,"url":"https://github.com/solidsnack/sqlmod","last_synced_at":"2025-06-23T05:04:23.117Z","repository":{"id":66073502,"uuid":"86516115","full_name":"solidsnack/sqlmod","owner":"solidsnack","description":"Provides support for sharing SQL queries across projects and avoiding those long and confusing, un-highlighted, embedded SQLs that often grow out of analytics and optimization projects.","archived":false,"fork":false,"pushed_at":"2017-03-28T23:10:17.000Z","size":51,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-23T05:02:22.099Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","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/solidsnack.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":"2017-03-28T23:09:30.000Z","updated_at":"2017-03-31T08:38:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"d4d75aed-df1e-4b8f-8e80-2c4924cbb104","html_url":"https://github.com/solidsnack/sqlmod","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/solidsnack/sqlmod","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solidsnack%2Fsqlmod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solidsnack%2Fsqlmod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solidsnack%2Fsqlmod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solidsnack%2Fsqlmod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/solidsnack","download_url":"https://codeload.github.com/solidsnack/sqlmod/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solidsnack%2Fsqlmod/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261417551,"owners_count":23155069,"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-11-17T01:11:11.131Z","updated_at":"2025-06-23T05:04:18.098Z","avatar_url":"https://github.com/solidsnack.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `sqlmod`\n\nModular SQL excitement: `sqlmod` allows you to treat a file of SQL queries as a\nmodule in your favorite programming language.\n\nFor longer queries, embedding as strings is error prone and confusing; and ORMs\nand SQL expression languages don't generally provide clear and communicative\naccess to analytic functionality. A collection of named queries in a separate\nfile:\n\n* allows queries to be shared between projects,\n* allows queries to be shared with analysts and copy-pasted into BI tools,\n* allows access to advanced or database specific SQL in a way that is more\n  modular and readable than embedded SQL.\n\n## Example\n\n```sql\n--@ now ro\nSELECT now()\n\n--@ maybe_create_user\n--- Uses anonymous PL/pgSQL to handle potentially redundant user creation.\nDO $$\nDECLARE\n  sql_state text;\nBEGIN\n  BEGIN\n    CREATE ROLE the_user;\n  EXCEPTION\n    WHEN duplicate_object THEN\n      --- Do nothing.\n    WHEN OTHERS THEN\n      GET STACKED DIAGNOSTICS sql_state = RETURNED_SQLSTATE;\n      RAISE INFO 'SQLState: %', sql_state;\n  END;\nEND\n$$;\n```\n\n## Historical Context\n\nORMs provide a way to work with SQL databases without writing SQL. This is\ngreat for those cases where the database is more or less modelling a hash\ntable; but little provision is made for bulk operations, aggregations, windows\nor administrative commands. SQL expression languages, like SQLAlchemy, allow us\nto go further with SQL, but these tools stress portability more than exactness,\nwhich can make granular control of the resulting query or its plan impossible.\n\nAnalysts have historically used SQL directly for both prototyping and\nproduction analysis.\n\nTo make use of raw SQL, either to facilitate cooperation with analysts, control\nperformance or access advanced features, developers use some form of embedded\nSQL. As a formal part of the SQL standard, \"embedded SQL\" includes a\npre-processor to rewrite the code to insert the actual database calls and type\ntranslation. This approach is well documented for the Oracle database, which\noffers a variety of bindings: Ada, Pascal, C, Fortran. Postgres, on the other\nhand, only provides it for C.\n\nEmbedded SQL is disadvantageous because of the absence of syntax highlighting\nand the awkward formatting of the queries (double-escaping and weird\nindentation, \u0026c). Embedded SQL, like ORMs, can make it hard to tell exactly\nwhat queries an app issues or where it issues them from.\n\nTo address the awkwardness implicit in embedded SQL, there arose _SQL modules_.\nThere is a SQL module processor that is part of Oracle and the Vax had one, as\nwell. These systems generally operate on an extended SQL, which contains\ndeclarations similar to prepared statements. The extended SQL is compiled to\nthe target language, usually a statically typed language like Pascal or C.\n\nWhile the principle of separating queries into their own file inspired\n`sqlmod`, which thus finds its historical ancestors in these SQL module\nlanguages, the queries are not compiled but rather parsed into objects which\ncan be introspected as well as directly executed. This keeps the implementation\nsmall and allows for both interactive development and flexible debugging, while\nretaining the modularity and clarity advantages of SQL modules.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolidsnack%2Fsqlmod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsolidsnack%2Fsqlmod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolidsnack%2Fsqlmod/lists"}