How to serialize data using Sequel and Ruby?

I have a table that should store id, name and hash. How to serialize a hash? (I use Ruby and Sequel as ORM.)

+3
source share
4 answers

If you are using Sequel :: Model, the Serialization plugin should do the trick.

+6
source

You seem to have found a sufficient answer, but I thought that I would send it in the usual Ruby way.

# outside of rails you'll need this
require 'base64'

# encode
h = { :first => "John", :age => 23 }
encoded = Base64.encode64(Marshal.dump(h))

# decode
h = Marshal.load(Base64.decode64(encoded))

Ruby (, JSON DB), , cookie Rails . cookie , .

+6

JSON-API, JSONAPI:: . :skip_collection_check, : 1) , , 2) ( ).

+1

YAML:

require 'yaml'

# encode
my_hash = { :first => "John", :age => 23 }
encoded = YAML.dump(my_hash)

# decode
my_hash = YAML.load(encoded)

Sequel String, . .

0

Source: https://habr.com/ru/post/1729940/


All Articles