CodeVetter · Repo Unpack · Data flow
diesel-rs/diesel
Library input becomes a typed query representation before a backend serializes binds and executes SQL. Connections own runtime caches and transaction state, while row conversion produces application values. CLI input combines arguments, environment variables, and TOML configuration before accessing databases or filesystem outputs. Migration state and generated schema files are separate persistence boundaries.
- QueryFragment::walk_ast defines AST-node behavior; to_sql performs a SQL-generation pass, while bind values are serialized separately from SQL placeholders.
- LoadQuery requires backend-compatible result types, converts the source through as_query, obtains a connection cursor, and maps each row through U::build_from_row with DeserializationError conversion.
- PostgreSQL collect_binds produces raw byte values and type metadata; with_prepared_query passes metadata to the statement cache and values separately to execution.
- The statement cache checks query cache safety, reuses occupied entries, registers newly prepared statements when capacity permits, and prepares uncached statements for unsafe or capacity-limited cases.
- CLI database URLs prefer explicit options over DATABASE_URL; config paths prefer arguments over DIESEL_CONFIG_FILE, and migration paths prefer arguments, MIGRATION_DIRECTORY, configuration, then ancestor discovery.
- SchemaResolverImpl owns catalog-result caching and a recursive resolution chain; requested tables load catalog metadata, views invoke load_view_data, and cycles return CyclicViewDefinition.
- Generated schema data passes through relation/custom-type formatting, rustfmt, and optional diffy patch application; print-schema writes to its output writer, while regeneration writes configured files or compares them in locked mode.
- SQL migration files are read into strings and passed to batch_execute; successful application inserts a version record, successful reversal deletes it, and applied versions are read in descending order.