mirror of
https://github.com/flibusta-apps/library_updater.git
synced 2025-12-06 15:45:36 +01:00
Add year to book table
This commit is contained in:
19
src/types.rs
19
src/types.rs
@@ -106,6 +106,7 @@ pub struct Book {
|
|||||||
pub uploaded: NaiveDate,
|
pub uploaded: NaiveDate,
|
||||||
pub is_deleted: bool,
|
pub is_deleted: bool,
|
||||||
pub pages: u64,
|
pub pages: u64,
|
||||||
|
pub year: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromVecExpression<Book> for Book {
|
impl FromVecExpression<Book> for Book {
|
||||||
@@ -143,6 +144,10 @@ impl FromVecExpression<Book> for Book {
|
|||||||
sql_parse::Expression::Integer(v) => v.0,
|
sql_parse::Expression::Integer(v) => v.0,
|
||||||
_ => panic!("Book.id"),
|
_ => panic!("Book.id"),
|
||||||
},
|
},
|
||||||
|
year: match &value[10] {
|
||||||
|
sql_parse::Expression::Integer(v) => v.0,
|
||||||
|
_ => panic!("Book.year"),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,17 +159,19 @@ impl Update for Book {
|
|||||||
"
|
"
|
||||||
CREATE OR REPLACE FUNCTION update_book(
|
CREATE OR REPLACE FUNCTION update_book(
|
||||||
source_ smallint, remote_id_ int, title_ varchar, lang_ varchar,
|
source_ smallint, remote_id_ int, title_ varchar, lang_ varchar,
|
||||||
file_type_ varchar, uploaded_ date, is_deleted_ boolean, pages_ int
|
file_type_ varchar, uploaded_ date, is_deleted_ boolean, pages_ int,
|
||||||
|
year_ smallint
|
||||||
) RETURNS void AS $$
|
) RETURNS void AS $$
|
||||||
BEGIN
|
BEGIN
|
||||||
IF EXISTS (SELECT * FROM books WHERE source = source_ AND remote_id = remote_id_) THEN
|
IF EXISTS (SELECT * FROM books WHERE source = source_ AND remote_id = remote_id_) THEN
|
||||||
UPDATE books SET title = title_, lang = lang_, file_type = file_type_,
|
UPDATE books SET title = title_, lang = lang_, file_type = file_type_,
|
||||||
uploaded = uploaded_, is_deleted = is_deleted_, pages = pages_
|
uploaded = uploaded_, is_deleted = is_deleted_, pages = pages_,
|
||||||
|
year = year_
|
||||||
WHERE source = source_ AND remote_id = remote_id_;
|
WHERE source = source_ AND remote_id = remote_id_;
|
||||||
RETURN;
|
RETURN;
|
||||||
END IF;
|
END IF;
|
||||||
INSERT INTO books (source, remote_id, title, lang, file_type, uploaded, is_deleted, pages)
|
INSERT INTO books (source, remote_id, title, lang, file_type, uploaded, is_deleted, pages, year)
|
||||||
VALUES (source_, remote_id_, title_, lang_, file_type_, uploaded_, is_deleted_, pages_);
|
VALUES (source_, remote_id_, title_, lang_, file_type_, uploaded_, is_deleted_, pages_, year_);
|
||||||
END;
|
END;
|
||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql;
|
||||||
"
|
"
|
||||||
@@ -180,8 +187,8 @@ impl Update for Book {
|
|||||||
source_id: i16,
|
source_id: i16,
|
||||||
) -> Result<(), Box<tokio_postgres::Error>> {
|
) -> Result<(), Box<tokio_postgres::Error>> {
|
||||||
match client.execute(
|
match client.execute(
|
||||||
"SELECT update_book($1, $2, cast($3 as varchar), cast($4 as varchar), cast($5 as varchar), $6, $7, $8);",
|
"SELECT update_book($1, $2, cast($3 as varchar), cast($4 as varchar), cast($5 as varchar), $6, $7, $8, $9);",
|
||||||
&[&source_id, &(self.id as i32), &self.title, &self.lang, &self.file_type, &self.uploaded, &self.is_deleted, &(self.pages as i32)]
|
&[&source_id, &(self.id as i32), &self.title, &self.lang, &self.file_type, &self.uploaded, &self.is_deleted, &(self.pages as i32), &(self.year as i32)]
|
||||||
).await {
|
).await {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(err) => Err(Box::new(err)),
|
Err(err) => Err(Box::new(err)),
|
||||||
|
|||||||
Reference in New Issue
Block a user