mirror of
https://github.com/flibusta-apps/library_updater.git
synced 2025-12-06 07:45:35 +01:00
Compare commits
4 Commits
e1af1c2623
...
7d99897b0e
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d99897b0e | |||
| 35dc3cbf6f | |||
| 4625adb6a4 | |||
| 65e23787f1 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
.vscode
|
/.vscode
|
||||||
|
/bruno
|
||||||
|
|||||||
40
src/types.rs
40
src/types.rs
@@ -828,30 +828,28 @@ impl FromVecExpression<Genre> for Genre {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Update for Genre {
|
impl Update for Genre {
|
||||||
async fn before_update(client: &Client) -> Result<(), Box<tokio_postgres::Error>> {
|
async fn before_update(client: &Client) -> Result<(), Box<tokio_postgres::Error>> {
|
||||||
match client.execute(
|
match client
|
||||||
"
|
.execute(
|
||||||
CREATE OR REPLACE FUNCTION update_book_sequence(source_ smallint, book_ integer, genre_ integer) RETURNS void AS $$
|
"
|
||||||
DECLARE
|
CREATE OR REPLACE FUNCTION update_genre(
|
||||||
book_id integer := -1;
|
source_ smallint, remote_id_ int, code_ varchar, description_ varchar, meta_ varchar
|
||||||
genre_id integer := -1;
|
) RETURNS void AS $$
|
||||||
BEGIN
|
BEGIN
|
||||||
SELECT id INTO book_id FROM books WHERE source = source_ AND remote_id = book_;
|
INSERT INTO genres (source, remote_id, code, description, meta)
|
||||||
|
VALUES (source_, remote_id_, code_, description_, meta_)
|
||||||
IF book_id IS NULL THEN
|
ON CONFLICT (source, remote_id) DO UPDATE SET
|
||||||
RETURN;
|
code = EXCLUDED.code,
|
||||||
END IF;
|
description = EXCLUDED.description,
|
||||||
|
meta = EXCLUDED.meta;
|
||||||
SELECT id INTO genre_id FROM genres WHERE source = source_ AND remote_id = genre_;
|
|
||||||
IF EXISTS (SELECT * FROM book_genres WHERE book = book_id AND genre = genre_id) THEN
|
|
||||||
RETURN;
|
|
||||||
END IF;
|
|
||||||
INSERT INTO book_genres (book, genre) VALUES (book_id, genre_id);
|
|
||||||
END;
|
END;
|
||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql;
|
||||||
"
|
",
|
||||||
, &[]).await {
|
&[],
|
||||||
Ok(_) => Ok(()),
|
)
|
||||||
Err(err) => Err(Box::new(err)),
|
.await
|
||||||
|
{
|
||||||
|
Ok(_) => Ok(()),
|
||||||
|
Err(err) => Err(Box::new(err)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user