Hi everybody
I am currently processing a lot of files. So I want to store the progress in PostgreSQL.
It works so far except one thing:
fn get_file_or_create(connection: &PgConnection, path: &String) -> models::File {
use schema::files::dsl::*;
let candidates = files
.filter(path.eq(path))
.load::<models::File>(connection)
.expect("unable to load files");
for file in candidates {
return file;
}
// create
diesel::insert_into(files)
.values((path.eq(path), status.eq(models::SOURCE_STATUS_PROCESSING)))
.get_result(connection)
.expect("unable to create new file")
}
This gives me this error:
error[E0271]: type mismatch resolving `<() as diesel::query_source::AppearsInFromClause<schema::files::table>>::Count == diesel::query_source::Once`
--> src/main.rs:95:10
|
95 | .get_result(connection)
| ^^^^^^^^^^ expected struct `diesel::query_source::Never`, found struct `diesel::query_source::Once`
|
= note: expected type `diesel::query_source::Never`
found type `diesel::query_source::Once`
Did I miss something? Or is there a function that already provides that?
I am using rust 1.33.0 with edition 2018 on Arch Linux.
In other parts of the code I can insert and select other data.
Some more relevant source code:
/// models.rs
#[derive(Queryable, Identifiable, PartialEq)]
pub struct File {
pub id: i32,
pub path: String,
pub status: String,
}
pub const SOURCE_STATUS_PROCESSING: &'static str = "Processing";
pub const SOURCE_STATUS_Complete: &'static str = "Complete";
/// schema.rs
table! {
files (id) {
id -> Int4,
path -> Text,
status -> Text,
}
}
Cheers,
Stefan