Expand description
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
Macros§
Structs§
- Column
- Represents table column name.
- Column
Schema - Represents column name and type for given SQL
Dialect
. - Column
Type - Represents column type for given SQL
Dialect
. - MapQuoted
Data - Wrapper around
QuotedData
that maps its content. - Monet
DbDialect - MonetDB SQL dialect.
- Object
- Generic object like table, schema, column etc. based
ObjectConcat
escaping rules. - Object
Concat - Concatenation of strings with object escaping rules.
- Object
Concat Display - Owned variant of
ObjectConcat
to be returned asimpl Display
. - Predicate
Statement - SQL statment with boolean logic.
- Predicates
- Collection of boolean predicates.
- Quoted
Data - Strings and other data in single quotes.
- Quoted
Data Concat - Concatenation of strings with quoted data escaping rules.
- Quoted
Data Concat Display - Owned variant of
QuotedDataConcat
to be returned asimpl Display
. - Schema
- Represents database schema name.
- Schema
Table - Represents table name in a schema.
- SqlServer
Dialect - SQL Server SQL dialect.
- Table
- Represents database table name.
Traits§
- Dialect
- SQL dialect of a database.
- SqlData
Type - Provide SQL data types in given dialect corresponding to Rust types.