sequel 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/CHANGELOG +4 -0
  2. data/Rakefile +1 -1
  3. data/lib/sequel/dataset.rb +38 -22
  4. metadata +2 -2
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ *0.1.5*
2
+
3
+ * Fixed Dataset#join to support multiple joins. Added #left_outer_join, #right_outer_join, #full_outer_join, #inner_join methods.
4
+
1
5
  *0.1.4*
2
6
 
3
7
  * Added String#split_sql.
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require 'fileutils'
6
6
  include FileUtils
7
7
 
8
8
  NAME = "sequel"
9
- VERS = "0.1.4"
9
+ VERS = "0.1.5"
10
10
  CLEAN.include ['**/.*.sw?', 'pkg/*', '.config', 'doc/*', 'coverage/*']
11
11
  RDOC_OPTS = ['--quiet', '--title', "Sequel: Concise ORM for Ruby",
12
12
  "--opname", "index.html",
@@ -213,15 +213,6 @@ module Sequel
213
213
  parenthesize ? "(#{fmt})" : fmt
214
214
  end
215
215
 
216
- # Formats a join condition.
217
- def join_cond_list(cond, join_table)
218
- cond.map do |kv|
219
- l = qualified_field_name(kv[0], join_table)
220
- r = qualified_field_name(kv[1], @opts[:from])
221
- "(#{l} = #{r})"
222
- end.join(AND_SEPARATOR)
223
- end
224
-
225
216
  # Returns a copy of the dataset with the source changed.
226
217
  def from(*source)
227
218
  dup_merge(:from => source)
@@ -358,17 +349,44 @@ module Sequel
358
349
  dup_merge(:except => dataset, :except_all => all)
359
350
  end
360
351
 
361
- LEFT_OUTER_JOIN = 'LEFT OUTER JOIN'.freeze
362
- INNER_JOIN = 'INNER JOIN'.freeze
363
- RIGHT_OUTER_JOIN = 'RIGHT OUTER JOIN'.freeze
364
- FULL_OUTER_JOIN = 'FULL OUTER JOIN'.freeze
352
+ JOIN_TYPES = {
353
+ :left_outer => 'LEFT OUTER JOIN'.freeze,
354
+ :right_outer => 'RIGHT OUTER JOIN'.freeze,
355
+ :full_outer => 'FULL OUTER JOIN'.freeze,
356
+ :inner => 'INNER JOIN'.freeze
357
+ }
358
+
359
+ def join_expr(type, table, expr)
360
+ join_type = JOIN_TYPES[type || :left_outer]
361
+ unless join_type
362
+ raise SequelError, "Invalid join type: #{type}"
363
+ end
364
+
365
+ join_expr = expr.map do |k, v|
366
+ l = qualified_field_name(k, table)
367
+ r = qualified_field_name(v, @opts[:last_joined_table] || @opts[:from])
368
+ "(#{l} = #{r})"
369
+ end.join(AND_SEPARATOR)
370
+
371
+ " #{join_type} #{table} ON #{join_expr}"
372
+ end
365
373
 
366
374
  # Returns a joined dataset.
367
- def join(table, expr)
368
- expr = {expr => :id} unless expr.is_a?(Hash)
369
- dup_merge(:join_type => LEFT_OUTER_JOIN, :join_table => table,
370
- :join_cond => expr)
375
+ def join_table(type, table, expr)
376
+ unless expr.is_a?(Hash)
377
+ expr = {expr => :id}
378
+ end
379
+ clause = join_expr(type, table, expr)
380
+ join = @opts[:join] ? @opts[:join] + clause : clause
381
+ dup_merge(:join => join, :last_joined_table => table)
371
382
  end
383
+
384
+ def left_outer_join(table, expr); join_table(:left_outer, table, expr); end
385
+ alias_method :join, :left_outer_join
386
+ def right_outer_join(table, expr); join_table(:right_outer, table, expr); end
387
+ def full_outer_join(table, expr); join_table(:full_outer, table, expr); end
388
+ def inner_join(table, expr); join_table(:inner, table, expr); end
389
+
372
390
 
373
391
  alias all to_a
374
392
 
@@ -420,10 +438,8 @@ module Sequel
420
438
  "SELECT DISTINCT #{select_fields} FROM #{select_source}" : \
421
439
  "SELECT #{select_fields} FROM #{select_source}"
422
440
 
423
- if join_type = opts[:join_type]
424
- join_table = opts[:join_table]
425
- join_cond = join_cond_list(opts[:join_cond], join_table)
426
- sql << " #{join_type} #{join_table} ON #{join_cond}"
441
+ if join = opts[:join]
442
+ sql << join
427
443
  end
428
444
 
429
445
  if where = opts[:where]
@@ -499,7 +515,7 @@ module Sequel
499
515
 
500
516
  if opts[:group]
501
517
  raise SequelError, "Can't update a grouped dataset"
502
- elsif (opts[:from].size > 1) or opts[:join_type]
518
+ elsif (opts[:from].size > 1) or opts[:join]
503
519
  raise SequelError, "Can't update a joined dataset"
504
520
  end
505
521
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: sequel
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.4
7
- date: 2007-05-25 00:00:00 +03:00
6
+ version: 0.1.5
7
+ date: 2007-05-26 00:00:00 +03:00
8
8
  summary: Concise ORM for Ruby.
9
9
  require_paths:
10
10
  - lib