#escaping #sql-query #sql #helper

format-sql-query

Collection of types and helpers for building hopefully correctly escaped SQL queries

5 releases (3 breaking)

0.4.0 Jun 23, 2020
0.3.1 Jan 17, 2020
0.3.0 Dec 18, 2019
0.2.0 Oct 29, 2019
0.1.0 Aug 28, 2019

#1772 in Database interfaces

Download history 32/week @ 2024-07-21 62/week @ 2024-07-28 70/week @ 2024-08-04 36/week @ 2024-08-11 57/week @ 2024-08-18 54/week @ 2024-08-25 65/week @ 2024-09-01 22/week @ 2024-09-08 46/week @ 2024-09-15 74/week @ 2024-09-22 36/week @ 2024-09-29 119/week @ 2024-10-06 86/week @ 2024-10-13 99/week @ 2024-10-20 22/week @ 2024-10-27 38/week @ 2024-11-03

255 downloads per month
Used in 2 crates

MIT license

20KB
417 lines

Latest Version Documentation License

Collection of types and helpers for building hopefully correctly escaped SQL queries.

Example usage

use format_sql_query::*;

println!("SELECT {} FROM {} WHERE {} = {}", Column("foo bar".into()), SchemaTable("foo".into(), "baz".into()), Column("blah".into()), QuotedData("hello 'world' foo"));
// SELECT "foo bar" FROM foo.baz WHERE blah = 'hello ''world'' foo'

lib.rs:

Collection of types and helpers for building hopefully correctly escaped SQL queries.

Example usage

use format_sql_query::*;

println!("SELECT {} FROM {} WHERE {} = {}", Column("foo bar".into()), SchemaTable("foo".into(), "baz".into()), Column("blah".into()), QuotedData("hello 'world' foo"));
// SELECT "foo bar" FROM foo.baz WHERE blah = 'hello ''world'' foo'

Design goals

  • All objects will implement Display to get escaped and perhaps quoted formatting that can be used directly in SQL statements.
  • Avoid allocations by making most types just wrappers around string slices.
  • New-type patter that is used to construct an object out of strings and other objects.
  • Generous From trait implementations to make it easy to construct objects from strings.
  • All single field new-type objects will implement .as_str() to get original value.
  • Types that are string slice wrappers implement Copy to make them easy to use.
  • Types should implement Eq and Ord.
  • New-type objects with more than one filed should have getters.
  • When returning types make sure they don't reference self but the original string slice lifetime.

All objects are using base escaping rules wrappers:

  • ObjectConcat for table names, schemas, columns etc.
  • QuotedDataConcat for data values

Dependencies

~460KB