### Configure SQL Check Features in Cargo.toml Source: https://github.com/tamaro-skaljic/sql-check/blob/main/README.md This example illustrates how to configure the `sql-check` crate with specific features in Cargo.toml. It includes enabling PostgreSQL support, Tokio runtime, and rustls TLS. ```toml [dependencies] sql-check = { version = "0.9.0-alpha.1", features = ["postgres", "_rt-tokio", "_tls-rustls-ring-webpki"] } ``` -------------------------------- ### Run SQLite Tests with sql-check Source: https://github.com/tamaro-skaljic/sql-check/blob/main/TESTING.md Executes the sql-check tests using an in-memory SQLite database. This command requires no external database setup and uses specific features for SQLite, the Tokio runtime, and Rustls TLS. ```bash DATABASE_URL="sqlite::memory:" cargo test --features sqlite,_rt-tokio,_tls-rustls-ring-webpki --tests ``` -------------------------------- ### Add SQL Check Dependency to Cargo.toml Source: https://github.com/tamaro-skaljic/sql-check/blob/main/README.md This snippet shows how to add the sql-check crate to your project's Cargo.toml file. It includes examples for basic installation and enabling specific database support like PostgreSQL. ```toml [dependencies] sql-check = "0.9.0-alpha.1" # Enable database support sql-check = { version = "0.9.0-alpha.1", features = ["postgres"] } ``` -------------------------------- ### Overwrite Compile-Fail Test Errors for MySQL Source: https://github.com/tamaro-skaljic/sql-check/blob/main/TESTING.md Updates the expected error messages for MySQL compile-fail tests. This command is used when error formats change or for new database setups, requiring the 'mysql' feature and Tokio runtime. ```bash DATABASE_URL="mysql://root:password@localhost:3306/sqlcheck" TRYBUILD=overwrite cargo test \ --features mysql,_rt-tokio,_tls-rustls-ring-webpki compile_fail_tests_mysql ``` -------------------------------- ### Overwrite Compile-Fail Test Errors for PostgreSQL Source: https://github.com/tamaro-skaljic/sql-check/blob/main/TESTING.md Updates the expected error messages for PostgreSQL compile-fail tests. This command is used when error formats change or for new database setups, requiring the 'postgres' feature and Tokio runtime. ```bash DATABASE_URL="postgres://username:password@localhost:5432/sqlcheck" TRYBUILD=overwrite cargo test \ --features postgres,_rt-tokio,_tls-rustls-ring-webpki compile_fail_tests_postgres ``` -------------------------------- ### Example of Compile Error with Invalid SQL in SQL Check Source: https://github.com/tamaro-skaljic/sql-check/blob/main/README.md This Rust code snippet demonstrates an invalid SQL query that will cause a compile-time error when processed by the `sql_check::check!` macro. The expected output is a compilation error detailing the SQL validation failure. ```rust let sql = check!("SELECT invalid_column FROM nonexistent_table"); ``` -------------------------------- ### Build Rust Project with or Without SQL Validation Source: https://context7.com/tamaro-skaljic/sql-check/llms.txt Illustrates the command-line arguments for building a Rust project with and without the SQL validation feature enabled. `--no-default-features` disables the `check` feature, while setting `DATABASE_URL` is required when validation is active. ```bash # Build without validation car go build --release --no-default-features # Build with validation DATABASE_URL="postgres://..." cargo build ``` -------------------------------- ### Run MySQL Tests with sql-check Source: https://github.com/tamaro-skaljic/sql-check/blob/main/TESTING.md Executes the sql-check tests against a MySQL database. Requires a running MySQL server, a created 'sqlcheck' database, and correct credentials. It uses features for MySQL, Tokio, and Rustls TLS. ```bash DATABASE_URL="mysql://root:password@localhost:3306/sqlcheck" cargo test \ --features mysql,_rt-tokio,_tls-rustls-ring-webpki --tests ``` -------------------------------- ### Run PostgreSQL Tests with sql-check Source: https://github.com/tamaro-skaljic/sql-check/blob/main/TESTING.md Executes the sql-check tests against a PostgreSQL database. Requires a running PostgreSQL server, a created 'sqlcheck' database, and correct credentials. It uses features for PostgreSQL, Tokio, and Rustls TLS. ```bash DATABASE_URL="postgres://username:password@localhost:5432/sqlcheck" cargo test \ --features postgres,_rt-tokio,_tls-rustls-ring-webpki --tests ``` -------------------------------- ### Basic Compile-time SQL Validation in Rust Source: https://github.com/tamaro-skaljic/sql-check/blob/main/README.md Demonstrates the basic usage of the `check!` macro from the `sql-check` crate in Rust. This macro validates a SQL query at compile time and returns the SQL string for use with database libraries. ```rust use sql_check::check; // This will be validated at compile time let sql = check!("SELECT * FROM users WHERE id = 1"); // Use the SQL string with your database library let result = database.execute(sql).await?; ``` -------------------------------- ### Set DATABASE_URL Environment Variable for SQL Check Source: https://github.com/tamaro-skaljic/sql-check/blob/main/README.md Shows how to set the `DATABASE_URL` environment variable before building a Rust project that uses `sql-check`. This variable is required for the compile-time database connection and validation. ```bash # Set DATABASE_URL before building export DATABASE_URL="postgres://user:pass@localhost/mydb" cargo build ``` -------------------------------- ### Run sql-check Tests Without Validation Source: https://github.com/tamaro-skaljic/sql-check/blob/main/TESTING.md Executes the sql-check tests without enabling compile-time SQL validation. This command disables the default features and focuses on runtime behavior. ```bash cargo test --no-default-features --tests ``` -------------------------------- ### PostgreSQL Configuration for SQL Check (Rust) Source: https://context7.com/tamaro-skaljic/sql-check/llms.txt Configure SQL Check for PostgreSQL by enabling the `postgres` feature in `Cargo.toml`, along with an async runtime and TLS backend. Set the `DATABASE_URL` environment variable to your PostgreSQL connection string before building. ```toml # Cargo.toml [dependencies] sql-check = { version = "0.9.0-alpha.1", features = ["postgres", "_rt-tokio", "_tls-rustls-ring-webpki"] } ``` ```bash # Set environment variable before building export DATABASE_URL="postgres://user:password@localhost:5432/mydb" cargo build ``` ```rust use sql_check::check; fn main() { // PostgreSQL-specific syntax is validated let query = check!("SELECT COALESCE(NULL, 'default')"); let serial_table = check!( "CREATE TABLE IF NOT EXISTS users (\n id SERIAL PRIMARY KEY,\n name TEXT NOT NULL,\n created_at TIMESTAMPTZ DEFAULT NOW()\n )" ); // Use the validated SQL with any PostgreSQL client library // e.g., tokio-postgres, diesel, etc. } ``` -------------------------------- ### Validate SQLite SQL Queries at Compile Time Source: https://context7.com/tamaro-skaljic/sql-check/llms.txt Demonstrates how to use the `check!` macro to validate SQLite-specific SQL syntax during compilation. This requires the `DATABASE_URL` environment variable to be set for the target SQLite database. ```rust use sql_check::check; fn main() { // SQLite-specific syntax validation let query = check!("SELECT datetime('now')"); let coalesce = check!("SELECT COALESCE(NULL, 'default')"); let create_table = check!( "CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, email TEXT UNIQUE NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP )" ); // SQLite uses ? for parameters let insert = check!("INSERT INTO users (name, email) VALUES (?, ?)"); } ``` -------------------------------- ### MySQL Configuration for SQL Check (Rust) Source: https://context7.com/tamaro-skaljic/sql-check/llms.txt Configure SQL Check for MySQL by enabling the `mysql` feature in `Cargo.toml`. MySQL uses `?` for parameter placeholders and has different syntax for auto-increment columns. Set the `DATABASE_URL` environment variable to your MySQL connection string. ```toml # Cargo.toml [dependencies] sql-check = { version = "0.9.0-alpha.1", features = ["mysql", "_rt-tokio", "_tls-rustls-ring-webpki"] } ``` ```bash export DATABASE_URL="mysql://user:password@localhost:3306/mydb" cargo build ``` ```rust use sql_check::check; fn main() { // MySQL-specific syntax validation let query = check!("SELECT IFNULL(NULL, 'default')"); let query_now = check!("SELECT NOW()"); let create_table = check!( "CREATE TABLE IF NOT EXISTS users (\n id INT AUTO_INCREMENT PRIMARY KEY,\n name VARCHAR(255) NOT NULL,\n email VARCHAR(255) UNIQUE NOT NULL,\n created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n )" ); // MySQL uses ? for parameters let insert = check!("INSERT INTO users (name, email) VALUES (?, ?)"); let update = check!("UPDATE users SET name = ? WHERE id = ?"); } ``` -------------------------------- ### Configure SQL Check Feature Flags in Cargo.toml Source: https://context7.com/tamaro-skaljic/sql-check/llms.txt Shows how to manage the `check` feature flag in `Cargo.toml` to enable or disable SQL validation. Disabling the `check` feature (using `default-features = false`) is recommended for production builds to avoid runtime overhead. ```toml # Cargo.toml - Development (validation enabled) [dependencies] sql-check = { version = "0.9.0-alpha.1", features = ["postgres", "_rt-tokio", "_tls-rustls-ring-webpki"] } # Production (validation disabled) [dependencies] sql-check = { version = "0.9.0-alpha.1", default-features = false } ``` -------------------------------- ### Toggle SQL Validation Feature in Rust Code Source: https://context7.com/tamaro-skaljic/sql-check/llms.txt Demonstrates how to conditionally compile code based on the `check` feature flag. When the `check` feature is disabled, the `check!` macro acts as a no-op, returning the SQL string without validation, which is useful for production environments. ```rust use sql_check::check; fn main() { // When check feature is ENABLED: // - Validates SQL at compile time // - Requires DATABASE_URL to be set // - Invalid SQL causes compilation error // When check feature is DISABLED: // - No validation occurs // - No DATABASE_URL required // - All SQL strings pass through unchanged let sql = check!("SELECT 1"); // Works in both modes #[cfg(not(feature = "check"))] { // This compiles when check is disabled (no validation) let invalid = check!("THIS IS NOT VALID SQL"); println!("Invalid SQL passed: {}", invalid); } } ``` -------------------------------- ### Overwrite Compile-Fail Test Errors for SQLite Source: https://github.com/tamaro-skaljic/sql-check/blob/main/TESTING.md Updates the expected error messages for SQLite compile-fail tests. This is useful when error formats change or when setting up for a new database. It requires the 'sqlite' feature and Tokio runtime. ```bash DATABASE_URL="sqlite::memory:" TRYBUILD=overwrite cargo test \ --features sqlite,_rt-tokio,_tls-rustls-ring-webpki compile_fail_tests_sqlite ``` -------------------------------- ### Compile-Time Error Handling for Invalid SQL Source: https://context7.com/tamaro-skaljic/sql-check/llms.txt Shows how the `check!` macro generates compile-time errors when invalid SQL is detected. The error message includes the database's specific error details and the exact location of the invalid SQL in the source code. ```rust use sql_check::check; fn main() { // This causes a compile-time error: let _sql = check!("SELECT * FROM this_table_does_not_exist_anywhere"); } // Compile error output: // error: SQL validation failed: error returned from database: relation "this_table_does_not_exist_anywhere" does not exist // --> src/main.rs:4:16 // | // 4 | let _sql = check!("SELECT * FROM this_table_does_not_exist_anywhere"); // | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // Syntax errors are also caught: // let _sql = check!("SELECT FROM WHERE"); // error: SQL validation failed: syntax error at or near "FROM" ``` -------------------------------- ### Disable SQL Check Validation using Cargo Build Flags Source: https://github.com/tamaro-skaljic/sql-check/blob/main/README.md Illustrates how to disable the default features for `sql-check` using cargo build flags, specifically `--no-default-features`. This is an alternative method to disabling compile-time validation for production builds. ```bash cargo build --release --no-default-features ``` -------------------------------- ### SQLite Configuration for SQL Check (Rust) Source: https://context7.com/tamaro-skaljic/sql-check/llms.txt Configure SQL Check for SQLite by enabling the `sqlite` feature in `Cargo.toml`. SQLite supports in-memory databases, which can be used for compile-time validation by setting `DATABASE_URL` to `sqlite::memory:`. ```toml # Cargo.toml [dependencies] sql-check = { version = "0.9.0-alpha.1", features = ["sqlite", "_rt-tokio", "_tls-rustls-ring-webpki"] } ``` ```bash # In-memory database export DATABASE_URL="sqlite::memory:" ``` -------------------------------- ### check! Macro - Compile-Time SQL Validation (Rust) Source: https://context7.com/tamaro-skaljic/sql-check/llms.txt The `check!` macro validates SQL queries at compile time. It connects to a database specified by `DATABASE_URL` and expands to the SQL string literal if valid, or produces a compilation error if invalid. Supports various SQL statements, including parameterized queries. ```rust use sql_check::check; fn main() { // Valid SQL - compiles successfully and returns the SQL string let select_query = check!("SELECT 1"); println!("Query: {}", select_query); // Output: Query: SELECT 1 // Valid SELECT with function let timestamp_query = check!("SELECT current_timestamp"); // Valid CREATE TABLE query let create_table = check!( "CREATE TABLE IF NOT EXISTS users (\n id SERIAL PRIMARY KEY,\n name TEXT NOT NULL,\n email TEXT UNIQUE NOT NULL,\n created_at TIMESTAMPTZ DEFAULT NOW()\n )" ); // Parameterized queries (PostgreSQL uses $1, $2 syntax) let insert_query = check!("INSERT INTO users (name, email) VALUES ($1, $2)"); let update_query = check!("UPDATE users SET name = $1 WHERE id = $2"); let delete_query = check!("DELETE FROM users WHERE id = $1"); // Invalid SQL - causes compile-time error: // error: SQL validation failed: relation "nonexistent_table" does not exist // let invalid = check!("SELECT * FROM nonexistent_table"); } ``` -------------------------------- ### Disable SQL Check Validation in Cargo.toml Source: https://github.com/tamaro-skaljic/sql-check/blob/main/README.md This snippet demonstrates how to disable the default compile-time validation feature for the `sql-check` crate in Cargo.toml. This is useful for production builds or when a database connection is unavailable. ```toml [dependencies] sql-check = { version = "0.9.0-alpha.1", default-features = false } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.