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
255 downloads per month
Used in 2 crates
20KB
417 lines
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
andOrd
. - 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