#escaping #sql-query #sql

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

#1460 in Database interfaces

Download history 19/week @ 2023-12-04 4/week @ 2023-12-11 48/week @ 2023-12-18 3/week @ 2024-01-01 17/week @ 2024-01-08 33/week @ 2024-01-15 13/week @ 2024-01-22 23/week @ 2024-01-29 45/week @ 2024-02-05 106/week @ 2024-02-12 86/week @ 2024-02-19 57/week @ 2024-02-26 32/week @ 2024-03-04 69/week @ 2024-03-11 23/week @ 2024-03-18

194 downloads per month

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

~440KB