tgqe 0.0.2

The Great Qin Empire —— A centralized system for integrating and summarizing common compiler front-end library errors and span error output libraries, with optional Ariadne integration.
/**

 *  - Copyright (c) 星灿长风v(Starwindv) 2026/08/03
 *  - License: BSD-3
 *  - Author: 星灿长风v(StarWindv)
 *  - Location: tgqe/src/modules/tests/sqlite.rs
 */
use crate::base_types::{
    TgqeCoordinate, TgqeCtx, TgqeErrorInfo,
    TgqePosition, TgqeSpan,
};
use crate::channel::sqlite::SQLite;
use crate::enums::TgqeLevelFilter;

fn sample_ctx() -> TgqeCtx {
    let coord = TgqeCoordinate::new(
        "test.rs", 1, 0, 0,
    );
    let span = TgqeSpan::new(
        coord.clone(),
        coord.clone(),
    );
    TgqeCtx::new(
        TgqePosition::new(coord, span),
        TgqeErrorInfo::new(
            "winnow::error::ParseError",
            "expected digit",
            "found x",
            TgqeLevelFilter::Error,
        ),
        "hints",
        "labels",
        "winnow",
        0,
    )
}

#[tokio::test]
async fn save_and_batch_save_roundtrip() {
    let db_path =
        std::env::temp_dir().join(format!(
            "tgqe_test_{}.db",
            std::time::SystemTime::now()
                .duration_since(
                    std::time::UNIX_EPOCH,
                )
                .unwrap()
                .as_nanos()
        ));

    let mut db = SQLite {
        pool: None,
        db_path: db_path.clone(),
    };

    db.save(&sample_ctx()).await.unwrap();
    db.batch_save(&[
        sample_ctx(),
        sample_ctx(),
    ])
    .await
    .unwrap();

    let pool = db.pool.as_ref().unwrap();
    let count: i64 = sqlx::query_scalar(
        "SELECT COUNT(*) FROM tgqe_errors",
    )
    .fetch_one(pool)
    .await
    .unwrap();
    assert_eq!(count, 3);

    let _ = std::fs::remove_file(&db_path);
}