generated from alecodes/base-template
feat: improve error handling and messages
This commit is contained in:
parent
e65afb8553
commit
5d1b4bdfd8
3 changed files with 26 additions and 6 deletions
|
|
@ -5,6 +5,7 @@ use sqlx::Row as _;
|
|||
use sqlx::TypeInfo;
|
||||
|
||||
use crate::error;
|
||||
use crate::error::Error;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Column<T> {
|
||||
|
|
@ -28,7 +29,10 @@ pub enum ColumnType {
|
|||
|
||||
impl ColumnType {
|
||||
pub fn new(row: &PgRow, idx: usize) -> error::Result<Self> {
|
||||
let column = row.columns().get(idx).unwrap();
|
||||
let column = row
|
||||
.columns()
|
||||
.get(idx)
|
||||
.ok_or_else(|| Error::ColumnParse(String::from("Could not get column")))?;
|
||||
let sql_type = column.type_info().name();
|
||||
let name = String::from(column.name());
|
||||
|
||||
|
|
@ -106,7 +110,7 @@ impl ColumnType {
|
|||
name,
|
||||
}))
|
||||
}
|
||||
&_ => panic!("{} Type not found!", sql_type),
|
||||
&_ => Err(Error::ColumnParse(format!("{} type not found!", sql_type))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue