mirror of
https://github.com/flibusta-apps/library_updater.git
synced 2025-12-06 07:45:35 +01:00
Refactor
This commit is contained in:
26
src/types.rs
26
src/types.rs
@@ -6,7 +6,7 @@ use tokio_postgres::Client;
|
|||||||
use crate::utils::{fix_annotation_text, parse_lang, remove_wrong_chars};
|
use crate::utils::{fix_annotation_text, parse_lang, remove_wrong_chars};
|
||||||
|
|
||||||
pub trait FromVecExpression<T> {
|
pub trait FromVecExpression<T> {
|
||||||
fn from_vec_expression(value: &Vec<Expression>) -> T;
|
fn from_vec_expression(value: &[Expression]) -> T;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -31,7 +31,7 @@ pub struct Author {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FromVecExpression<Author> for Author {
|
impl FromVecExpression<Author> for Author {
|
||||||
fn from_vec_expression(value: &Vec<Expression>) -> Author {
|
fn from_vec_expression(value: &[Expression]) -> Author {
|
||||||
Author {
|
Author {
|
||||||
id: match &value[0] {
|
id: match &value[0] {
|
||||||
sql_parse::Expression::Integer(v) => v.0,
|
sql_parse::Expression::Integer(v) => v.0,
|
||||||
@@ -107,7 +107,7 @@ pub struct Book {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FromVecExpression<Book> for Book {
|
impl FromVecExpression<Book> for Book {
|
||||||
fn from_vec_expression(value: &Vec<Expression>) -> Book {
|
fn from_vec_expression(value: &[Expression]) -> Book {
|
||||||
Book {
|
Book {
|
||||||
id: match &value[0] {
|
id: match &value[0] {
|
||||||
sql_parse::Expression::Integer(v) => v.0,
|
sql_parse::Expression::Integer(v) => v.0,
|
||||||
@@ -197,7 +197,7 @@ pub struct BookAuthor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FromVecExpression<BookAuthor> for BookAuthor {
|
impl FromVecExpression<BookAuthor> for BookAuthor {
|
||||||
fn from_vec_expression(value: &Vec<Expression>) -> BookAuthor {
|
fn from_vec_expression(value: &[Expression]) -> BookAuthor {
|
||||||
BookAuthor {
|
BookAuthor {
|
||||||
book_id: match &value[0] {
|
book_id: match &value[0] {
|
||||||
sql_parse::Expression::Integer(v) => v.0,
|
sql_parse::Expression::Integer(v) => v.0,
|
||||||
@@ -270,7 +270,7 @@ pub struct Translator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FromVecExpression<Translator> for Translator {
|
impl FromVecExpression<Translator> for Translator {
|
||||||
fn from_vec_expression(value: &Vec<Expression>) -> Translator {
|
fn from_vec_expression(value: &[Expression]) -> Translator {
|
||||||
Translator {
|
Translator {
|
||||||
book_id: match &value[0] {
|
book_id: match &value[0] {
|
||||||
sql_parse::Expression::Integer(v) => v.0,
|
sql_parse::Expression::Integer(v) => v.0,
|
||||||
@@ -347,7 +347,7 @@ pub struct Sequence {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FromVecExpression<Sequence> for Sequence {
|
impl FromVecExpression<Sequence> for Sequence {
|
||||||
fn from_vec_expression(value: &Vec<Expression>) -> Sequence {
|
fn from_vec_expression(value: &[Expression]) -> Sequence {
|
||||||
Sequence {
|
Sequence {
|
||||||
id: match &value[0] {
|
id: match &value[0] {
|
||||||
sql_parse::Expression::Integer(v) => v.0,
|
sql_parse::Expression::Integer(v) => v.0,
|
||||||
@@ -410,7 +410,7 @@ pub struct SequenceInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FromVecExpression<SequenceInfo> for SequenceInfo {
|
impl FromVecExpression<SequenceInfo> for SequenceInfo {
|
||||||
fn from_vec_expression(value: &Vec<Expression>) -> SequenceInfo {
|
fn from_vec_expression(value: &[Expression]) -> SequenceInfo {
|
||||||
SequenceInfo {
|
SequenceInfo {
|
||||||
book_id: match &value[0] {
|
book_id: match &value[0] {
|
||||||
sql_parse::Expression::Integer(v) => v.0,
|
sql_parse::Expression::Integer(v) => v.0,
|
||||||
@@ -497,7 +497,7 @@ pub struct BookAnnotation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FromVecExpression<BookAnnotation> for BookAnnotation {
|
impl FromVecExpression<BookAnnotation> for BookAnnotation {
|
||||||
fn from_vec_expression(value: &Vec<Expression>) -> BookAnnotation {
|
fn from_vec_expression(value: &[Expression]) -> BookAnnotation {
|
||||||
BookAnnotation {
|
BookAnnotation {
|
||||||
book_id: match &value[0] {
|
book_id: match &value[0] {
|
||||||
sql_parse::Expression::Integer(v) => v.0,
|
sql_parse::Expression::Integer(v) => v.0,
|
||||||
@@ -572,7 +572,7 @@ pub struct BookAnnotationPic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FromVecExpression<BookAnnotationPic> for BookAnnotationPic {
|
impl FromVecExpression<BookAnnotationPic> for BookAnnotationPic {
|
||||||
fn from_vec_expression(value: &Vec<Expression>) -> BookAnnotationPic {
|
fn from_vec_expression(value: &[Expression]) -> BookAnnotationPic {
|
||||||
BookAnnotationPic {
|
BookAnnotationPic {
|
||||||
book_id: match &value[0] {
|
book_id: match &value[0] {
|
||||||
sql_parse::Expression::Integer(v) => v.0,
|
sql_parse::Expression::Integer(v) => v.0,
|
||||||
@@ -625,7 +625,7 @@ pub struct AuthorAnnotation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FromVecExpression<AuthorAnnotation> for AuthorAnnotation {
|
impl FromVecExpression<AuthorAnnotation> for AuthorAnnotation {
|
||||||
fn from_vec_expression(value: &Vec<Expression>) -> AuthorAnnotation {
|
fn from_vec_expression(value: &[Expression]) -> AuthorAnnotation {
|
||||||
AuthorAnnotation {
|
AuthorAnnotation {
|
||||||
author_id: match &value[0] {
|
author_id: match &value[0] {
|
||||||
sql_parse::Expression::Integer(v) => v.0,
|
sql_parse::Expression::Integer(v) => v.0,
|
||||||
@@ -700,7 +700,7 @@ pub struct AuthorAnnotationPic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FromVecExpression<AuthorAnnotationPic> for AuthorAnnotationPic {
|
impl FromVecExpression<AuthorAnnotationPic> for AuthorAnnotationPic {
|
||||||
fn from_vec_expression(value: &Vec<Expression>) -> AuthorAnnotationPic {
|
fn from_vec_expression(value: &[Expression]) -> AuthorAnnotationPic {
|
||||||
AuthorAnnotationPic {
|
AuthorAnnotationPic {
|
||||||
author_id: match &value[0] {
|
author_id: match &value[0] {
|
||||||
sql_parse::Expression::Integer(v) => v.0,
|
sql_parse::Expression::Integer(v) => v.0,
|
||||||
@@ -753,7 +753,7 @@ pub struct Genre {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FromVecExpression<Genre> for Genre {
|
impl FromVecExpression<Genre> for Genre {
|
||||||
fn from_vec_expression(value: &Vec<Expression>) -> Genre {
|
fn from_vec_expression(value: &[Expression]) -> Genre {
|
||||||
Genre {
|
Genre {
|
||||||
id: match &value[0] {
|
id: match &value[0] {
|
||||||
sql_parse::Expression::Integer(v) => v.0,
|
sql_parse::Expression::Integer(v) => v.0,
|
||||||
@@ -826,7 +826,7 @@ pub struct BookGenre {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FromVecExpression<BookGenre> for BookGenre {
|
impl FromVecExpression<BookGenre> for BookGenre {
|
||||||
fn from_vec_expression(value: &Vec<Expression>) -> BookGenre {
|
fn from_vec_expression(value: &[Expression]) -> BookGenre {
|
||||||
BookGenre {
|
BookGenre {
|
||||||
book_id: match &value[1] {
|
book_id: match &value[1] {
|
||||||
sql_parse::Expression::Integer(v) => v.0,
|
sql_parse::Expression::Integer(v) => v.0,
|
||||||
|
|||||||
@@ -140,32 +140,28 @@ where
|
|||||||
let mut issues = Vec::new();
|
let mut issues = Vec::new();
|
||||||
let ast = parse_statement(&line, &mut issues, &parse_options);
|
let ast = parse_statement(&line, &mut issues, &parse_options);
|
||||||
|
|
||||||
match ast {
|
if let Some(Statement::InsertReplace(
|
||||||
Some(Statement::InsertReplace(
|
i @ InsertReplace {
|
||||||
i @ InsertReplace {
|
type_: InsertReplaceType::Insert(_),
|
||||||
type_: InsertReplaceType::Insert(_),
|
..
|
||||||
..
|
},
|
||||||
},
|
)) = ast {
|
||||||
)) => {
|
for value in i.values.into_iter() {
|
||||||
for value in i.values.into_iter() {
|
for t_value in value.1.into_iter() {
|
||||||
for t_value in value.1.into_iter() {
|
let value = T::from_vec_expression(&t_value);
|
||||||
let value = T::from_vec_expression(&t_value);
|
let client = pool.get().await.unwrap();
|
||||||
let client = pool.get().await.unwrap();
|
|
||||||
|
|
||||||
match value.update(&client, source_id).await {
|
match value.update(&client, source_id).await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// log::info!("{:?}", value);
|
// log::info!("{:?}", value);
|
||||||
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
log::error!("Update error: {:?} : {:?}", value, err);
|
|
||||||
return Err(err)
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
Err(err) => {
|
||||||
|
log::error!("Update error: {:?} : {:?}", value, err);
|
||||||
|
return Err(err)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user