sequel 4.43.0 → 4.44.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +40 -0
- data/doc/active_record.rdoc +2 -2
- data/doc/code_order.rdoc +15 -0
- data/doc/dataset_filtering.rdoc +1 -1
- data/doc/model_dataset_method_design.rdoc +132 -0
- data/doc/opening_databases.rdoc +2 -2
- data/doc/release_notes/4.44.0.txt +125 -0
- data/lib/sequel/adapters/jdbc.rb +5 -1
- data/lib/sequel/adapters/jdbc/as400.rb +1 -1
- data/lib/sequel/adapters/postgres.rb +23 -14
- data/lib/sequel/core.rb +1 -1
- data/lib/sequel/database/schema_generator.rb +27 -0
- data/lib/sequel/dataset/actions.rb +1 -1
- data/lib/sequel/dataset/query.rb +5 -1
- data/lib/sequel/extensions/eval_inspect.rb +4 -4
- data/lib/sequel/extensions/implicit_subquery.rb +48 -0
- data/lib/sequel/extensions/to_dot.rb +1 -1
- data/lib/sequel/model.rb +3 -5
- data/lib/sequel/model/associations.rb +107 -4
- data/lib/sequel/model/base.rb +98 -12
- data/lib/sequel/model/dataset_module.rb +1 -1
- data/lib/sequel/plugins/active_model.rb +11 -3
- data/lib/sequel/plugins/association_dependencies.rb +7 -0
- data/lib/sequel/plugins/auto_validations.rb +10 -0
- data/lib/sequel/plugins/blacklist_security.rb +13 -4
- data/lib/sequel/plugins/class_table_inheritance.rb +11 -0
- data/lib/sequel/plugins/column_conflicts.rb +8 -0
- data/lib/sequel/plugins/composition.rb +12 -2
- data/lib/sequel/plugins/constraint_validations.rb +12 -0
- data/lib/sequel/plugins/csv_serializer.rb +9 -0
- data/lib/sequel/plugins/defaults_setter.rb +6 -0
- data/lib/sequel/plugins/force_encoding.rb +4 -3
- data/lib/sequel/plugins/hook_class_methods.rb +6 -0
- data/lib/sequel/plugins/input_transformer.rb +9 -0
- data/lib/sequel/plugins/insert_returning_select.rb +8 -0
- data/lib/sequel/plugins/instance_hooks.rb +4 -3
- data/lib/sequel/plugins/json_serializer.rb +9 -0
- data/lib/sequel/plugins/lazy_attributes.rb +7 -0
- data/lib/sequel/plugins/many_through_many.rb +13 -2
- data/lib/sequel/plugins/nested_attributes.rb +7 -0
- data/lib/sequel/plugins/pg_array_associations.rb +18 -2
- data/lib/sequel/plugins/pg_row.rb +3 -3
- data/lib/sequel/plugins/pg_typecast_on_load.rb +7 -0
- data/lib/sequel/plugins/prepared_statements.rb +2 -2
- data/lib/sequel/plugins/prepared_statements_safe.rb +7 -0
- data/lib/sequel/plugins/serialization.rb +9 -0
- data/lib/sequel/plugins/single_table_inheritance.rb +13 -1
- data/lib/sequel/plugins/subclasses.rb +15 -1
- data/lib/sequel/plugins/touch.rb +7 -0
- data/lib/sequel/plugins/tree.rb +7 -0
- data/lib/sequel/plugins/typecast_on_load.rb +7 -0
- data/lib/sequel/plugins/update_refresh.rb +24 -13
- data/lib/sequel/plugins/validation_class_methods.rb +13 -0
- data/lib/sequel/sql.rb +28 -0
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/postgres_spec.rb +18 -15
- data/spec/core/dataset_spec.rb +5 -0
- data/spec/core/expression_filters_spec.rb +33 -0
- data/spec/extensions/active_model_spec.rb +15 -1
- data/spec/extensions/association_dependencies_spec.rb +8 -0
- data/spec/extensions/auto_validations_spec.rb +8 -0
- data/spec/extensions/blacklist_security_spec.rb +6 -0
- data/spec/extensions/class_table_inheritance_spec.rb +9 -0
- data/spec/extensions/column_conflicts_spec.rb +6 -0
- data/spec/extensions/composition_spec.rb +8 -0
- data/spec/extensions/constraint_validations_plugin_spec.rb +12 -0
- data/spec/extensions/csv_serializer_spec.rb +7 -0
- data/spec/extensions/defaults_setter_spec.rb +7 -0
- data/spec/extensions/force_encoding_spec.rb +14 -0
- data/spec/extensions/hook_class_methods_spec.rb +10 -0
- data/spec/extensions/implicit_subquery_spec.rb +60 -0
- data/spec/extensions/input_transformer_spec.rb +10 -0
- data/spec/extensions/insert_returning_select_spec.rb +6 -0
- data/spec/extensions/json_serializer_spec.rb +7 -0
- data/spec/extensions/lazy_attributes_spec.rb +6 -0
- data/spec/extensions/many_through_many_spec.rb +44 -0
- data/spec/extensions/nested_attributes_spec.rb +5 -0
- data/spec/extensions/pg_array_associations_spec.rb +46 -0
- data/spec/extensions/pg_typecast_on_load_spec.rb +5 -0
- data/spec/extensions/prepared_statements_safe_spec.rb +5 -0
- data/spec/extensions/serialization_spec.rb +7 -0
- data/spec/extensions/single_table_inheritance_spec.rb +19 -2
- data/spec/extensions/subclasses_spec.rb +13 -0
- data/spec/extensions/to_dot_spec.rb +1 -1
- data/spec/extensions/touch_spec.rb +6 -0
- data/spec/extensions/tree_spec.rb +6 -0
- data/spec/extensions/typecast_on_load_spec.rb +6 -0
- data/spec/extensions/update_refresh_spec.rb +7 -1
- data/spec/extensions/validation_class_methods_spec.rb +13 -0
- data/spec/model/association_reflection_spec.rb +177 -0
- data/spec/model/associations_spec.rb +16 -0
- data/spec/model/dataset_methods_spec.rb +59 -0
- data/spec/model/model_spec.rb +59 -0
- metadata +8 -2
@@ -49,6 +49,13 @@ module Sequel
|
|
49
49
|
super(load_typecast_pg(values))
|
50
50
|
end
|
51
51
|
|
52
|
+
# Freeze the typecast on load columns when freezing the model class.
|
53
|
+
def freeze
|
54
|
+
@pg_typecast_on_load_columns.freeze
|
55
|
+
|
56
|
+
super
|
57
|
+
end
|
58
|
+
|
52
59
|
# Lookup the conversion proc for the column's oid in the Database
|
53
60
|
# object, and use it to convert the value.
|
54
61
|
def load_typecast_pg(values)
|
@@ -32,11 +32,11 @@ module Sequel
|
|
32
32
|
|
33
33
|
# Setup the datastructure used to hold the prepared statements in the model.
|
34
34
|
def self.apply(model)
|
35
|
-
model.instance_variable_set(:@prepared_statements, :insert=>{}, :insert_select=>{}, :update=>{}, :lookup_sql=>{}, :fixed=>{})
|
35
|
+
model.instance_variable_set(:@prepared_statements, {:insert=>{}, :insert_select=>{}, :update=>{}, :lookup_sql=>{}, :fixed=>{}}.freeze)
|
36
36
|
end
|
37
37
|
|
38
38
|
module ClassMethods
|
39
|
-
Plugins.inherited_instance_variables(self, :@prepared_statements=>lambda{|v| {:insert=>{}, :insert_select=>{}, :update=>{}, :lookup_sql=>{}, :fixed=>{}}})
|
39
|
+
Plugins.inherited_instance_variables(self, :@prepared_statements=>lambda{|v| {:insert=>{}, :insert_select=>{}, :update=>{}, :lookup_sql=>{}, :fixed=>{}}.freeze})
|
40
40
|
|
41
41
|
private
|
42
42
|
|
@@ -38,6 +38,13 @@ module Sequel
|
|
38
38
|
Plugins.inherited_instance_variables(self, :@prepared_statements_column_defaults=>:dup)
|
39
39
|
Plugins.after_set_dataset(self, :set_prepared_statements_column_defaults)
|
40
40
|
|
41
|
+
# Freeze the prepared statements column defaults when freezing the model class.
|
42
|
+
def freeze
|
43
|
+
@prepared_statements_column_defaults.freeze if @prepared_statements_column_defaults
|
44
|
+
|
45
|
+
super
|
46
|
+
end
|
47
|
+
|
41
48
|
private
|
42
49
|
|
43
50
|
# Set the column defaults based on the database schema. All columns
|
@@ -125,6 +125,15 @@ module Sequel
|
|
125
125
|
attr_accessor :serialization_module
|
126
126
|
|
127
127
|
Plugins.inherited_instance_variables(self, :@deserialization_map=>:dup, :@serialization_map=>:dup)
|
128
|
+
|
129
|
+
# Freeze serialization metadata when freezing model class.
|
130
|
+
def freeze
|
131
|
+
@deserialization_map.freeze
|
132
|
+
@serialization_map.freeze
|
133
|
+
@serialization_module.freeze if @serialization_module
|
134
|
+
|
135
|
+
super
|
136
|
+
end
|
128
137
|
|
129
138
|
# Create instance level reader that deserializes column values on request,
|
130
139
|
# and instance level writer that stores new deserialized values.
|
@@ -152,6 +152,18 @@ module Sequel
|
|
152
152
|
|
153
153
|
Plugins.inherited_instance_variables(self, :@sti_dataset=>nil, :@sti_key=>nil, :@sti_key_map=>nil, :@sti_model_map=>nil, :@sti_key_chooser=>nil)
|
154
154
|
|
155
|
+
# Freeze STI information when freezing model class. Note that
|
156
|
+
# because of how STI works, you should not freeze an STI subclass
|
157
|
+
# until after all subclasses of it have been created.
|
158
|
+
def freeze
|
159
|
+
@sti_dataset.freeze
|
160
|
+
@sti_key_array.freeze if @sti_key_array
|
161
|
+
@sti_key_map.freeze if @sti_key_map.is_a?(Hash)
|
162
|
+
@sti_model_map.freeze if @sti_model_map.is_a?(Hash)
|
163
|
+
|
164
|
+
super
|
165
|
+
end
|
166
|
+
|
155
167
|
# Copy the necessary attributes to the subclasses, and filter the
|
156
168
|
# subclass's dataset based on the sti_kep_map entry for the class.
|
157
169
|
def inherited(subclass)
|
@@ -159,7 +171,7 @@ module Sequel
|
|
159
171
|
key = Array(sti_key_map[subclass]).dup
|
160
172
|
sti_subclass_added(key)
|
161
173
|
rp = dataset.row_proc
|
162
|
-
subclass.set_dataset(sti_dataset.where(SQL::QualifiedIdentifier.new(sti_dataset.first_source_alias, sti_key)=>Sequel.delay{key}), :inherited=>true)
|
174
|
+
subclass.set_dataset(sti_dataset.where(SQL::QualifiedIdentifier.new(sti_dataset.first_source_alias, sti_key)=>Sequel.delay{Sequel.synchronize{key}}), :inherited=>true)
|
163
175
|
subclass.instance_eval do
|
164
176
|
@dataset = @dataset.with_row_proc(rp)
|
165
177
|
@sti_key_array = key
|
@@ -5,7 +5,7 @@ module Sequel
|
|
5
5
|
# The Subclasses plugin keeps track of all subclasses of the
|
6
6
|
# current model class. Direct subclasses are available via the
|
7
7
|
# subclasses method, and all descendent classes are available via the
|
8
|
-
# descendents method
|
8
|
+
# descendents method:
|
9
9
|
#
|
10
10
|
# c = Class.new(Sequel::Model)
|
11
11
|
# c.plugin :subclasses
|
@@ -18,6 +18,14 @@ module Sequel
|
|
18
18
|
# ssc1.subclasses # []
|
19
19
|
# c.descendents # [sc1, ssc1, sc2]
|
20
20
|
#
|
21
|
+
# You can also finalize the associations and then freeze the classes
|
22
|
+
# in all descendent classes. Doing so is a recommended practice after
|
23
|
+
# all models have been defined in production and testing, and this makes
|
24
|
+
# it easier that keeping track of the classes to finalize and freeze
|
25
|
+
# manually:
|
26
|
+
#
|
27
|
+
# c.freeze_descendants
|
28
|
+
#
|
21
29
|
# You can provide a block when loading the plugin, and it will be called
|
22
30
|
# with each subclass created:
|
23
31
|
#
|
@@ -47,6 +55,12 @@ module Sequel
|
|
47
55
|
Sequel.synchronize{subclasses.dup}.map{|x| [x] + x.send(:descendents)}.flatten
|
48
56
|
end
|
49
57
|
|
58
|
+
# Freeze all descendent classes. This also finalizes the associations for those
|
59
|
+
# classes before freezing.
|
60
|
+
def freeze_descendents
|
61
|
+
descendents.each(&:finalize_associations).each(&:freeze)
|
62
|
+
end
|
63
|
+
|
50
64
|
Plugins.inherited_instance_variables(self, :@subclasses=>lambda{|v| []}, :@on_subclass=>nil)
|
51
65
|
|
52
66
|
# Add the subclass to this model's current subclasses,
|
data/lib/sequel/plugins/touch.rb
CHANGED
@@ -63,6 +63,13 @@ module Sequel
|
|
63
63
|
|
64
64
|
Plugins.inherited_instance_variables(self, :@touched_associations=>:dup, :@touch_column=>nil)
|
65
65
|
|
66
|
+
# Freeze the touched associations when freezing the model class.
|
67
|
+
def freeze
|
68
|
+
@touched_associations.freeze
|
69
|
+
|
70
|
+
super
|
71
|
+
end
|
72
|
+
|
66
73
|
# Add additional associations to be touched. See the :association option
|
67
74
|
# of the Sequel::Plugin::Touch.configure method for the format of the associations
|
68
75
|
# arguments.
|
data/lib/sequel/plugins/tree.rb
CHANGED
@@ -63,6 +63,13 @@ module Sequel
|
|
63
63
|
|
64
64
|
Plugins.inherited_instance_variables(self, :@parent_column=>nil, :@tree_order=>nil)
|
65
65
|
|
66
|
+
# Should freeze tree order if it is an array when freezing the model class.
|
67
|
+
def freeze
|
68
|
+
@tree_order.freeze if @tree_order.is_a?(Array)
|
69
|
+
|
70
|
+
super
|
71
|
+
end
|
72
|
+
|
66
73
|
# Returns list of all root nodes (those with no parent nodes).
|
67
74
|
#
|
68
75
|
# TreeClass.roots # => [root1, root2]
|
@@ -44,6 +44,13 @@ module Sequel
|
|
44
44
|
super.load_typecast
|
45
45
|
end
|
46
46
|
|
47
|
+
# Freeze typecast on load columns when freezing model class.
|
48
|
+
def freeze
|
49
|
+
@typecast_on_load_columns.freeze
|
50
|
+
|
51
|
+
super
|
52
|
+
end
|
53
|
+
|
47
54
|
Plugins.inherited_instance_variables(self, :@typecast_on_load_columns=>:dup)
|
48
55
|
end
|
49
56
|
|
@@ -27,16 +27,36 @@ module Sequel
|
|
27
27
|
# +columns+ option. This can be a performance gain if it
|
28
28
|
# would avoid pointlessly comparing many other columns.
|
29
29
|
# Note that this option currently only has an effect if the
|
30
|
-
# dataset
|
30
|
+
# dataset supports RETURNING.
|
31
31
|
#
|
32
32
|
# # Only include the artist column in RETURNING
|
33
33
|
# Album.plugin :update_refresh, :columns => :artist
|
34
34
|
#
|
35
35
|
# # Only include the artist and title columns in RETURNING
|
36
36
|
# Album.plugin :update_refresh, :columns => [ :artist, :title ]
|
37
|
-
#
|
38
37
|
module UpdateRefresh
|
38
|
+
# Set the specific columns to refresh, if the :columns option
|
39
|
+
# is provided.
|
40
|
+
def self.configure(model, opts=OPTS)
|
41
|
+
model.instance_eval do
|
42
|
+
@update_refresh_columns = Array(opts[:columns]) || []
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
module ClassMethods
|
47
|
+
# The specific columns to refresh when updating, if UPDATE RETURNING is supported.
|
48
|
+
attr_reader :update_refresh_columns
|
49
|
+
|
50
|
+
# Freeze the update refresh columns when freezing the model class.
|
51
|
+
def freeze
|
52
|
+
@update_refresh_columns.freeze
|
53
|
+
|
54
|
+
super
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
39
58
|
module InstanceMethods
|
59
|
+
# If the dataset does not support UPDATE RETURNING, then refresh after an update.
|
40
60
|
def after_update
|
41
61
|
super
|
42
62
|
unless this.supports_returning?(:update)
|
@@ -46,6 +66,8 @@ module Sequel
|
|
46
66
|
|
47
67
|
private
|
48
68
|
|
69
|
+
# If the dataset supports UPDATE RETURNING, use it to do the refresh in the same
|
70
|
+
# query as the update.
|
49
71
|
def _update_without_checking(columns)
|
50
72
|
ds = _update_dataset
|
51
73
|
if ds.supports_returning?(:update)
|
@@ -61,17 +83,6 @@ module Sequel
|
|
61
83
|
end
|
62
84
|
end
|
63
85
|
end
|
64
|
-
|
65
|
-
module ClassMethods
|
66
|
-
attr_reader :update_refresh_columns
|
67
|
-
end
|
68
|
-
|
69
|
-
def self.configure(model, opts=OPTS)
|
70
|
-
model.instance_eval do
|
71
|
-
@update_refresh_columns = Array(opts[:columns]) || []
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
86
|
end
|
76
87
|
end
|
77
88
|
end
|
@@ -39,6 +39,19 @@ module Sequel
|
|
39
39
|
# options.
|
40
40
|
attr_reader :validation_reflections
|
41
41
|
|
42
|
+
# Freeze validation metadata when freezing model class.
|
43
|
+
def freeze
|
44
|
+
@validations.freeze.each_value(&:freeze)
|
45
|
+
@validation_reflections.freeze.each_value do |vs|
|
46
|
+
vs.freeze.each do |v|
|
47
|
+
v.freeze
|
48
|
+
v.last.freeze
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
super
|
53
|
+
end
|
54
|
+
|
42
55
|
# The Generator class is used to generate validation definitions using
|
43
56
|
# the validates {} idiom.
|
44
57
|
class Generator
|
data/lib/sequel/sql.rb
CHANGED
@@ -62,6 +62,11 @@ module Sequel
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
# Show that this is an SQLTime, and the time represented
|
66
|
+
def inspect
|
67
|
+
"#<#{self.class} #{to_s}>"
|
68
|
+
end
|
69
|
+
|
65
70
|
# Return a string in HH:MM:SS format representing the time.
|
66
71
|
def to_s(*args)
|
67
72
|
if args.empty?
|
@@ -1054,6 +1059,20 @@ module Sequel
|
|
1054
1059
|
def lit(*args)
|
1055
1060
|
args.empty? ? LiteralString.new(self) : SQL::PlaceholderLiteralString.new(self, args)
|
1056
1061
|
end
|
1062
|
+
|
1063
|
+
# Return a string showing that this is a blob, the size, and the some or all of the content,
|
1064
|
+
# depending on the size.
|
1065
|
+
def inspect
|
1066
|
+
size = length
|
1067
|
+
|
1068
|
+
content = if size > 20
|
1069
|
+
"start=#{self[0...10].to_s.inspect} end=#{self[-10..-1].to_s.inspect}"
|
1070
|
+
else
|
1071
|
+
"content=#{super}"
|
1072
|
+
end
|
1073
|
+
|
1074
|
+
"#<#{self.class}:0x#{"%x" % object_id} bytes=#{size} #{content}>"
|
1075
|
+
end
|
1057
1076
|
|
1058
1077
|
# Returns +self+, since it is already a blob.
|
1059
1078
|
def to_sequel_blob
|
@@ -1801,6 +1820,10 @@ module Sequel
|
|
1801
1820
|
# ruby array of two element arrays as an SQL value list instead of an ordered
|
1802
1821
|
# hash-like conditions specifier.
|
1803
1822
|
class ValueList < ::Array
|
1823
|
+
# Show that this is a value list and not just an array
|
1824
|
+
def inspect
|
1825
|
+
"#<#{self.class} #{super}>"
|
1826
|
+
end
|
1804
1827
|
end
|
1805
1828
|
|
1806
1829
|
# The purpose of the +VirtualRow+ class is to allow the easy creation of SQL identifiers and functions
|
@@ -1990,6 +2013,11 @@ module Sequel
|
|
1990
2013
|
include SQL::InequalityMethods
|
1991
2014
|
include SQL::AliasMethods
|
1992
2015
|
include SQL::CastMethods
|
2016
|
+
|
2017
|
+
# Show that the current string is a literal string in addition to the output.
|
2018
|
+
def inspect
|
2019
|
+
"#<#{self.class} #{super}>"
|
2020
|
+
end
|
1993
2021
|
|
1994
2022
|
# Return self if no args are given, otherwise return a SQL::PlaceholderLiteralString
|
1995
2023
|
# with the current string and the given args.
|
data/lib/sequel/version.rb
CHANGED
@@ -5,7 +5,7 @@ module Sequel
|
|
5
5
|
MAJOR = 4
|
6
6
|
# The minor version of Sequel. Bumped for every non-patch level
|
7
7
|
# release, generally around once a month.
|
8
|
-
MINOR =
|
8
|
+
MINOR = 44
|
9
9
|
# The tiny version of Sequel. Usually 0, only bumped for bugfix
|
10
10
|
# releases that fix regressions from previous versions.
|
11
11
|
TINY = 0
|
@@ -2,6 +2,9 @@ SEQUEL_ADAPTER_TEST = :postgres
|
|
2
2
|
|
3
3
|
require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
|
4
4
|
|
5
|
+
uses_pg = Sequel::Postgres::USES_PG if DB.adapter_scheme == :postgres
|
6
|
+
uses_pg_or_jdbc = uses_pg || DB.adapter_scheme == :jdbc
|
7
|
+
|
5
8
|
def DB.sqls
|
6
9
|
(@sqls ||= [])
|
7
10
|
end
|
@@ -361,7 +364,7 @@ describe "A PostgreSQL database" do
|
|
361
364
|
a = nil
|
362
365
|
Sequel.connect(DB.opts.merge(:notice_receiver=>proc{|r| a = r.result_error_message})){|db| db.do("BEGIN\nRAISE WARNING 'foo';\nEND;")}
|
363
366
|
a.must_equal "WARNING: foo\n"
|
364
|
-
end if
|
367
|
+
end if uses_pg && DB.server_version >= 90000
|
365
368
|
|
366
369
|
# These only test the SQL created, because a true test using file_fdw or postgres_fdw
|
367
370
|
# requires superuser permissions, and you should not be running the tests as a superuser.
|
@@ -524,7 +527,7 @@ describe "A PostgreSQL dataset" do
|
|
524
527
|
info[:constraint].must_be_nil
|
525
528
|
info[:column].must_equal 't2'
|
526
529
|
info[:type].must_be_nil
|
527
|
-
end if DB.server_version >= 90300 &&
|
530
|
+
end if DB.server_version >= 90300 && uses_pg && Object.const_defined?(:PG) && ::PG.const_defined?(:Constants) && ::PG::Constants.const_defined?(:PG_DIAG_SCHEMA_NAME)
|
528
531
|
|
529
532
|
it "should support Database#do for executing anonymous code blocks" do
|
530
533
|
@db.drop_table?(:btest)
|
@@ -1776,7 +1779,7 @@ if DB.adapter_scheme == :postgres
|
|
1776
1779
|
end
|
1777
1780
|
end
|
1778
1781
|
|
1779
|
-
if
|
1782
|
+
if uses_pg_or_jdbc && DB.server_version >= 90000
|
1780
1783
|
describe "Postgres::Database#copy_into" do
|
1781
1784
|
before(:all) do
|
1782
1785
|
@db = DB
|
@@ -1928,7 +1931,7 @@ if ((DB.adapter_scheme == :postgres && SEQUEL_POSTGRES_USES_PG) || DB.adapter_sc
|
|
1928
1931
|
end
|
1929
1932
|
end
|
1930
1933
|
|
1931
|
-
if
|
1934
|
+
if uses_pg && DB.server_version >= 90000
|
1932
1935
|
describe "Postgres::Database LISTEN/NOTIFY" do
|
1933
1936
|
before(:all) do
|
1934
1937
|
@db = DB
|
@@ -2416,7 +2419,7 @@ describe 'PostgreSQL array handling' do
|
|
2416
2419
|
@ds.get(:i).must_equal a
|
2417
2420
|
@ds.filter(:i=>:$i).call(:first, :i=>a).must_equal(:i=>a)
|
2418
2421
|
@ds.filter(:i=>:$i).call(:first, :i=>Sequel.pg_array([Sequel.blob("b\0")], 'bytea')).must_be_nil
|
2419
|
-
end if
|
2422
|
+
end if uses_pg_or_jdbc
|
2420
2423
|
|
2421
2424
|
it 'with models' do
|
2422
2425
|
@db.create_table!(:items) do
|
@@ -2604,7 +2607,7 @@ describe 'PostgreSQL hstore handling' do
|
|
2604
2607
|
@ds.get(:i).must_equal @h
|
2605
2608
|
@ds.filter(:i=>:$i).call(:first, :i=>@h).must_equal(:i=>@h)
|
2606
2609
|
@ds.filter(:i=>:$i).call(:first, :i=>{}).must_be_nil
|
2607
|
-
end if
|
2610
|
+
end if uses_pg_or_jdbc
|
2608
2611
|
|
2609
2612
|
it 'with models and associations' do
|
2610
2613
|
@db.create_table!(:items) do
|
@@ -2877,7 +2880,7 @@ describe 'PostgreSQL json type' do
|
|
2877
2880
|
j = Sequel.pg_array([pg_json.call('a'=>1), pg_json.call(['b', 2])], json_type)
|
2878
2881
|
@ds.call(:insert, {:i=>j}, {:i=>:$i})
|
2879
2882
|
@ds.get(:i).must_equal j
|
2880
|
-
end if
|
2883
|
+
end if uses_pg_or_jdbc
|
2881
2884
|
|
2882
2885
|
it 'operations/functions with pg_json_ops' do
|
2883
2886
|
Sequel.extension :pg_json_ops
|
@@ -3072,7 +3075,7 @@ describe 'PostgreSQL inet/cidr types' do
|
|
3072
3075
|
@ds.filter(:i=>:$i, :c=>:$c, :m=>:$m).call(:first, :i=>[@ipv4], :c=>[@ipv4nm], :m=>['12:34:56:78:90:ab']).must_equal(:i=>[@ipv4], :c=>[@ipv4nm], :m=>['12:34:56:78:90:ab'])
|
3073
3076
|
@ds.filter(:i=>:$i, :c=>:$c, :m=>:$m).call(:first, :i=>[], :c=>[], :m=>[]).must_be_nil
|
3074
3077
|
@ds.filter(:i=>:$i, :c=>:$c, :m=>:$m).call(:delete, :i=>[@ipv4], :c=>[@ipv4nm], :m=>['12:34:56:78:90:ab']).must_equal 1
|
3075
|
-
end if
|
3078
|
+
end if uses_pg_or_jdbc
|
3076
3079
|
|
3077
3080
|
it 'with models' do
|
3078
3081
|
@db.create_table!(:items) do
|
@@ -3235,7 +3238,7 @@ describe 'PostgreSQL range types' do
|
|
3235
3238
|
@ds.filter(h).call(:first, @pgra).each{|k, v| v.must_be :==, @ra[k].to_a}
|
3236
3239
|
@ds.filter(h).call(:first, r2).must_be_nil
|
3237
3240
|
@ds.filter(h).call(:delete, @ra).must_equal 1
|
3238
|
-
end if
|
3241
|
+
end if uses_pg_or_jdbc
|
3239
3242
|
|
3240
3243
|
it 'with models' do
|
3241
3244
|
@db.create_table!(:items){primary_key :id; int4range :i4; int8range :i8; numrange :n; daterange :d; tsrange :t; tstzrange :tz}
|
@@ -3416,7 +3419,7 @@ describe 'PostgreSQL interval types' do
|
|
3416
3419
|
@ds.filter(:i=>:$i).call(:first, :i=>[d]).must_equal(:i=>[d])
|
3417
3420
|
@ds.filter(:i=>:$i).call(:first, :i=>[]).must_be_nil
|
3418
3421
|
@ds.filter(:i=>:$i).call(:delete, :i=>[d]).must_equal 1
|
3419
|
-
end if
|
3422
|
+
end if uses_pg_or_jdbc
|
3420
3423
|
|
3421
3424
|
it 'with models' do
|
3422
3425
|
@db.create_table!(:items) do
|
@@ -3533,7 +3536,7 @@ describe 'PostgreSQL row-valued/composite types' do
|
|
3533
3536
|
@ds.delete
|
3534
3537
|
@ds.call(:insert, {:address=>Sequel.pg_row([nil, nil, nil])}, {:address=>:$address, :id=>1})
|
3535
3538
|
@ds.get(:address).must_equal(:street=>nil, :city=>nil, :zip=>nil)
|
3536
|
-
end if
|
3539
|
+
end if uses_pg_or_jdbc
|
3537
3540
|
|
3538
3541
|
it 'use arrays of row types in bound variables' do
|
3539
3542
|
@ds = @db[:company]
|
@@ -3545,7 +3548,7 @@ describe 'PostgreSQL row-valued/composite types' do
|
|
3545
3548
|
@ds.delete
|
3546
3549
|
@ds.call(:insert, {:employees=>Sequel.pg_array([@db.row_type(:person, [1, Sequel.pg_row([nil, nil, nil])])])}, {:employees=>:$employees, :id=>1})
|
3547
3550
|
@ds.get(:employees).must_equal [{:address=>{:city=>nil, :zip=>nil, :street=>nil}, :id=>1}]
|
3548
|
-
end if
|
3551
|
+
end if uses_pg_or_jdbc
|
3549
3552
|
|
3550
3553
|
it 'operations/functions with pg_row_ops' do
|
3551
3554
|
@ds.insert(:id=>1, :address=>Sequel.pg_row(['123 Sesame St', 'Somewhere', '12345']))
|
@@ -3671,7 +3674,7 @@ describe 'PostgreSQL row-valued/composite types' do
|
|
3671
3674
|
@ds.get(:address).must_equal @a
|
3672
3675
|
@ds.filter(:address=>Sequel.cast(:$address, :address)).call(:first, :address=>@a)[:id].must_equal 1
|
3673
3676
|
@ds.filter(:address=>Sequel.cast(:$address, :address)).call(:first, :address=>Address.new(:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12356')).must_be_nil
|
3674
|
-
end if
|
3677
|
+
end if uses_pg_or_jdbc
|
3675
3678
|
|
3676
3679
|
it 'use arrays of model objects in bound variables' do
|
3677
3680
|
@ds = @db[:company]
|
@@ -3679,7 +3682,7 @@ describe 'PostgreSQL row-valued/composite types' do
|
|
3679
3682
|
@ds.get(:company).must_equal Company.new(:id=>1, :employees=>@es)
|
3680
3683
|
@ds.filter(:employees=>Sequel.cast(:$employees, 'person[]')).call(:first, :employees=>@es)[:id].must_equal 1
|
3681
3684
|
@ds.filter(:employees=>Sequel.cast(:$employees, 'person[]')).call(:first, :employees=>Sequel.pg_array([@db.row_type(:person, [1, Sequel.pg_row(['123 Sesame St', 'Somewhere', '12356'])])])).must_be_nil
|
3682
|
-
end if
|
3685
|
+
end if uses_pg_or_jdbc
|
3683
3686
|
|
3684
3687
|
it 'model typecasting' do
|
3685
3688
|
Person.plugin :pg_typecast_on_load, :address unless @native
|
@@ -3744,7 +3747,7 @@ describe 'pg_static_cache_updater extension' do
|
|
3744
3747
|
q1.push(proc{throw :stop})
|
3745
3748
|
q.pop
|
3746
3749
|
end
|
3747
|
-
end if
|
3750
|
+
end if uses_pg && DB.server_version >= 90000
|
3748
3751
|
|
3749
3752
|
describe 'PostgreSQL enum types' do
|
3750
3753
|
before do
|