Path: | doc/release_notes/3.38.0.txt |
Last Update: | Mon May 20 13:42:57 +0000 2013 |
DB.register_row_type(:address)
Then you can create values of that row type:
ad = DB.row_type(:address, ['555 Foo St.', 'Bar City', '98765']) # or ad = DB.row_type(:address, :street=>'555 Foo St.', :city=>'Bar City', :zip=>'98765')
Which you can use in your datasets:
DB[:people].insert(:name=>'Me', :address=>ad)
If you are using the native postgres adapter, when retreiving row type values, they will be returned as instances of the row type, which are hash-like objects:
ad = DB[:people].get(:address) ad[:street] # => '555 Foo St.' ad[:city] # => 'Bar City' ad[:zip] # => '98765'
If you are also using the pg_array extension, then arrays of composite types are supported automatically. Composite types can also include arrays of other types as well as other composite types, though recursive composite types are not allowed by PostgreSQL.
Using arrays and composite types brings one of the benefits of document databases to PostgreSQL, allowing you to store nested structures inside a single row.
r = Sequel.pg_row_op(:row_column)
Then you can get DSL support for accessing members of that row_column via the #[] method:
r[:a] # (row_column).a
This works with composite types containing composite types:
r[:a][:b] # ((row_column).a).b
When used in conjunction with the pg_array_ops extension, there is support for composite types that include arrays, as well as arrays of composite types:
r[1][:a] # (row_column[1]).a r[:a][1] # (row_column).a[1]
The extension offers additional support for referencing a table‘s type when it contains a column with the same name, see the RDoc for details.
class Address < Sequel::Model(:address) plugin :pg_row end
Then you can use Address instances in your datasets:
ad = Address.new(:street=>'555 Foo St.', :city=>'Bar City', :zip=>'98765') DB[:people].insert(:name=>'Me', :address=>ad)
And if you are using the native postgres adapter, the dataset will return the type as a model instance:
ad = DB[:people].get(:address) ad.street # => '555 Foo St.' ad.city # => 'Bar City' ad.zip # => '98765'
Sequel.expr(:table).* # table.* Sequel.expr(:schema__table).* # schema.table.*
This makes it easier to represent the selection of all columns in a table without using the core extensions.
Sequel.pg_array Sequel.pg_array_op Sequel.hstore Sequel.hstore_op Sequel.pg_json Sequel.pg_range Sequel.pg_range_op
The only reason such typecasting was allowed in the first place was to work around issues in the jdbc/postgres, do/postgres, and swift/postgres adapters, using the the typecast_on_load plugin. If you were previously using the typecast_on_load plugin for hstore or array columns, you need to switch to using the new pg_typecast_on_load plugin.
Sequel.expr(:column___alias).desc
This is because expr now returns an AliasedExpression, which doesn‘t support the desc method. However, as you can‘t apply an order to an aliased expression, nobody should be relying on this.