146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
.execute(&mut *self.0).await.stack()?.rows_affected() {
1 => { Ok("Source enabled.") },
0 => { Ok("Source not found.") },
_ => { bail!("Database error.") },
}
}
pub async fn exists <I> (&mut self, post_url: &str, id: I) -> Result<bool>
where I: Into<i64> {
let row = sqlx::query("select exists(select true from rsstg_post where url = $1 and source_id = $2) as exists;")
.bind(post_url)
.bind(id.into())
.fetch_one(&mut *self.0).await.stack()?;
if let Some(exists) = row.try_get("exists").stack()? {
Ok(exists)
} else {
bail!("Database error: can't check whether post exists.");
}
}
/// Get all pending events for (now + 1 minute)
pub async fn get_queue (&mut self) -> Result<Vec<Queue>> {
let block: Vec<Queue> = sqlx::query_as("select source_id, next_fetch, owner, last_scrape from rsstg_order natural left join rsstg_source where next_fetch < now() + interval '1 minute';")
.fetch_all(&mut *self.0).await.stack()?;
Ok(block)
|
>
>
>
>
>
>
>
>
|
<
<
|
<
|
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
.execute(&mut *self.0).await.stack()?.rows_affected() {
1 => { Ok("Source enabled.") },
0 => { Ok("Source not found.") },
_ => { bail!("Database error.") },
}
}
/// Checks whether a post with the given URL exists for the specified source.
///
/// # Parameters
/// - `post_url`: The URL of the post to check.
/// - `id`: The source identifier (converted to `i64`).
///
/// # Returns
/// `true` if a post with the URL exists for the source, `false` otherwise.
pub async fn exists <I> (&mut self, post_url: &str, id: I) -> Result<bool>
where I: Into<i64> {
let row = sqlx::query("select exists(select true from rsstg_post where url = $1 and source_id = $2) as exists;")
.bind(post_url)
.bind(id.into())
.fetch_one(&mut *self.0).await.stack()?;
row.try_get("exists")
.stack_err("Database error: can't check whether post exists.")
}
/// Get all pending events for (now + 1 minute)
pub async fn get_queue (&mut self) -> Result<Vec<Queue>> {
let block: Vec<Queue> = sqlx::query_as("select source_id, next_fetch, owner, last_scrape from rsstg_order natural left join rsstg_source where next_fetch < now() + interval '1 minute';")
.fetch_all(&mut *self.0).await.stack()?;
Ok(block)
|