mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-06 01:34:21 +01:00
Merge pull request #98 from haaawk/remove_copies
This commit is contained in:
@@ -65,12 +65,12 @@ impl Database {
|
||||
loop {
|
||||
match rows.next()? {
|
||||
RowResult::Row(row) => {
|
||||
let ty = row.get::<String>(0)?;
|
||||
let ty = row.get::<&str>(0)?;
|
||||
if ty != "table" {
|
||||
continue;
|
||||
}
|
||||
let root_page: i64 = row.get::<i64>(3)?;
|
||||
let sql: String = row.get::<String>(4)?;
|
||||
let sql: &str = row.get::<&str>(4)?;
|
||||
let table = schema::BTreeTable::from_sql(&sql, root_page as usize)?;
|
||||
schema.add_table(Rc::new(table));
|
||||
}
|
||||
@@ -242,7 +242,7 @@ pub struct Row<'a> {
|
||||
}
|
||||
|
||||
impl<'a> Row<'a> {
|
||||
pub fn get<T: crate::types::FromValue>(&self, idx: usize) -> Result<T> {
|
||||
pub fn get<T: crate::types::FromValue<'a> + 'a>(&self, idx: usize) -> Result<T> {
|
||||
let value = &self.values[idx];
|
||||
T::from_value(value)
|
||||
}
|
||||
|
||||
@@ -165,14 +165,14 @@ pub fn to_value(value: &OwnedValue) -> Value<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait FromValue {
|
||||
fn from_value(value: &Value) -> Result<Self>
|
||||
pub trait FromValue<'a> {
|
||||
fn from_value(value: &Value<'a>) -> Result<Self>
|
||||
where
|
||||
Self: Sized;
|
||||
Self: Sized + 'a;
|
||||
}
|
||||
|
||||
impl FromValue for i64 {
|
||||
fn from_value(value: &Value) -> Result<Self> {
|
||||
impl<'a> FromValue<'a> for i64 {
|
||||
fn from_value(value: &Value<'a>) -> Result<Self> {
|
||||
match value {
|
||||
Value::Integer(i) => Ok(*i),
|
||||
_ => anyhow::bail!("Expected integer value"),
|
||||
@@ -180,8 +180,8 @@ impl FromValue for i64 {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromValue for String {
|
||||
fn from_value(value: &Value) -> Result<Self> {
|
||||
impl<'a> FromValue<'a> for String {
|
||||
fn from_value(value: &Value<'a>) -> Result<Self> {
|
||||
match value {
|
||||
Value::Text(s) => Ok(s.to_string()),
|
||||
_ => anyhow::bail!("Expected text value"),
|
||||
@@ -189,6 +189,15 @@ impl FromValue for String {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> FromValue<'a> for &'a str {
|
||||
fn from_value(value: &Value<'a>) -> Result<&'a str> {
|
||||
match value {
|
||||
Value::Text(s) => Ok(&s),
|
||||
_ => anyhow::bail!("Expected text value"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Record<'a> {
|
||||
pub values: Vec<Value<'a>>,
|
||||
|
||||
Reference in New Issue
Block a user