Skip to content

Commit

Permalink
Merge pull request #310 from penberg/rows-v2
Browse files Browse the repository at this point in the history
libsql/core: Add Rows::column_{count,name}() to V2
  • Loading branch information
penberg authored Aug 24, 2023
2 parents d939395 + b3faf33 commit 9aab53f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/core/src/v2/hrana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,14 @@ impl RowsInner for Rows {
inner: Box::new(row),
}))
}

fn column_count(&self) -> i32 {
self.cols.len() as i32
}

fn column_name(&self, idx: i32) -> Option<&str> {
todo!();
}
}

pub struct Row {
Expand Down
20 changes: 20 additions & 0 deletions crates/core/src/v2/rows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ use crate::{Result, Value};

pub(super) trait RowsInner {
fn next(&mut self) -> Result<Option<Row>>;

fn column_count(&self) -> i32;

fn column_name(&self, idx: i32) -> Option<&str>;
}

pub struct Rows {
Expand All @@ -12,6 +16,14 @@ impl Rows {
pub fn next(&mut self) -> Result<Option<Row>> {
self.inner.next()
}

pub fn column_count(&self) -> i32 {
self.inner.column_count()
}

pub fn column_name(&self, idx: i32) -> Option<&str> {
self.inner.column_name(idx)
}
}

pub(super) struct LibsqlRows(pub(super) crate::Rows);
Expand All @@ -24,6 +36,14 @@ impl RowsInner for LibsqlRows {

Ok(row)
}

fn column_count(&self) -> i32 {
self.0.column_count()
}

fn column_name(&self, idx: i32) -> Option<&str> {
self.0.column_name(idx)
}
}

pub struct Row {
Expand Down

0 comments on commit 9aab53f

Please sign in to comment.