more refactoring and slightly better api

This commit is contained in:
Kay Simmons 2022-11-02 18:09:35 -07:00 committed by Mikayla Maki
parent aa7b909b7b
commit eb0598dac2
7 changed files with 588 additions and 627 deletions

View file

@ -1,3 +1,9 @@
use std::{
ffi::{CString, OsStr},
os::unix::prelude::OsStrExt,
path::{Path, PathBuf},
};
use anyhow::Result;
use crate::statement::{SqlType, Statement};
@ -241,3 +247,20 @@ impl<T: Bind> Bind for &[T] {
Ok(current_index)
}
}
impl Bind for &Path {
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
self.as_os_str().as_bytes().bind(statement, start_index)
}
}
impl Column for PathBuf {
fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> {
let blob = statement.column_blob(start_index)?;
Ok((
PathBuf::from(OsStr::from_bytes(blob).to_owned()),
start_index + 1,
))
}
}