Last active
September 25, 2016 20:16
-
-
Save crisward/8ab38a64d22b08bcdca99098afc47eff to your computer and use it in GitHub Desktop.
Select fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Org | |
DB.mapping({ | |
id: Int32, | |
name: {type: String, nilable: true}, | |
address: {type: String, nilable: true}, | |
postcode: {type: String, nilable: true}, | |
created_at: {type: Time, nilable: true}, | |
updated_at: {type: Time, nilable: true}, | |
deleted_at: {type: Time, nilable: true}, | |
}) | |
JSON.mapping({ | |
id: Int32, | |
name: {type: String, nilable: true}, | |
address: {type: String, nilable: true}, | |
postcode: {type: String, nilable: true}, | |
created_at: {type: Time, nilable: true, converter: Time::Format.new("%FT%T.%LZ")}, # 2012-04-23T18:25:43.511Z | |
updated_at: {type: Time, nilable: true, converter: Time::Format.new("%FT%T.%LZ")}, | |
deleted_at: {type: Time, nilable: true, converter: Time::Format.new("%FT%T.%LZ")}, | |
}) | |
end | |
@db.query("SELECT id,name FROM orgs") do |rs| | |
json = Org.new(rs).to_json | |
end | |
# # Result Wanted | |
# [ | |
# {id:1,name:"org 1"}, | |
# {id:2,name:null}, | |
# {id:3,name:"org 3"} | |
# ] | |
# | |
### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment