Crate format_sql_query

Source
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 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

Macros§

impl_sql_data_type

Structs§

Column
Represents table column name.
ColumnSchema
Represents column name and type for given SQL Dialect.
ColumnType
Represents column type for given SQL Dialect.
MapQuotedData
Wrapper around QuotedData that maps its content.
MonetDbDialect
MonetDB SQL dialect.
Object
Generic object like table, schema, column etc. based ObjectConcat escaping rules.
ObjectConcat
Concatenation of strings with object escaping rules.
ObjectConcatDisplay
Owned variant of ObjectConcat to be returned as impl Display.
PredicateStatement
SQL statment with boolean logic.
Predicates
Collection of boolean predicates.
QuotedData
Strings and other data in single quotes.
QuotedDataConcat
Concatenation of strings with quoted data escaping rules.
QuotedDataConcatDisplay
Owned variant of QuotedDataConcat to be returned as impl Display.
Schema
Represents database schema name.
SchemaTable
Represents table name in a schema.
SqlServerDialect
SQL Server SQL dialect.
Table
Represents database table name.

Traits§

Dialect
SQL dialect of a database.
SqlDataType
Provide SQL data types in given dialect corresponding to Rust types.