Skip to content

Compile-time syntax checking of PostgreSQL queries

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

avstack/postgres-syntax

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

postgres-syntax

This crate provides simple compile-time syntax checking of PostgreSQL queries using the pg_query crate (currently version 5.1 which uses libpg_query 16-5.1.0).

It doesn't know anything about your schema, so it doesn't do type-checking or verify that tables you reference actually exist. It's just checking that the SQL syntax is valid. If you want type and name checking, you might prefer sqlx.

Crate

Example

The crate provides one macro, postgres_syntax::sql, which takes a string literal and passes it through if it's valid SQL syntax, or emits a compiler error if it's not valid SQL.

use postgres_syntax::sql;

let _ = sql!("SELECT name, email_address FROM user WHERE id = $1 BLARG");
error: failed to parse SQL query: syntax error at or near "BLARG"
 --> examples/bad_syntax.rs:4:11
  |
4 |   let _ = sql!("SELECT name, email_address FROM user WHERE id = $1 BLARG");
  |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |

License

postgres-syntax is licensed under either of

at your option.

Contribution

Any kinds of contributions are welcome as a pull request.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in these crates by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Acknowledgements

postgres-syntax development is sponsored by AVStack. We provide globally-distributed, scalable, managed A/V infrastructure.

About

Compile-time syntax checking of PostgreSQL queries

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published