sequel 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,15 @@
1
+ *0.0.16*
2
+
3
+ * Added support for subqueries in Dataset#literal.
4
+
5
+ * Added support for Model.all_by_XXX methods through Model.method_missing.
6
+
7
+ * Added basic SQL logging to Database.
8
+
9
+ * Added Enumerable#send_each convenience method.
10
+
11
+ * Changed Dataset#destroy to return the number of deleted records.
12
+
1
13
  *0.0.15*
2
14
 
3
15
  * Improved Dataset#insert_sql to allow arrays as well as hashes.
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require 'fileutils'
6
6
  include FileUtils
7
7
 
8
8
  NAME = "sequel"
9
- VERS = "0.0.15"
9
+ VERS = "0.0.16"
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",
@@ -7,3 +7,10 @@ class Time
7
7
  strftime(SQL_FORMAT)
8
8
  end
9
9
  end
10
+
11
+ # Enumerable extensions.
12
+ module Enumerable
13
+ def send_each(sym, *args)
14
+ each {|i| i.send(sym, *args)}
15
+ end
16
+ end
@@ -17,6 +17,7 @@ module Sequel
17
17
  def initialize(opts = {})
18
18
  @opts = opts
19
19
  @pool = ConnectionPool.new(@opts[:max_connections] || 4)
20
+ @logger = opts[:logger]
20
21
  end
21
22
 
22
23
  # Returns a blank dataset
@@ -104,6 +104,7 @@ module Sequel
104
104
  end
105
105
 
106
106
  NULL = "NULL".freeze
107
+ SUBQUERY = "(%s)".freeze
107
108
 
108
109
  # Returns a literal representation of a value to be used as part
109
110
  # of an SQL expression. This method is overriden in descendants.
@@ -114,6 +115,7 @@ module Sequel
114
115
  when NilClass: NULL
115
116
  when Symbol: v.to_field_name
116
117
  when Array: v.empty? ? NULL : v.map {|i| literal(i)}.join(COMMA_SEPARATOR)
118
+ when self.class: SUBQUERY % v.sql
117
119
  else
118
120
  raise "can't express #{v.inspect}:#{v.class} as a SQL literal"
119
121
  end
@@ -421,7 +423,9 @@ module Sequel
421
423
  def destroy
422
424
  raise 'Dataset not associated with model' unless @record_class
423
425
 
424
- @db.transaction {each {|r| r.destroy}}
426
+ count = 0
427
+ @db.transaction {each {|r| count += 1; r.destroy}}
428
+ count
425
429
  end
426
430
 
427
431
  def print(*columns)
data/lib/sequel/model.rb CHANGED
@@ -202,6 +202,7 @@ module Sequel
202
202
 
203
203
  FIND_BY_REGEXP = /^find_by_(.*)/.freeze
204
204
  FILTER_BY_REGEXP = /^filter_by_(.*)/.freeze
205
+ ALL_BY_REGEXP = /^all_by_(.*)/.freeze
205
206
 
206
207
  def self.method_missing(m, *args)
207
208
  Thread.exclusive do
@@ -209,13 +210,15 @@ module Sequel
209
210
  if method_name =~ FIND_BY_REGEXP
210
211
  c = $1
211
212
  meta_def(method_name) {|arg| find(c => arg)}
212
- send(m, *args) if respond_to?(m)
213
213
  elsif method_name =~ FILTER_BY_REGEXP
214
214
  c = $1
215
215
  meta_def(method_name) {|arg| filter(c => arg)}
216
- send(m, *args) if respond_to?(m)
216
+ elsif method_name =~ ALL_BY_REGEXP
217
+ c = $1
218
+ meta_def(method_name) {|arg| filter(c => arg).all}
217
219
  end
218
220
  end
221
+ respond_to?(m) ? send(m, *args) : super(m, *args)
219
222
  end
220
223
 
221
224
  def db; self.class.db; end
data/lib/sequel/mysql.rb CHANGED
@@ -23,12 +23,14 @@ module Sequel
23
23
  end
24
24
 
25
25
  def execute(sql)
26
+ @logger.info(sql) if @logger
26
27
  @pool.hold do |conn|
27
28
  conn.query(sql)
28
29
  end
29
30
  end
30
31
 
31
32
  def execute_insert(sql)
33
+ @logger.info(sql) if @logger
32
34
  @pool.hold do |conn|
33
35
  conn.query(sql)
34
36
  conn.insert_id
@@ -36,6 +38,7 @@ module Sequel
36
38
  end
37
39
 
38
40
  def execute_affected(sql)
41
+ @logger.info(sql) if @logger
39
42
  @pool.hold do |conn|
40
43
  conn.query(sql)
41
44
  conn.affected_rows
@@ -188,14 +188,17 @@ module Sequel
188
188
  end
189
189
 
190
190
  def execute(sql)
191
+ @logger.info(sql) if @logger
191
192
  @pool.hold {|conn| conn.execute(sql)}
192
193
  end
193
194
 
194
195
  def execute_and_forget(sql)
196
+ @logger.info(sql) if @logger
195
197
  @pool.hold {|conn| conn.execute(sql).clear}
196
198
  end
197
199
 
198
200
  def execute_insert(sql, table)
201
+ @logger.info(sql) if @logger
199
202
  @pool.hold do |conn|
200
203
  conn.execute(sql).clear
201
204
  conn.last_insert_id(table)
data/lib/sequel/sqlite.rb CHANGED
@@ -30,10 +30,12 @@ module Sequel
30
30
  end
31
31
 
32
32
  def execute(sql)
33
+ @logger.info(sql) if @logger
33
34
  @pool.hold {|conn| conn.execute(sql)}
34
35
  end
35
36
 
36
37
  def execute_insert(sql)
38
+ @logger.info(sql) if @logger
37
39
  @pool.hold {|conn| conn.execute(sql); conn.last_insert_row_id}
38
40
  end
39
41
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: sequel
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.15
7
- date: 2007-03-30 00:00:00 +02:00
6
+ version: 0.0.16
7
+ date: 2007-04-08 00:00:00 +03:00
8
8
  summary: Concise ORM for Ruby.
9
9
  require_paths:
10
10
  - lib