<commit_before>use rusqlite::{Connection, Result};
use tagged_rusqlite::tagged_sql;

fn main() -> Result<()> {
    let conn = Connection::open_in_memory()?;

    tagged_sql!(
        CreateTable,
        "CREATE TABLE person (
                  id              INTEGER PRIMARY KEY,
                  name            TEXT NOT NULL,
                  data            BLOB
                  )"
    );

    CreateTable::prepare(&conn).execute()?;

    tagged_sql!(
        InsertPerson,
        r#"INSERT INTO
                person (name, data)
                VALUES (
                    ?1 /*:name:String*/,
                    ?2 /*:data:Option<Vec<u8>>*/
                )
                "#
    );

    let mut insert = InsertPerson::prepare(&conn);
    insert.execute_bind(&InsertPersonParams {
        name: "Steven".to_string(),
        data: Some(vec![1u8, 2u8]),
    })?;
    insert.execute_bind(&InsertPersonParams {
        name: "John".to_string(),
        data: None,
    })?;
    insert.execute_bind(&InsertPersonParams {
        name: "Bill".to_string(),
        data: None,
    })?;

    tagged_sql!(
        SelectPerson,
        r#"SELECT
                            id   /*:i64*/,
                            name /*:String*/,
                            data /*:Option<Vec<u8>>*/
                            FROM person
                            "#
    );

    let mut stmt = SelectPerson::prepare(&conn);
    let person_iterator = stmt.query()?;

    for person in person_iterator {
        println!("Found person {:?}", &person.unwrap());
    }

    tagged_sql!(
        SearchByName,
        r#"SELECT
                            id   /*:i64*/,
                            name /*:String*/,
                            data /*:Option<Vec<u8>>*/
                            FROM person
                            WHERE name = ? /*:name:String*/
                            "#
    );
    let search_params = SearchByNameParams {
        name: "John".into(),
    };
    for person in SearchByName::prepare(&conn).query_bind(&search_params)? {
        println!(
            "Found person with name {}  {:?}",
            &search_params.name,
            &person.unwrap()
        );
    }

    let mut stmt = SelectPerson::prepare(&conn);
    println!("Found single person {:?} ", stmt.query_row()?);

    let mut stmt = SearchByName::prepare(&conn);
    let search_params = SearchByNameParams {
        name: "Bill".into(),
    };
    println!(<commit_msg>Minor fixes to sql queries for tagged rusqlite<commit_after>use rusqlite::{Connection, Result};
use tagged_rusqlite::tagged_sql;

fn main() -> Result<()> {
    let conn = Connection::open_in_memory()?;

    tagged_sql!(
        CreateTable,
        "CREATE TABLE person (
                  id              INTEGER PRIMARY KEY,
                  name            TEXT NOT NULL,
                  data            BLOB
                  );"
    );

    CreateTable::prepare(&conn).execute()?;

    tagged_sql!(
        InsertPerson,
        r#"INSERT INTO
                person (name, data)
                VALUES (
                    ?1 /*:name:String*/,
                    ?2 /*:data:Option<Vec<u8>>*/
                );
                "#
    );

    let mut insert = InsertPerson::prepare(&conn);
    insert.execute_bind(&InsertPersonParams {
        name: "Steven".to_string(),
        data: Some(vec![1u8, 2u8]),
    })?;
    insert.execute_bind(&InsertPersonParams {
        name: "John".to_string(),
        data: None,
    })?;
    insert.execute_bind(&InsertPersonParams {
        name: "Bill".to_string(),
        data: None,
    })?;

    tagged_sql!(
        SelectPerson,
        r#"SELECT
                            id   /*:i64*/,
                            name /*:String*/,
                            data /*:Option<Vec<u8>>*/
                            FROM person;
                            "#
    );

    let mut stmt = SelectPerson::prepare(&conn);
    let person_iterator = stmt.query()?;

    for person in person_iterator {
        println!("Found person {:?}", &person.unwrap());
    }

    tagged_sql!(
        SearchByName,
        r#"SELECT
                            id   /*:i64*/,
                            name /*:String*/,
                            data /*:Option<Vec<u8>>*/
                            FROM person
                            WHERE name = ? /*:name:String*/;
                            "#
    );
    let search_params = SearchByNameParams {
        name: "John".into(),
    };
    for person in SearchByName::prepare(&conn).query_bind(&search_params)? {
        println!(
            "Found person with name {}  {:?}",
            &search_params.name,
            &person.unwrap()
        );
    }

    let mut stmt = SelectPerson::prepare(&conn);
    println!("Found single person {:?} ", stmt.query_row()?);

    let mut stmt = SearchByName::prepare(&conn);
    let search_params = SearchByNameParams {
        name: "Bill".into(),
    };
    println!(
{'fraction_non_alphanumeric': 0.1326387497495492, 'fraction_numerical': 0.005209376878381086, 'mean_word_length': 1.3569405099150142, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '810384', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1360, 'n_words': 270}