{"id":23150890,"url":"https://github.com/cipherstash/sqltk","last_synced_at":"2025-08-17T19:32:07.275Z","repository":{"id":266400794,"uuid":"714906352","full_name":"cipherstash/sqltk","owner":"cipherstash","description":"sqltk","archived":false,"fork":false,"pushed_at":"2025-06-20T03:14:49.000Z","size":7295,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-28T07:35:50.824Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","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/cipherstash.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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}},"created_at":"2023-11-06T04:51:12.000Z","updated_at":"2025-06-20T03:14:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"953cd8f5-5240-4090-99e0-9e1676f18834","html_url":"https://github.com/cipherstash/sqltk","commit_stats":null,"previous_names":["cipherstash/sqltk"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/cipherstash/sqltk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cipherstash%2Fsqltk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cipherstash%2Fsqltk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cipherstash%2Fsqltk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cipherstash%2Fsqltk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cipherstash","download_url":"https://codeload.github.com/cipherstash/sqltk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cipherstash%2Fsqltk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270898250,"owners_count":24664700,"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","status":"online","status_checked_at":"2025-08-17T02:00:09.016Z","response_time":129,"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":[],"created_at":"2024-12-17T18:19:11.402Z","updated_at":"2025-08-17T19:32:07.256Z","avatar_url":"https://github.com/cipherstash.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sqltk\n\n`sqltk` is a toolkit for analysis and transformation of SQL statements, built on top of [`sqlparser`](https://crates.io/crates/sqlparser).\n\n## Features\n\n- A comprehensive `Visitor` trait and implementations for all `sqlparser` AST node types.\n\n- A `Transform` trait for rewriting ASTs (`sqltk` does not provide a `VisitorMut` trait).\n\n### Comprehensive Visitor trait with more useful AST traversal order\n\n`sqlparser`'s `Visitor` implementation only contains callbacks for a handful of AST node types.\n\nIn contrast, `sqltk`'s implementation will invoke `Visitor::enter` and `Visitor::exit` for _all_ `sqlparser` node types.\n\nAdditionally, `sqltk` traverses the AST in an order that is useful for semantic analysis  - specifically any node that might be _referred to_ by another node will be visited _before_ a node that might refer to it.\n\nThis means your `Visitor` implementations can safely assume that any semantic dependencies of the node being visited have already been visited.\n\nFor example, in a `SELECT` statement the `FROM` clause will be visited before the projection or the `WHERE` clause etc.\n\nThe analysis that determines AST traversal order happens at compile time (see `packages/sqltk-codegen`).\n\n### Transform trait\n\nThe `Transform` trait contains a single method imaginitively named `transform`. Which takes a reference to the *original* AST node and an owned clone of the node as arguments. Edits are applied to the owned node and returned in a `Result`.\n\nThe reason for this existence of this trait is so that metadata about nodes (from a previous analysis step) which inform the transformation process can be held in the type that implements `Transform`. These will be regular Rust shared references to AST nodes (and therefore read-only). Which would *prevent* mutation of the nodes in-place because Rust will not allow coexistence of `\u0026node` and `\u0026mut node`.\n\n`sqlparser`'s `VisitorMut::visit_mut` method accepts a `\u0026mut node` argument, thus preventing coexistance of references to nodes in another data structure - which rules out the use of some patterns for associating metadata with those nodes.\n\nTransformation begins at the leaf nodes of the AST (AKA depth-first) and ends at the root node.\n\n## Getting started\n\nAdd `sqltk` to your Cargo project\n\n`$ cargo add sqltk`\n\nIf you plan to hack on `sqltk` itself then you will need to install `cargo-expand` if you plan on running the code generator.\n\n`$ cargo install cargo-expand`\n\n  \u003e NOTE: `cargo-expand` invokes Rust *nightly* to do its job. Therefore a nightly Rust toolchain must be installed. However, `sqltk`'s generated code does not require a nightly compiler.\n\n## `sqltk-codegen`\n\nAnalyses `sqlparser` source code and generates:\n\n- Analyzes the `sqlparser` AST in order to determine an AST traversal order for single-pass semantic analysis workloads\n- Generates the `Visitable` trait implementations for all AST node types\n- Generates the `Transformer` trait implementations for all AST node types\n- Generates the `AsNodeKey` trait implementations\n\nTo update:\n\n```bash\n# Run the code generation\ncargo run -p sqltk-codegen\n\n# Commit the changes\ngit add packages/sqltk/src/generated\ngit commit -m 'Re-generated trait implementations with `cargo run -p sqltk-codegen`'\n```\n\nYou will need to do this whenever:\n\n- You are updating sqltk-parser from [upstream](https://github.com/apache/datafusion-sqlparser-rs), and\n- Any AST handling in sqltk-parser has changed\n\n## `sqltk-parser`\n\nAs noted below, `sqltk-parser` is a soft fork of `sqlparser` (now an Apache project as [datafusion-sqlparser-rs](https://github.com/apache/datafusion-sqlparser-rs)).\n\nIf you are a developer on the sqltk project, the `pull-upstream-sqlparser.sh` script (with inline documentation) can assist in pulling in updates from this upstream library.\n\n## About\n\n`sqltk` is maintained by CipherStash and is a core component of [Proxy](https://cipherstash.com/products/cipherstash-proxy), our encryption-in-use database proxy.\n\n`packages/sqltk-parser` is a soft fork of [datafusion-sqlparser-rs](https://github.com/apache/datafusion-sqlparser-rs), and its use is governed by the [Apache Software License 2.0](https://github.com/apache/datafusion-sqlparser-rs/blob/main/LICENSE.txt).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcipherstash%2Fsqltk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcipherstash%2Fsqltk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcipherstash%2Fsqltk/lists"}