Skip to content

Instantly share code, notes, and snippets.

@crisward
Last active September 25, 2016 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crisward/8ab38a64d22b08bcdca99098afc47eff to your computer and use it in GitHub Desktop.
Save crisward/8ab38a64d22b08bcdca99098afc47eff to your computer and use it in GitHub Desktop.
Select fields
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