This PR adds a new Result#columns method which returns an array of Result::Column objects to represent column information such as name, length, and type. At some point this could replaced the fields method, but as of now was added as a non-breaking change.
We added a new Columns class as well. When instantiating a new Result in the C extension, we assign a new instance of our Columns class which carries a pointer to a struct. After populating the properties of the result, we cache the column_info in a struct on the Columns Value and add the information in (including casting some integers into symbol values). We can then lazily-load the data out of the struct and populate the ruby array when calling #columns
Full disclosure: I've never written a C extension (or any C for that matter) before. Any and all feedback welcome - I added a few inline comments in the PR.
Closes #99
This PR adds a new
Result#columns
method which returns an array ofResult::Column
objects to represent column information such as name, length, and type. At some point this could replaced thefields
method, but as of now was added as a non-breaking change.We added a new
Columns
class as well. When instantiating a newResult
in the C extension, we assign a new instance of ourColumns
class which carries a pointer to a struct. After populating the properties of the result, we cache thecolumn_info
in a struct on theColumns
Value and add the information in (including casting some integers into symbol values). We can then lazily-load the data out of the struct and populate the ruby array when calling#columns
Full disclosure: I've never written a C extension (or any C for that matter) before. Any and all feedback welcome - I added a few inline comments in the PR.
CC @composerinteralia @ywenc