sequel_core 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/CHANGELOG +74 -0
  2. data/COPYING +1 -0
  3. data/README +17 -6
  4. data/Rakefile +16 -21
  5. data/lib/sequel_core.rb +18 -28
  6. data/lib/sequel_core/adapters/ado.rb +3 -15
  7. data/lib/sequel_core/adapters/dbi.rb +1 -14
  8. data/lib/sequel_core/adapters/informix.rb +3 -3
  9. data/lib/sequel_core/adapters/jdbc.rb +2 -2
  10. data/lib/sequel_core/adapters/mysql.rb +39 -59
  11. data/lib/sequel_core/adapters/odbc.rb +18 -38
  12. data/lib/sequel_core/adapters/openbase.rb +1 -17
  13. data/lib/sequel_core/adapters/oracle.rb +1 -19
  14. data/lib/sequel_core/adapters/postgres.rb +20 -60
  15. data/lib/sequel_core/adapters/sqlite.rb +4 -8
  16. data/lib/sequel_core/connection_pool.rb +150 -0
  17. data/lib/sequel_core/core_ext.rb +41 -0
  18. data/lib/sequel_core/core_sql.rb +35 -38
  19. data/lib/sequel_core/database.rb +20 -17
  20. data/lib/sequel_core/dataset.rb +49 -80
  21. data/lib/sequel_core/dataset/callback.rb +11 -13
  22. data/lib/sequel_core/dataset/convenience.rb +18 -136
  23. data/lib/sequel_core/dataset/pagination.rb +81 -0
  24. data/lib/sequel_core/dataset/sequelizer.rb +5 -4
  25. data/lib/sequel_core/dataset/sql.rb +43 -33
  26. data/lib/sequel_core/deprecated.rb +200 -0
  27. data/lib/sequel_core/exceptions.rb +0 -14
  28. data/lib/sequel_core/object_graph.rb +199 -0
  29. data/lib/sequel_core/pretty_table.rb +27 -24
  30. data/lib/sequel_core/schema/generator.rb +16 -4
  31. data/lib/sequel_core/schema/sql.rb +5 -3
  32. data/lib/sequel_core/worker.rb +1 -1
  33. data/spec/adapters/informix_spec.rb +1 -47
  34. data/spec/adapters/mysql_spec.rb +85 -54
  35. data/spec/adapters/oracle_spec.rb +1 -57
  36. data/spec/adapters/postgres_spec.rb +66 -49
  37. data/spec/adapters/sqlite_spec.rb +4 -29
  38. data/spec/connection_pool_spec.rb +358 -0
  39. data/spec/core_sql_spec.rb +24 -19
  40. data/spec/database_spec.rb +13 -9
  41. data/spec/dataset_spec.rb +59 -78
  42. data/spec/object_graph_spec.rb +202 -0
  43. data/spec/pretty_table_spec.rb +1 -9
  44. data/spec/schema_generator_spec.rb +7 -1
  45. data/spec/schema_spec.rb +27 -0
  46. data/spec/sequelizer_spec.rb +2 -2
  47. data/spec/spec_helper.rb +4 -2
  48. metadata +16 -57
  49. data/lib/sequel_core/array_keys.rb +0 -322
  50. data/lib/sequel_core/model.rb +0 -8
  51. data/spec/array_keys_spec.rb +0 -682
@@ -59,12 +59,15 @@ module Sequel
59
59
  end
60
60
 
61
61
  def full_text_index(columns, opts = {})
62
- columns = [columns] unless columns.is_a?(Array)
63
- @indexes << {:columns => columns, :full_text => true}.merge(opts)
62
+ index(columns, opts.merge(:type => :full_text))
64
63
  end
65
64
 
65
+ def spatial_index(columns, opts = {})
66
+ index(columns, opts.merge(:type => :spatial))
67
+ end
68
+
66
69
  def unique(columns, opts = {})
67
- index(columns, {:unique => true}.merge(opts))
70
+ index(columns, opts.merge(:unique => true))
68
71
  end
69
72
 
70
73
  def create_info
@@ -136,7 +139,16 @@ module Sequel
136
139
  @operations << { \
137
140
  :op => :add_index, \
138
141
  :columns => columns, \
139
- :full_text => true \
142
+ :type => :full_text \
143
+ }.merge(opts)
144
+ end
145
+
146
+ def add_spatial_index(columns, opts = {})
147
+ columns = [columns] unless columns.is_a?(Array)
148
+ @operations << { \
149
+ :op => :add_index, \
150
+ :columns => columns, \
151
+ :type => :spatial \
140
152
  }.merge(opts)
141
153
  end
142
154
 
@@ -51,7 +51,7 @@ module Sequel
51
51
  end
52
52
 
53
53
  def expression_list(*args, &block)
54
- schema_utility_dataset.expression_list(*args, &block)
54
+ schema_utility_dataset.send(:expression_list, *args, &block)
55
55
  end
56
56
 
57
57
  def column_definition_sql(column)
@@ -96,8 +96,10 @@ module Sequel
96
96
 
97
97
  def index_definition_sql(table_name, index)
98
98
  index_name = index[:name] || default_index_name(table_name, index[:columns])
99
- if index[:full_text]
100
- raise Error, "Full-text indexes are not supported for this database"
99
+ if index[:type]
100
+ raise Error, "Index types are not supported for this database"
101
+ elsif index[:where]
102
+ raise Error, "Partial indexes are not supported for this database"
101
103
  elsif index[:unique]
102
104
  "CREATE UNIQUE INDEX #{index_name} ON #{table_name} (#{literal(index[:columns])})"
103
105
  else
@@ -20,7 +20,7 @@ module Sequel
20
20
  loop {next_job}
21
21
  rescue Sequel::Error::WorkerStop # signals the worker thread to stop
22
22
  ensure
23
- rollback! if @transaction && !@errors.empty?
23
+ raise Sequel::Error::Rollback if @transaction && !@errors.empty?
24
24
  end
25
25
 
26
26
  def busy?
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), '../../lib/sequel_core')
2
2
  require File.join(File.dirname(__FILE__), '../spec_helper.rb')
3
3
 
4
4
  unless defined?(INFORMIX_DB)
5
- INFORMIX_DB = Sequel('informix://localhost/mydb')
5
+ INFORMIX_DB = Sequel.connect('informix://localhost/mydb')
6
6
  end
7
7
 
8
8
  if INFORMIX_DB.table_exists?(:test)
@@ -95,49 +95,3 @@ context "A Informix dataset" do
95
95
  @d.order(:value).last.should == {:name => 'def', :value => 789}
96
96
  end
97
97
  end
98
-
99
- context "A Informix dataset in array tuples mode" do
100
- setup do
101
- @d = INFORMIX_DB[:test]
102
- @d.delete # remove all records
103
- Sequel.use_array_tuples
104
- end
105
-
106
- teardown do
107
- Sequel.use_hash_tuples
108
- end
109
-
110
- specify "should return the correct records" do
111
- @d.to_a.should == []
112
- @d << {:name => 'abc', :value => 123}
113
- @d << {:name => 'abc', :value => 456}
114
- @d << {:name => 'def', :value => 789}
115
-
116
- @d.order(:value).select(:name, :value).to_a.should == [
117
- ['abc', 123],
118
- ['abc', 456],
119
- ['def', 789]
120
- ]
121
- end
122
-
123
- specify "should work correctly with transforms" do
124
- @d.transform(:value => [proc {|v| v.to_s}, proc {|v| v.to_i}])
125
-
126
- @d.to_a.should == []
127
- @d << {:name => 'abc', :value => 123}
128
- @d << {:name => 'abc', :value => 456}
129
- @d << {:name => 'def', :value => 789}
130
-
131
- @d.order(:value).select(:name, :value).to_a.should == [
132
- ['abc', '123'],
133
- ['abc', '456'],
134
- ['def', '789']
135
- ]
136
-
137
- a = @d.order(:value).first
138
- a.values.should == ['abc', '123']
139
- a.keys.should == [:name, :value]
140
- a[:name].should == 'abc'
141
- a[:value].should == '123'
142
- end
143
- end
@@ -3,8 +3,8 @@ require File.join(File.dirname(__FILE__), '../spec_helper.rb')
3
3
  require 'logger'
4
4
 
5
5
  unless defined?(MYSQL_DB)
6
- MYSQL_URL = 'mysql://root@localhost/sandbox' unless defined? MYSQL_URL
7
- MYSQL_DB = Sequel(MYSQL_URL)
6
+ MYSQL_URL = (ENV['SEQUEL_MY_SPEC_DB']||'mysql://root@localhost/sandbox') unless defined? MYSQL_URL
7
+ MYSQL_DB = Sequel.connect(MYSQL_URL)
8
8
  end
9
9
  unless defined?(MYSQL_SOCKET_FILE)
10
10
  MYSQL_SOCKET_FILE = '/tmp/mysql.sock'
@@ -114,16 +114,16 @@ context "A MySQL dataset" do
114
114
  @d.select('COUNT(*)'.lit).sql.should == \
115
115
  'SELECT COUNT(*) FROM items'
116
116
 
117
- @d.select(:value.MAX).sql.should == \
117
+ @d.select(:max[:value]).sql.should == \
118
118
  'SELECT max(`value`) FROM items'
119
119
 
120
120
  @d.select(:NOW[]).sql.should == \
121
121
  'SELECT NOW() FROM items'
122
122
 
123
- @d.select(:items__value.MAX).sql.should == \
123
+ @d.select(:max[:items__value]).sql.should == \
124
124
  'SELECT max(items.`value`) FROM items'
125
125
 
126
- @d.order(:name.DESC).sql.should == \
126
+ @d.order(:name.desc).sql.should == \
127
127
  'SELECT * FROM items ORDER BY `name` DESC'
128
128
 
129
129
  @d.select('items.name AS item_name'.lit).sql.should == \
@@ -155,13 +155,13 @@ context "A MySQL dataset" do
155
155
  @d.reverse_order(:name).sql.should == \
156
156
  'SELECT * FROM items ORDER BY `name` DESC'
157
157
 
158
- @d.reverse_order(:name.DESC).sql.should == \
158
+ @d.reverse_order(:name.desc).sql.should == \
159
159
  'SELECT * FROM items ORDER BY `name`'
160
160
 
161
- @d.reverse_order(:name, :test.DESC).sql.should == \
161
+ @d.reverse_order(:name, :test.desc).sql.should == \
162
162
  'SELECT * FROM items ORDER BY `name` DESC, `test`'
163
163
 
164
- @d.reverse_order(:name.DESC, :test).sql.should == \
164
+ @d.reverse_order(:name.desc, :test).sql.should == \
165
165
  'SELECT * FROM items ORDER BY `name`, `test` DESC'
166
166
  end
167
167
 
@@ -198,52 +198,6 @@ context "A MySQL dataset" do
198
198
  end
199
199
  end
200
200
 
201
- context "A MySQL dataset in array tuples mode" do
202
- setup do
203
- @d = MYSQL_DB[:items]
204
- @d.delete # remove all records
205
- Sequel.use_array_tuples
206
- end
207
-
208
- teardown do
209
- Sequel.use_hash_tuples
210
- end
211
-
212
- specify "should return the correct records" do
213
- @d.to_a.should == []
214
- @d << {:name => 'abc', :value => 123}
215
- @d << {:name => 'abc', :value => 456}
216
- @d << {:name => 'def', :value => 789}
217
-
218
- @d.order(:value).select(:name, :value).to_a.should == [
219
- ['abc', 123],
220
- ['abc', 456],
221
- ['def', 789]
222
- ]
223
- end
224
-
225
- specify "should work correctly with transforms" do
226
- @d.transform(:value => [proc {|v| v.to_s}, proc {|v| v.to_i}])
227
-
228
- @d.to_a.should == []
229
- @d << {:name => 'abc', :value => 123}
230
- @d << {:name => 'abc', :value => 456}
231
- @d << {:name => 'def', :value => 789}
232
-
233
- @d.order(:value).select(:name, :value).to_a.should == [
234
- ['abc', '123'],
235
- ['abc', '456'],
236
- ['def', '789']
237
- ]
238
-
239
- a = @d.order(:value).first
240
- a.values.should == ['abc', '123']
241
- a.keys.should == [:name, :value]
242
- a[:name].should == 'abc'
243
- a[:value].should == '123'
244
- end
245
- end
246
-
247
201
  context "MySQL datasets" do
