trilogy-libraries / trilogy

Trilogy is a client library for MySQL-compatible database servers, designed for performance, flexibility, and ease of embedding.
MIT License
700 stars 69 forks source link

Add `Result#columns` to store field types #124

Open ipc103 opened 1 year ago

ipc103 commented 1 year ago

Closes #99

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.

CC @composerinteralia @ywenc