CREATE TABLE users (id text, email text, phone_number text);SELECT to_json(users.email, users.phone_number) AS user FROM users WHERE id=usr_123;function to_json但这很好用:
SELECT to_json(users.*) AS user FROM users WHERE id=usr_1
我正在使用Sinatra,并试图通过使用' JSON‘gem并调用.to_json方法来输出一个json格式的对象。我希望输出是JSON,其中包含attr_reader部分中的符号及其值。这是我的代码。我需要做什么特殊的事情才能让它工作吗?@id = id end content_type :json
Foo.new(2, &