Skip to main content

Crate sqlmodel_console

Crate sqlmodel_console 

Source
Expand description

SQLModel Console - Beautiful terminal output for SQLModel Rust.

sqlmodel-console is the optional UX layer for SQLModel Rust. It renders errors, query results, schema trees, and progress in a way that adapts to humans (rich formatting) or agents/CI (plain or JSON).

§Role In The Architecture

  • Optional integration: enabled via the console feature in sqlmodel or in driver crates.
  • Agent-safe output: auto-detects AI coding tools and switches to plain text.
  • Diagnostics: provides structured renderables for tables, errors, and status.

This crate provides styled console output that automatically adapts to the terminal environment. When running under an AI coding agent, output is plain text. When running interactively, output is richly formatted.

§Features

  • rich - Enable rich formatted output with colors, tables, panels
  • syntax - Enable SQL syntax highlighting (requires rich)
  • full - Enable all features

§Output Mode Detection

The crate automatically detects the appropriate output mode:

  • Plain: AI agents (Claude Code, Codex, etc.), CI systems, piped output
  • Rich: Interactive human terminal sessions
  • Json: Structured output for tool integrations

You can override detection via environment variables:

  • SQLMODEL_PLAIN=1 - Force plain text output
  • SQLMODEL_RICH=1 - Force rich output (even for agents)
  • SQLMODEL_JSON=1 - Force JSON structured output

§Example

use sqlmodel_console::OutputMode;

let mode = OutputMode::detect();
if mode.supports_ansi() {
    println!("Rich formatting available!");
} else {
    println!("Plain text mode");
}

Re-exports§

pub use console::SqlModelConsole;
pub use mode::OutputMode;
pub use theme::Theme;
pub use traits::ConsoleAware;

Modules§

console
SqlModelConsole - Main coordinator for console output.
logging
Logging infrastructure for sqlmodel-console.
mode
Output mode detection for agent-safe console output.
prelude
Prelude for convenient imports.
renderables
SQLModel-specific renderables.
theme
Theme definitions for SQLModel console output.
traits
Traits for console-aware components.
widgets
Progress indicators and interactive widgets.

Macros§

log_debug
Log a debug message.
log_error
Log an error message.
log_info
Log an info message.
log_trace
Log a trace message.
log_warn
Log a warning message.