248
202
  setup do
249
203
  @d = MYSQL_DB[:orders]
@@ -513,6 +467,39 @@ context "A MySQL database" do
513
467
  MYSQL_DB[:posts].full_text_search(:title, '+ruby -rails', :boolean => true).sql.should ==
514
468
  "SELECT * FROM posts WHERE (MATCH (`title`) AGAINST ('+ruby -rails' IN BOOLEAN MODE))"
515
469
  end
470
+
471
+ specify "should support spatial indexes" do
472
+ g = Sequel::Schema::Generator.new(MYSQL_DB) do
473
+ point :geom
474
+ spatial_index [:geom]
475
+ end
476
+ MYSQL_DB.create_table_sql_list(:posts, *g.create_info).should == [
477
+ "CREATE TABLE posts (`geom` point)",
478
+ "CREATE SPATIAL INDEX posts_geom_index ON posts (`geom`)"
479
+ ]
480
+ end
481
+
482
+ specify "should support indexes with index type" do
483
+ g = Sequel::Schema::Generator.new(MYSQL_DB) do
484
+ text :title
485
+ index :title, :type => :hash
486
+ end
487
+ MYSQL_DB.create_table_sql_list(:posts, *g.create_info).should == [
488
+ "CREATE TABLE posts (`title` text)",
489
+ "CREATE INDEX posts_title_index ON posts (`title`) USING hash"
490
+ ]
491
+ end
492
+
493
+ specify "should support unique indexes with index type" do
494
+ g = Sequel::Schema::Generator.new(MYSQL_DB) do
495
+ text :title
496
+ index :title, :type => :hash, :unique => true
497
+ end
498
+ MYSQL_DB.create_table_sql_list(:posts, *g.create_info).should == [
499
+ "CREATE TABLE posts (`title` text)",
500
+ "CREATE UNIQUE INDEX posts_title_index ON posts (`title`) USING hash"
501
+ ]
502
+ end
516
503
  end
517
504
 
518
505
  class Sequel::MySQL::Database
@@ -548,6 +535,50 @@ class Sequel::MySQL::Database
548
535
  end
549
536
  end
550
537
 
538
+ context "MySQL::Dataset#insert" do
539
+ setup do
540
+ @d = MYSQL_DB[:items]
541
+ @d.delete # remove all records
542
+ MYSQL_DB.sqls.clear
543
+ end
544
+
545
+ specify "should insert record with default values when no arguments given" do
546
+ @d.insert
547
+
548
+ MYSQL_DB.sqls.should == [
549
+ "INSERT INTO items () VALUES ()"
550
+ ]
551
+
552
+ @d.all.should == [
553
+ {:name => nil, :value => nil}
554
+ ]
555
+ end
556
+
557
+ specify "should insert record with default values when empty hash given" do
558
+ @d.insert {}
559
+
560
+ MYSQL_DB.sqls.should == [
561
+ "INSERT INTO items () VALUES ()"
562
+ ]
563
+
564
+ @d.all.should == [
565
+ {:name => nil, :value => nil}
566
+ ]
567
+ end
568
+
569
+ specify "should insert record with default values when empty array given" do
570
+ @d.insert []
571
+
572
+ MYSQL_DB.sqls.should == [
573
+ "INSERT INTO items () VALUES ()"
574
+ ]
575
+
576
+ @d.all.should == [
577
+ {:name => nil, :value => nil}
578
+ ]
579
+ end
580
+ end
581
+
551
582
  context "MySQL::Dataset#multi_insert" do
