Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: no such table: rooms #3

Open
ail3ngrimaldi opened this issue Apr 16, 2024 · 0 comments
Open

Error: no such table: rooms #3

ail3ngrimaldi opened this issue Apr 16, 2024 · 0 comments

Comments

@ail3ngrimaldi
Copy link
Collaborator

ail3ngrimaldi commented Apr 16, 2024

After fixing the bot logging, this error remains on file rooms.rs lines 143/176/197: https://github.com/ail3ngrimaldi/matrix-llm-bot/tree/to-sqlite

#[tracing::instrument(name = "Store room in the database", skip(room_id, db_client))]
pub async fn store_room(db_client: &SqlitePool, room_id: &str) -> Result<(), StoreRoomError> {
    sqlx::query!(                       <<<<<<<<<<<<<<<<<<<<<<<
        r#"
            INSERT INTO rooms (room_id) VALUES ($1)
        "#,
        room_id,
    )
    .execute(db_client)
    .await
    .map_err(|e|{
        tracing::error!("Failed to execute query: {:?}", e);
        StoreRoomError(e)
    })?;

    Ok(())
}
#[tracing::instrument(name = "Get last room from database", skip(db_client))]
pub async fn on_handle_next_room(db_client: &SqlitePool) -> Result<String, anyhow::Error> {
    let room = sqlx::query!(
        r#"
            SELECT * 
            FROM rooms
            WHERE available = true
            ORDER BY created_at DESC
            LIMIT 1
        "#
    )
    .fetch_one(db_client)
    .await
    .map(|row| row.room_id).map_err(|e|{
        tracing::error!("Failed to execute query: {:?}", e);
        e
    })?;

    Ok(room)
}
#[tracing::instrument(name = "Count rooms from database", skip(db_client))]
pub async fn count_rooms(db_client: &SqlitePool) -> Result<i32, anyhow::Error> {
    let result = sqlx::query!(
        r#"
            SELECT COUNT(*) AS count
            FROM rooms
            WHERE available = true
        "#
    )
    .fetch_one(db_client)
    .await
    .map(|row| row.count)
    .map_err(|e|{
        tracing::error!("Failed to execute query: {:?}", e);
        e
    })?;

    let count  = result;

    Ok(count)
}

Disclaimer: The bot password is not beign setted using the .env file, it can be tested with any matrix user, but for now you have to pass the password directly on the base.yml file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant