njord-rs / njord

A versatile, feature-rich Rust ORM ⛵
https://njord.rs
BSD 3-Clause "New" or "Revised" License
409 stars 21 forks source link

Add raw_execute outside of select #210

Closed chaseWillden closed 1 day ago

chaseWillden commented 2 days ago

The previous implementations only allow for selecting. This implementation allows for all other SQL query types:

#[test]
fn execute_raw_sql() {
    let db_relative_path = "./db/insert.db";
    let db_path = Path::new(&db_relative_path);
    let conn = sqlite::open(db_path).unwrap();

    let sql = sql! {
        INSERT INTO users (username, email, address)
        VALUES
            ("raw_execute", "raw_execute@icloud.com", "raw_execute_address");

        DELETE FROM users
        WHERE username = "raw_execute";
    };

    let results = sqlite::raw_execute(&conn, &sql);

    assert!(!results.is_err());
}