552
583
  setup do
553
584
  @d = MYSQL_DB[:items]
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), '../../lib/sequel_core')
2
2
  require File.join(File.dirname(__FILE__), '../spec_helper.rb')
3
3
 
4
4
  unless defined?(ORACLE_DB)
5
- ORACLE_DB = Sequel('oracle://hr:hr@localhost/XE')
5
+ ORACLE_DB = Sequel.connect('oracle://hr:hr@localhost/XE')
6
6
  end
7
7
 
8
8
  if ORACLE_DB.table_exists?(:items)
@@ -221,59 +221,3 @@ context "Joined Oracle dataset" do
221
221
  ]
222
222
  end
223
223
  end
224
-
225
-
226
- context "An Oracle dataset in array tuples mode" do
227
- setup do
228
- @d = ORACLE_DB[:items]
229
- @d.delete # remove all records
230
- Sequel.use_array_tuples
231
- end
232
-
233
- teardown do
234
- Sequel.use_hash_tuples
235
- end
236
-
237
- specify "should return the correct records" do
238
- @d.to_a.should == []
239
- @d << {:name => 'abc', :value => 123}
240
- @d << {:name => 'abc', :value => 456}
241
- @d << {:name => 'def', :value => 789}
242
-
243
- @d.order(:value).select(:name, :value).to_a.should == [
244
- ['abc', 123],
245
- ['abc', 456],
246
- ['def', 789]
247
- ]
248
-
249
- @d.order(:value).select(:name, :value).limit(1).to_a.should == [
250
- ['abc',123]
251
- ]
252
-
253
- @d.order(:value).select(:name, :value).limit(2,1).to_a.should == [
254
- ['abc',456],
255
- ['def',789]
256
- ]
257
- end
258
-
259
- specify "should work correctly with transforms" do
260
- @d.transform(:value => [proc {|v| v.to_s}, proc {|v| v.to_i}])
261
-
262
- @d.to_a.should == []
263
- @d << {:name => 'abc', :value => 123}
264
- @d << {:name => 'abc', :value => 456}
265
- @d << {:name => 'def', :value => 789}
266
-
267
- @d.order(:value).select(:name, :value).to_a.should == [
268
- ['abc', '123'],
269
- ['abc', '456'],
270
- ['def', '789']
271
- ]
272
-
273
- a = @d.order(:value).first
274
- a.values.should == ['abc', '123']
275
- a.keys.should == [:name, :value]
276
- a[:name].should == 'abc'
277
- a[:value].should == '123'
278
- end
279
- end
@@ -2,11 +2,12 @@ require File.join(File.dirname(__FILE__), '../../lib/sequel_core')
2
2
  require File.join(File.dirname(__FILE__), '../spec_helper.rb')
3
3
 
4
4
  unless defined?(POSTGRES_DB)
5
- POSTGRES_DB = Sequel(ENV['SEQUEL_PG_SPEC_DB']||'postgres://postgres:postgres@localhost:5432/reality_spec')
5
+ POSTGRES_DB = Sequel.connect(ENV['SEQUEL_PG_SPEC_DB']||'postgres://postgres:postgres@localhost:5432/reality_spec')
6
6
  end
7
7
 
8
8
  POSTGRES_DB.drop_table(:test) if POSTGRES_DB.table_exists?(:test)
9
9
  POSTGRES_DB.drop_table(:test2) if POSTGRES_DB.table_exists?(:test2)
10
+ POSTGRES_DB.drop_table(:test3) if POSTGRES_DB.table_exists?(:test3)
10
11
 
11
12
  POSTGRES_DB.create_table :test do
12
13
  text :name
@@ -16,6 +17,10 @@ POSTGRES_DB.create_table :test2 do
16
17
  text :name
17
18
  integer :value
18
19
  end
20
+ POSTGRES_DB.create_table :test3 do
21
+ integer :value
22
+ timestamp :time
23
+ end
19
24
 
20
25
  context "A PostgreSQL database" do
21
26
  setup do
@@ -95,16 +100,16 @@ context "A PostgreSQL dataset" do
95
100
  @d.select('COUNT(*)'.lit).sql.should == \
96
101
  'SELECT COUNT(*) FROM test'
97
102
 
98
- @d.select(:value.MAX).sql.should == \
103
+ @d.select(:max[:value]).sql.should == \
99
104
  'SELECT max("value") FROM test'
100
105
 
101
106
  @d.select(:NOW[]).sql.should == \
102
107
  'SELECT NOW() FROM test'
103
108
 
104
- @d.select(:items__value.MAX).sql.should == \
109
+ @d.select(:max[:items__value]).sql.should == \
105
110
  'SELECT max(items."value") FROM test'
106
111
 
107
- @d.order(:name.DESC).sql.should == \
112
+ @d.order(:name.desc).sql.should == \
108
113
  'SELECT * FROM test ORDER BY "name" DESC'
109
114
 
110
115
  @d.select('test.name AS item_name'.lit).sql.should == \
@@ -136,13 +141,13 @@ context "A PostgreSQL dataset" do
136
141
  @d.reverse_order(:name).sql.should == \
137
142
  'SELECT * FROM test ORDER BY "name" DESC'
138
143
 
139
- @d.reverse_order(:name.DESC).sql.should == \
144
+ @d.reverse_order(:name.desc).sql.should == \
140
145
  'SELECT * FROM test ORDER BY "name"'
141
146
 
142
- @d.reverse_order(:name, :test.DESC).sql.should == \
147
+ @d.reverse_order(:name, :test.desc).sql.should == \
143
148
  'SELECT * FROM test ORDER BY "name" DESC, "test"'
144
149
 
145
- @d.reverse_order(:name.DESC, :test).sql.should == \
150
+ @d.reverse_order(:name.desc, :test).sql.should == \
146
151
  'SELECT * FROM test ORDER BY "name", "test" DESC'
147
152
  end
148
153
 
@@ -167,49 +172,17 @@ context "A PostgreSQL dataset" do
167
172
  end
168
173
  end
169
174
 
170
- context "A PostgreSQL dataset in array tuples mode" do
175
+ context "A PostgreSQL dataaset with a timestamp field" do
171
176
  setup do
172
- @d = POSTGRES_DB[:test]
173
- @d.delete # remove all records
174
- Sequel.use_array_tuples
175
- end
176
-
177
- teardown do
178
- Sequel.use_hash_tuples
179
- end
180
-
181
- specify "should return the correct records" do
182
- @d.to_a.should == []
183
- @d << {:name => 'abc', :value => 123}
184
- @d << {:name => 'abc', :value => 456}
185
- @d << {:name => 'def', :value => 789}
186
-
187
- @d.order(:value).select(:name, :value).to_a.should == [
188
- ['abc', 123],
189
- ['abc', 456],
190
- ['def', 789]
191
- ]
177
+ @d = POSTGRES_DB[:test3]
178
+ @d.delete
192
179
  end
193
-
194
- specify "should work correctly with transforms" do
195
- @d.transform(:value => [proc {|v| v.to_s}, proc {|v| v.to_i}])
196
-
197
- @d.to_a.should == []
198
- @d << {:name => 'abc', :value => 123}
199
- @d << {:name => 'abc', :value => 456}
200
- @d << {:name => 'def', :value => 789}
201
180
 
202
- @d.order(:value).select(:name, :value).to_a.should == [
203
- ['abc', '123'],
204
- ['abc', '456'],
205
- ['def', '789']
206
- ]
207
-
208
- a = @d.order(:value).first
209
- a.values.should == ['abc', '123']
210
- a.keys.should == [:name, :value]
211
- a[:name].should == 'abc'
212
- a[:value].should == '123'
181
+ specify "should store milliseconds in time fields" do
182
+ t = Time.now
183
+ @d << {:value=>1, :time=>t}
184
+ @d[:value =>'1'][:time].should == t
185
+ @d[:value=>'1'][:time].usec.should == t.usec
213
186
  end
214
187
  end
215
188
 
@@ -266,7 +239,7 @@ context "A PostgreSQL database" do
266
239
  end
267
240
  POSTGRES_DB.create_table_sql_list(:posts, *g.create_info).should == [
268
241
  "CREATE TABLE posts (\"title\" text, \"body\" text)",
269
- "CREATE INDEX posts_title_body_index ON posts USING gin(to_tsvector(\"title\" || \"body\"))"
242
+ "CREATE INDEX posts_title_body_index ON posts USING gin (to_tsvector(\"title\" || \"body\"))"
270
243
  ]
271
244
  end
272
245
 
@@ -278,7 +251,7 @@ context "A PostgreSQL database" do
278
251
  end
279
252
  POSTGRES_DB.create_table_sql_list(:posts, *g.create_info).should == [
280
253
  "CREATE TABLE posts (\"title\" text, \"body\" text)",
281
- "CREATE INDEX posts_title_body_index ON posts USING gin(to_tsvector('french', \"title\" || \"body\"))"
254
+ "CREATE INDEX posts_title_body_index ON posts USING gin (to_tsvector('french', \"title\" || \"body\"))"
282
255
  ]
283
256
  end
284
257
 
@@ -292,6 +265,50 @@ context "A PostgreSQL database" do
292
265
  POSTGRES_DB[:posts].full_text_search(:title, 'ruby', :language => 'french').sql.should ==
293
266
  "SELECT * FROM posts WHERE (to_tsvector('french', \"title\") @@ to_tsquery('french', 'ruby'))"
294
267
  end
268
+
269
+ specify "should support spatial indexes" do
270
+ g = Sequel::Schema::Generator.new(POSTGRES_DB) do
271
+ geometry :geom
272
+ spatial_index [:geom]
273
+ end
274
+ POSTGRES_DB.create_table_sql_list(:posts, *g.create_info).should == [
275
+ "CREATE TABLE posts (\"geom\" geometry)",
276
+ "CREATE INDEX posts_geom_index ON posts USING gist (\"geom\")"
277
+ ]
278
+ end
279
+
280
+ specify "should support indexes with index type" do
281
+ g = Sequel::Schema::Generator.new(POSTGRES_DB) do
282
+ varchar :title, :size => 5
283
+ index :title, :type => 'hash'
284
+ end
285
+ POSTGRES_DB.create_table_sql_list(:posts, *g.create_info).should == [
286
+ "CREATE TABLE posts (\"title\" varchar(5))",
287
+ "CREATE INDEX posts_title_index ON posts USING hash (\"title\")"
288
+ ]
289
+ end
290
+
291
+ specify "should support unique indexes with index type" do
292
+ g = Sequel::Schema::Generator.new(POSTGRES_DB) do
293
+ varchar :title, :size => 5
294
+ index :title, :type => 'hash', :unique => true
295
+ end
296
+ POSTGRES_DB.create_table_sql_list(:posts, *g.create_info).should == [
297
+ "CREATE TABLE posts (\"title\" varchar(5))",
298
+ "CREATE UNIQUE INDEX posts_title_index ON posts USING hash (\"title\")"
299
+ ]
300
+ end
301
+
302
+ specify "should support partial indexes" do
303
+ g = Sequel::Schema::Generator.new(POSTGRES_DB) do
304
+ varchar :title, :size => 5
305
+ index :title, :where => {:something => 5}
306
+ end
307
+ POSTGRES_DB.create_table_sql_list(:posts, *g.create_info).should == [
308
+ "CREATE TABLE posts (\"title\" varchar(5))",
309
+ "CREATE INDEX posts_title_index ON posts (\"title\") WHERE (\"something\" = 5)"
310
+ ]
311
+ end
295
312
  end
296
313
 
297
314
  context "Postgres::Dataset#multi_insert_sql / #import" do