Skip to main content

Crate drizzle_core

Crate drizzle_core 

Source
Expand description

SQL building blocks shared by every Drizzle dialect.

Most users depend on the drizzle crate, which re-exports this one as drizzle::core. This crate holds the parts that do not depend on a database:

  • SQL and ToSQL: SQL fragments with bound parameters.
  • expr: typed expressions and functions (eq, count, coalesce, …).
  • row and scope: compile-time row-type inference and query checks.
  • traits: the table, column, and schema traits the macros implement.
  • dialect: dialect markers and dialect-only feature gates.
  • error::DrizzleError: the error type every driver returns.

§Examples

Building a fragment by hand. Value stands in for a driver’s value type (SQLiteValue, PostgresValue, …):

use drizzle_core::{SQL, Token};

let query: SQL<'_, Value> = SQL::raw("SELECT * FROM")
    .append(SQL::ident("users"))
    .push(Token::WHERE)
    .append(SQL::ident("id"))
    .push(Token::EQ)
    .append(SQL::param(Value(42)));

assert_eq!(query.sql(), r#"SELECT * FROM "users" WHERE "id" = ?"#);
assert_eq!(query.params().count(), 1);

§Compile-time checks

Queries are checked when they are built and run, not when they reach the database. The compiler rejects a query that:

§no_std Support

This crate supports no_std environments with an allocator:

# With std (default)
drizzle-core = "0.2"

# no_std with allocator
drizzle-core = { version = "0.2", default-features = false, features = ["alloc"] }

Re-exports§

pub use bind::BindValue;
pub use bind::NullableBindValue;
pub use bind::ValueTypeForDialect;
pub use builder::BuilderInit;
pub use builder::ClauseAllowed;
pub use builder::ExecutableState;
pub use builder::InsertColumnsSet;
pub use builder::clause;
pub use derived::Derived;
pub use derived::DerivedField;
pub use dialect::DialectSupports;
pub use dialect::DialectTypes;
pub use dialect::MySQLDialect;
pub use dialect::PostgresDialect;
pub use dialect::SQLiteDialect;
pub use dialect::feature;
pub use join::Join;
pub use join::JoinType;
pub use pagination::PaginationArg;
pub use param::OwnedParam;
pub use param::Param;
pub use param::ParamBind;
pub use param::ParamSet;
pub use relation::JoinExplicit;
pub use relation::JoinForward;
pub use relation::JoinKey;
pub use relation::JoinReverse;
pub use relation::Joinable;
pub use relation::Relation;
pub use relation::SchemaHasTable;
pub use row::DecodeSelectedRef;
pub use row::ExprValueType;
pub use row::FromDrizzleRow;
pub use row::GroupByIdentity;
pub use row::HasSelectModel;
pub use row::IntoGroupBy;
pub use row::IntoSelectTarget;
pub use row::JoinedStarRow;
pub use row::MarkerAggValidFor;
pub use row::MarkerColumnCountValid;
pub use row::MarkerScopeValidFor;
pub use row::NullProbeRow;
pub use row::PkGroup;
pub use row::ResolveRow;
pub use row::RowColumnList;
pub use row::SQLTypeToRust;
pub use row::SelectAs;
pub use row::SelectAsFrom;
pub use row::SelectCols;
pub use row::SelectExpr;
pub use row::SelectStar;
pub use row::SelectTableFields;
pub use row::TableFields;
pub use row::WrapNullable;
pub use schema::OrderBy;
pub use schema::OrderTerm;
pub use schema::Ordered;
pub use schema::asc;
pub use schema::desc;
pub use scope::AliasKey;
pub use scope::FromMarker;
pub use scope::FullJoin;
pub use scope::HasScope;
pub use scope::InnerJoin;
pub use scope::JoinStep;
pub use scope::Lateral;
pub use scope::LeftJoin;
pub use scope::OuterJoined;
pub use scope::RightJoin;
pub use scope::ScopeContains;
pub use scope::ScopeEntry;
pub use scope::Scoped;
pub use scope::SelectSources;
pub use scope::SetOperand;
pub use scope::Src;
pub use sql::ColumnDialect;
pub use sql::ColumnFlags;
pub use sql::ColumnRef;
pub use sql::ColumnSqlRef;
pub use sql::ConstraintRef;
pub use sql::EnumVariantRef;
pub use sql::ForeignKeyRef;
pub use sql::OwnedSQL;
pub use sql::OwnedSQLChunk;
pub use sql::PrimaryKeyRef;
pub use sql::SQL;
pub use sql::SQLChunk;
pub use sql::SQLEnumVariants;
pub use sql::TableDialect;
pub use sql::TableRef;
pub use sql::TableSqlRef;
pub use sql::Token;
pub use placeholder::*;
pub use traits::*;

Modules§

bind
builder
conv
Value-conversion helpers shared by the dialect crates’ value decoding.
cte
Driver-neutral common table expression types.
derived
Typed derived-table projections.
dialect
Dialect markers, per-dialect type mappings, and dialect-only features.
error
The error type shared by every Drizzle crate and driver.
expr
Type-safe SQL expressions: comparisons, logic, aggregates and functions.
helpers
Free functions that render single SQL clauses (SELECT ..., WHERE ..., LIMIT ..., UNION, …).
join
JOIN keywords and the macros dialect crates use to build join helpers.
pagination
param
placeholder
prepared
relation
Traits that describe foreign-key relations between tables, generated by the table and schema macros.
row
Row type inference and row decoding for SELECT queries.
schema
Schema metadata for database enums, and ORDER BY terms.
scope
Compile-time checks that a query only reads tables it has joined.
sql
tracing
Macros that emit tracing events for queries and transactions.
traits
Traits for schema items (tables, columns, indexes, views, …) and SQL rendering.
types
Re-exports SQL type markers and type-level compatibility traits.

Macros§

drizzle_trace_query
Emits a debug-level drizzle.query event with the SQL text and parameter count.
drizzle_trace_tx
Emits an info-level drizzle.transaction event for a transaction step (begin, commit, rollback).
impl_join_arg_trait
Generates a dialect’s JoinArg trait: what .join(...) and its variants accept.
impl_join_helpers
Generates free functions that render join clauses (join, left_join, natural_full_outer_join, …) for one dialect.
impl_try_from_int
Implements TryFrom<int> for several integer types by converting to i64 and calling the type’s TryFrom<i64>.
tag
Defines a Tag type in one line.

Enums§

Dialect
The SQL dialect a value type or schema targets, known at runtime. A supported SQL database: SQLite, PostgreSQL or MySQL.