tursodatabase / libsql

libSQL is a fork of SQLite that is both Open Source, and Open Contributions.

Home Page:https://turso.tech/libsql

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stack overflow exception then trying to get sqlite schema on an empty turso database on Windows (only)

milen-denev opened this issue · comments

Stack overflow exception then trying to get sqlite schema on an empty turso database on Windows (only). Works on linux (Fedora v40), unknown for MacOs.

use libsql::{Builder, Connection};


#[tokio::main]
async fn main() {
    let builder = Builder::new_remote("libsql://<subdomain>.turso.io".into(), "<token>".into()).build().await.unwrap();
    let connection = builder.connect().unwrap();
    get_current_db_schema("Test", &connection).await;
}

pub async fn get_current_db_schema(name: &str, connection: &Connection) -> Option<Vec<String>> {  
    let query = format!("SELECT sql FROM sqlite_schema WHERE name = {}", name);

    let result_query = connection
         .query(&query, ())
         .await;

    if let Ok(mut result_row) = result_query {
         let result_rows = result_row
              .next()
              .await;

         if let Ok(_result_row) = result_rows {
              return None;
         }
         else {
              return None;
         }

    }
    else {
         return None;
    }
}

Repository with the same code: https://github.com/milen-denev/libsql_stackoverflow/