Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.51 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. require 'sequel'
  3. require 'sqlite3'
  4. require 'sequel/plugins/serialization'
  5.  
  6. DB = Sequel.sqlite
  7.  
  8. DB.create_table! :players do
  9.   String :name, primary_key: true
  10.   Blob :inventory
  11. end
  12.  
  13. class Player < Sequel::Model
  14.   plugin :serialization
  15.   serialize_attributes :marshal, :inventory
  16.   plugin :serialization_modification_detection
  17. end
  18.  
  19. Player.insert(name: 'joe')
  20.  
  21. j = Player['joe']
  22. j.inventory = {:weapon=>"Sword"}
  23. j.save
  24. puts Player.first(name: 'joe').inventory # => {:weapon=>"Sword"}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement