Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What you write sounds extremely sensible to me! Thoughts:

2. Loading the rows might be lazy, using a cursor etc, so you could encounter IO errors while traversing the rowset. You really, really want lazy rowsets for iterating enormous results without having to materialise the whole lot in memory.

5. Maybe as well as element-by-element access, there should be some sort of bulk access to get a buffer full of elements in one go.

A. I'd like to see some way to use a ColumnAccessor, or some other thing, to access elements in a row. I would like to write code like:

    use std::io::Result as IoResult;
    
    struct Column<T> {
        column_type: std::marker::PhantomData<T>,
    }
    
    struct Row {}
    
    impl Row {
        fn get<T>(&self, column: &Column<T>) -> T { unimplemented!(); }
    }
    
    struct RowSet {}
    
    impl RowSet {
        fn get_column<T>(&self, name: &str) -> IoResult<&Column<T>> { unimplemented!(); }
    
        fn get_row(&self, index: u64) -> IoResult<&Row> { unimplemented!(); }
    }
    
    pub fn main() -> IoResult<()> {
        let rows = RowSet {};
        let weight_column = rows.get_column::<f32>("weight")?;
        let row = rows.get_row(23)?;
        let weight = row.get(weight_column);
        Ok(())
    }
The point being that i can do the lookup of the column once, ensuring that it exists and has the type i expect, and then safely extract column values from rows later on.


2. I understood the `RowSet` as representing a batch, not the whole data set.

A. I agree that the column should only be requested once, similar to what you propose. Though I'd move the lifetime into the `Row` type instead of returning a reference. Unfortunately you don't totally escape the runtime check, since you still need to check if the column and row come from the same RowSet.


> I'd move the lifetime into the `Row` type instead of returning a reference

I'm afraid i don't understand; which lifetime, and which returned reference?

> Unfortunately you don't totally escape the runtime check, since you still need to check if the column and row come from the same RowSet.

True, but at that point it's a programmer error, so at least you can panic rather than returning a Result!




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: