Skip to content

Commit

Permalink
Add examples of transform_row and scalar_parser to README
Browse files Browse the repository at this point in the history
Co-authored-by: fionaochs <fionaochs@github.com>
  • Loading branch information
kmcq and fionaochs committed Sep 19, 2023
1 parent 81d82be commit 8c48501
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ query = client.query("select * from sys.node")
query_id = query.query_info.query_id
query.each_row {|row| ... } # when a thread is processing the query,
client.kill(query_id) # another thread / process can kill the query.

# Use Query#transform_row to parse Trino ROW types into Ruby Hashes.
# You can also set a scalar_parser to parse scalars how you'd like them.
scalar_parser = -> (data, type) { (type === 'json') ? JSON.parse(data) : data }
client.query("select * from sys.node") do |q|
q.scalar_parser = scalar_parser

# get query results. it feeds more rows until
# query execution finishes:
q.each_row {|row|
p q.transform_row(row)
}
end
```

## Build models
Expand Down

0 comments on commit 8c48501

Please sign in to comment.