CodingWithJamal
CodingWithJamal10mo ago

Convex Rust Client (None Async) help

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!");
}
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`
mismatched types
expected `UdfPath`, found `&str`
Why does the mutation take this type? Should it not be the key of the function?
3 Replies
lee
lee10mo ago
the rust client is open source, so you can see what UdfPath is, what it's for, and how to make one https://github.com/get-convex/convex-rs/blob/main/sync_types/src/udf_path.rs
GitHub
convex-rs/sync_types/src/udf_path.rs at main · get-convex/convex-rs
Rust client library for Convex. Contribute to get-convex/convex-rs development by creating an account on GitHub.
lee
lee10mo ago
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()
CodingWithJamal
CodingWithJamalOP10mo ago
oh i see thank you oh i did not see i needed to install the convex_sync_types crate 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 but i forgot that v.number is f64 so i had to rework a lot of my u32 types but thanks for the help

Did you find this page helpful?