#Convex Rust Client (None Async) help

6 messages · Page 1 of 1 (latest)

wispy ingot
#

Hello, im writing a a web scrapper and i want to save some data to convex. I cant use async rust. So how can i use the convex base client to send some mutation data over to my convex server.

const MUTATION_QUERY_KEY: &str = "anime:createAnimeData";

fn save_to_database() {
    println!("Loading data from disk...");

    let mut data: Vec<AnimeData> = Vec::new();
    let files = std::fs::read_dir("anime").unwrap();

    for file in files {
        let path = file.unwrap().path();
        if path.is_file() {
            let contents = std::fs::read_to_string(path).unwrap();
            let json_data: AnimeData = serde_json::from_str(&contents).unwrap();
            data.push(json_data);
        }
    }

    println!("Sending data to convex server...");

    let client = BaseConvexClient::new();

    for anime in data {
        client.mutation(MUTATION_QUERY_KEY, maplit::btreemap! {});
    }

    println!("Done!");
}

Here is the code. However i have a few errors:

mismatched types
expected `UdfPath`, found `&str`

Why does the mutation take this type? Should it not be the key of the function?

undone nacelle
#

tl;dr it's a struct that has some methods for converting "foo" into "foo:default", checking if the path starts with _system, and a few more things.
and you can make one with MUTATION_QUERY_KEY.parse().unwrap()

wispy ingot
#

oh i see thank you

wispy ingot
#

oh i did not see i needed to install the convex_sync_types crate

wispy ingot
#

okay i got it working, took a little to play around with the convex types. also just to make things easier i moved to the async client lol