refactor: tweak type name display to use TypeInfo::name

This commit is contained in:
Ryan Leckey 2020-06-18 18:58:59 -07:00
parent aaa475cc33
commit 6cfe5ac811
5 changed files with 39 additions and 46 deletions

View file

@ -937,7 +937,7 @@ impl PgTypeInfo {
impl Display for PgTypeInfo {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.pad(self.0.name())
f.pad(self.name())
}
}

View file

@ -100,46 +100,41 @@ impl<'c> Executor<'c> for &'c mut SqliteConnection {
// bind arguments, if any, to the statement
bind(&mut stmt, arguments)?;
{
// let SqliteStatement { ref handles, ref mut last_row_values, .. } = *stmt;
// let mut handle_i = 0;
while let Some((handle, last_row_values)) = stmt.execute()? {
// tell the worker about the new statement
worker.execute(handle);
while let Some((handle, last_row_values)) = stmt.execute()? {
// tell the worker about the new statement
worker.execute(handle);
// wake up the worker if needed
// the worker parks its thread on async-std when not in use
worker.wake();
// wake up the worker if needed
// the worker parks its thread on async-std when not in use
worker.wake();
emplace_row_metadata(
handle,
Arc::make_mut(scratch_row_column_names),
)?;
emplace_row_metadata(
handle,
Arc::make_mut(scratch_row_column_names),
)?;
loop {
// save the rows from the _current_ position on the statement
// and send them to the still-live row object
SqliteRow::inflate_if_needed(handle, last_row_values.take());
loop {
// save the rows from the _current_ position on the statement
// and send them to the still-live row object
SqliteRow::inflate_if_needed(handle, last_row_values.take());
match worker.step(handle).await? {
Either::Left(changes) => {
r#yield!(Either::Left(changes));
match worker.step(handle).await? {
Either::Left(changes) => {
r#yield!(Either::Left(changes));
break;
}
break;
}
Either::Right(()) => {
let (row, weak_values_ref) = SqliteRow::current(
*handle,
scratch_row_column_names
);
Either::Right(()) => {
let (row, weak_values_ref) = SqliteRow::current(
*handle,
scratch_row_column_names
);
let v = Either::Right(row);
*last_row_values = Some(weak_values_ref);
let v = Either::Right(row);
*last_row_values = Some(weak_values_ref);
r#yield!(v);
}
r#yield!(v);
}
}
}

View file

@ -84,9 +84,7 @@ impl<'r> ValueRef<'r> for SqliteValueRef<'r> {
fn type_info(&self) -> Option<Cow<'_, SqliteTypeInfo>> {
match self.0 {
SqliteValueData::Statement { statement, index } => {
DataType::from_code(statement.column_type(index))
.map(SqliteTypeInfo)
.map(Cow::Owned)
statement.column_decltype(index).map(Cow::Owned)
}
SqliteValueData::Value(v) => v.type_info(),

View file

@ -28,10 +28,10 @@ async fn it_describes_simple() -> anyhow::Result<()> {
let column_type_names = type_names(&columns);
assert_eq!(column_type_names[0], "bigint");
assert_eq!(column_type_names[1], "nvarchar(max)");
assert_eq!(column_type_names[2], "tinyint");
assert_eq!(column_type_names[3], "bigint");
assert_eq!(column_type_names[0], "BIGINT");
assert_eq!(column_type_names[1], "NVARCHAR");
assert_eq!(column_type_names[2], "TINYINT");
assert_eq!(column_type_names[3], "BIGINT");
Ok(())
}

View file

@ -28,10 +28,10 @@ async fn it_describes_simple() -> anyhow::Result<()> {
let column_type_names = type_names(&columns);
assert_eq!(column_type_names[0], "int8");
assert_eq!(column_type_names[1], "timestamptz");
assert_eq!(column_type_names[2], "text");
assert_eq!(column_type_names[3], "int8");
assert_eq!(column_type_names[0], "INT8");
assert_eq!(column_type_names[1], "TIMESTAMPTZ");
assert_eq!(column_type_names[2], "TEXT");
assert_eq!(column_type_names[3], "INT8");
Ok(())
}
@ -52,7 +52,7 @@ async fn it_describes_expression() -> anyhow::Result<()> {
let column_type_names = type_names(&columns);
assert_eq!(column_type_names[0], "int8");
assert_eq!(column_type_names[0], "INT8");
Ok(())
}
@ -86,7 +86,7 @@ async fn it_describes_record() -> anyhow::Result<()> {
let columns = d.columns;
let ty = columns[0].type_info.as_ref().unwrap();
assert_eq!(ty.to_string(), "record");
assert_eq!(ty.to_string(), "RECORD");
Ok(())
}