Skip to content

feat(ffi): expose sqlglot_generate_pretty with dialect-aware formatting - #24

Merged
yigalrozenberg merged 1 commit into
protegrity:masterfrom
AccountAim:feat/pretty-generate-ffi
Jul 21, 2026
Merged

feat(ffi): expose sqlglot_generate_pretty with dialect-aware formatting#24
yigalrozenberg merged 1 commit into
protegrity:masterfrom
AccountAim:feat/pretty-generate-ffi

Conversation

@gauravs

@gauravs gauravs commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Adds pretty-printing to the FFI and fixes generate_pretty to actually respect the target dialect.

Previously generate_pretty(ast, dialect) ignored its dialect argument, so formatted output always used source/ANSI quoting instead of the target's.

Changes

  • Fix generate_pretty to honor the target dialect
  • Add Generator::generate_pretty method; deprecate Generator::pretty
  • New FFI export sqlglot_generate_pretty; update C/C++ examples and docs
  • Bump 0.10.17

Before / after

Parsing MySQL and pretty-printing as T-SQL:

let ast = parse("SELECT `select` FROM `events`", Dialect::Mysql).unwrap();
let out = generate_pretty(&ast, Dialect::Tsql);

// Before — dialect ignored, MySQL backticks leak through:
SELECT
  `select`
FROM
  `events`

// After — normalized to T-SQL quoting:
SELECT
  [select]
FROM
  [events]

- fix generate_pretty to honor the target dialect (previously ignored)
- add Generator::generate_pretty method; deprecate Generator::pretty
- add sqlglot_generate_pretty FFI export; update C/C++ examples and docs
- bump 0.10.17
@yigalrozenberg
yigalrozenberg merged commit 996fcf4 into protegrity:master Jul 21, 2026
5 checks passed
@yigalrozenberg

Copy link
Copy Markdown
Collaborator

Thank you for this contribution, @gauravs!

This is a clean, well-tested improvement. Making generate_pretty honor the target dialect (instead of silently falling back to source/ANSI quoting) is a nice correctness win, and exposing sqlglot_generate_pretty through the FFI — with matching C/C++ examples and docs — rounds it out really well. The two new test files made verification straightforward.

Merged and released in v0.10.21, now live on crates.io.

One small adjustment on merge: since master had already advanced to 0.10.20, I resolved the version bump to 0.10.21 and updated the #[deprecated(since = ...)] note on Generator::pretty to match the actual release version. Everything else went in exactly as you wrote it.

Thanks again for helping improve sqlglot-rust!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants