Skip to content

Instantly share code, notes, and snippets.

@zaiste
Created February 5, 2017 22:52
Show Gist options
  • Select an option

  • Save zaiste/3768b6febfcd82941ad18b40bad1c6ca to your computer and use it in GitHub Desktop.

Select an option

Save zaiste/3768b6febfcd82941ad18b40bad1c6ca to your computer and use it in GitHub Desktop.
Ruby & Datamapper
require 'data_mapper'
require 'dm-pg-types'
DataMapper.setup(:default, 'postgres://localhost/play')
class Person
include DataMapper::Resource
property :id, Serial
property :name, String
property :info, HStore
property :decimals, DecimalArray, :scale => 5, :precision => 10
property :carts, StringArray
end
DataMapper.finalize
DataMapper.auto_upgrade!
p = Person.first(id: '5')
p.decimals = p.decimals.push(2.0)
zoo = p.carts
zoo.delete('pod')
p.carts = zoo
p.save
p p.decimals
p p.carts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment