Using Sequel and the tiny_tds client in a Sinatra application.
When I use the tiny_tds client in a controller directly, the dataset is
converted to JSON as expected:
before do
content_type :json
end
get '/' do
client = TinyTds::Client.new(:host =>'HOST', :database =>
'DATABASE', :username => 'USER', :password => 'PASSWORD')
query = 'SELECT * FROM MssqlTable'
client.execute(query).each.to_json
end
# results
[{
expected JSON object
}]
However, when I include Sequel:
class MssqlTable < Sequel::Model(: mssql_table )
end
get '/' do
Sequel.connect(adapter: :tinytds, host: 'HOST', port: 1433, database:
'DATABASE', user: 'USER', password: 'PASSWORD')
MssqlTable.all.to_json
# MssqlTable.all.each.to_json # "#<Enumerator:0x00007fdd400f43d8>"
# @results.all.each do |r|
# r.to_json # undefined method `bytesize' for #
# end
end
# results
["#<MssqlTable:0x00007effa80ed068>"]
What's the correct syntax to have <MssqlTable> converted to JSON?
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sequel-talk/18e47e8d-32e0-4f9f-8884-fcff233763c1n%40googlegroups.com.