sequel 0.4.1.2 → 0.4.1.3
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.
- data/CHANGELOG +11 -1
- data/COPYING +1 -1
- data/README +1 -1
- data/Rakefile +8 -1
- data/lib/sequel.rb +1 -2
- data/lib/sequel/adapters/openbase.rb +93 -0
- data/lib/sequel/adapters/oracle.rb +1 -8
- data/lib/sequel/database.rb +24 -9
- data/lib/sequel/model/plugins.rb +16 -1
- data/spec/database_spec.rb +10 -0
- data/spec/model_spec.rb +13 -0
- metadata +3 -2
data/CHANGELOG
CHANGED
@@ -1,4 +1,14 @@
|
|
1
|
-
|
1
|
+
=== SVN
|
2
|
+
|
3
|
+
* Better plugin conventions.
|
4
|
+
|
5
|
+
* Added experimental OpenBase adapter.
|
6
|
+
|
7
|
+
* Fixed Sequel.<xxx> methods to accept options hash as well as database name. Fixed Sequel.connect to accept options hash as well as URI (Wayne).
|
8
|
+
|
9
|
+
=== 0.4.1.2 (2007-12-04)
|
10
|
+
|
11
|
+
* Added release rake task (using RubyForge).
|
2
12
|
|
3
13
|
* Changed Model.is to accept variable arity.
|
4
14
|
|
data/COPYING
CHANGED
data/README
CHANGED
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ require 'fileutils'
|
|
6
6
|
include FileUtils
|
7
7
|
|
8
8
|
NAME = "sequel"
|
9
|
-
VERS = "0.4.1.
|
9
|
+
VERS = "0.4.1.3"
|
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",
|
@@ -104,6 +104,13 @@ task :uninstall => [:clean] do
|
|
104
104
|
sh %{sudo gem uninstall #{NAME}}
|
105
105
|
end
|
106
106
|
|
107
|
+
task :release => [:package] do
|
108
|
+
sh %{rubyforge login}
|
109
|
+
sh %{rubyforge add_release sequel sequel #{VERS} pkg/sequel-#{VERS}.tgz}
|
110
|
+
sh %{rubyforge add_file sequel sequel #{VERS} pkg/sequel-#{VERS}.gem}
|
111
|
+
sh %{rubyforge add_file sequel sequel #{VERS} pkg/sequel-#{VERS}-x86-mswin32-60.gem}
|
112
|
+
end
|
113
|
+
|
107
114
|
desc 'Update docs and upload to rubyforge.org'
|
108
115
|
task :doc_rforge do
|
109
116
|
sh %{rake doc}
|
data/lib/sequel.rb
CHANGED
@@ -23,7 +23,6 @@ module Sequel #:nodoc:
|
|
23
23
|
def connect(*args)
|
24
24
|
Database.connect(*args)
|
25
25
|
end
|
26
|
-
|
27
26
|
alias_method :open, :connect
|
28
27
|
|
29
28
|
def single_threaded=(value)
|
@@ -35,7 +34,7 @@ module Sequel #:nodoc:
|
|
35
34
|
begin
|
36
35
|
case args.size
|
37
36
|
when 1: # Sequel.dbi(db_name)
|
38
|
-
opts = {:database => args[0]}
|
37
|
+
opts = args[0].is_a?(Hash) ? args[0] : {:database => args[0]}
|
39
38
|
when 0 # Sequel.dbi
|
40
39
|
opts = {}
|
41
40
|
else # Sequel.dbi(db_name, opts)
|
@@ -0,0 +1,93 @@
|
|
1
|
+
if !Object.const_defined?('Sequel')
|
2
|
+
require File.join(File.dirname(__FILE__), '../../sequel')
|
3
|
+
end
|
4
|
+
|
5
|
+
require 'openbase'
|
6
|
+
|
7
|
+
module Sequel
|
8
|
+
module OpenBase
|
9
|
+
class Database < Sequel::Database
|
10
|
+
set_adapter_scheme :openbase
|
11
|
+
|
12
|
+
def connect
|
13
|
+
OpenBase.new(
|
14
|
+
opts[:database],
|
15
|
+
opts[:host] || 'localhost',
|
16
|
+
opts[:user],
|
17
|
+
opts[:password]
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
def disconnect
|
22
|
+
# would this work?
|
23
|
+
@pool.disconnect {|c| c.disconnect}
|
24
|
+
end
|
25
|
+
|
26
|
+
def dataset(opts = nil)
|
27
|
+
OpenBase::Dataset.new(self, opts)
|
28
|
+
end
|
29
|
+
|
30
|
+
def execute(sql)
|
31
|
+
@logger.info(sql) if @logger
|
32
|
+
@pool.hold {|conn| conn.execute(sql)}
|
33
|
+
end
|
34
|
+
|
35
|
+
alias_method :do, :execute
|
36
|
+
end
|
37
|
+
|
38
|
+
class Dataset < Sequel::Dataset
|
39
|
+
def literal(v)
|
40
|
+
case v
|
41
|
+
when Time: literal(v.iso8601)
|
42
|
+
else
|
43
|
+
super
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def fetch_rows(sql, &block)
|
48
|
+
@db.synchronize do
|
49
|
+
result = @db.execute sql
|
50
|
+
begin
|
51
|
+
@columns = result.column_infos.map {|c| c.name.to_sym}
|
52
|
+
result.each do |r|
|
53
|
+
row = {}
|
54
|
+
r.each_with_index {|v, i| row[@columns[i]] = v}
|
55
|
+
yield row
|
56
|
+
end
|
57
|
+
ensure
|
58
|
+
# result.close
|
59
|
+
end
|
60
|
+
end
|
61
|
+
self
|
62
|
+
end
|
63
|
+
|
64
|
+
def array_tuples_fetch_rows(sql, &block)
|
65
|
+
@db.synchronize do
|
66
|
+
result = @db.execute sql
|
67
|
+
begin
|
68
|
+
@columns = result.column_infos.map {|c| c.name.to_sym}
|
69
|
+
result.each do |r|
|
70
|
+
r.keys = @columns
|
71
|
+
yield r
|
72
|
+
end
|
73
|
+
ensure
|
74
|
+
# cursor.close
|
75
|
+
end
|
76
|
+
end
|
77
|
+
self
|
78
|
+
end
|
79
|
+
|
80
|
+
def insert(*values)
|
81
|
+
@db.do insert_sql(*values)
|
82
|
+
end
|
83
|
+
|
84
|
+
def update(values, opts = nil)
|
85
|
+
@db.do update_sql(values, opts)
|
86
|
+
end
|
87
|
+
|
88
|
+
def delete(opts = nil)
|
89
|
+
@db.do delete_sql(opts)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -60,7 +60,7 @@ module Sequel
|
|
60
60
|
@columns = cursor.get_col_names.map {|c| c.to_sym}
|
61
61
|
while r = cursor.fetch
|
62
62
|
row = {}
|
63
|
-
r.each_with_index {|v, i| row[columns[i]] = v}
|
63
|
+
r.each_with_index {|v, i| row[@columns[i]] = v}
|
64
64
|
yield row
|
65
65
|
end
|
66
66
|
ensure
|
@@ -70,13 +70,6 @@ module Sequel
|
|
70
70
|
self
|
71
71
|
end
|
72
72
|
|
73
|
-
def hash_row(row)
|
74
|
-
@columns.inject({}) do |m, c|
|
75
|
-
m[c] = row.shift
|
76
|
-
m
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
73
|
def array_tuples_fetch_rows(sql, &block)
|
81
74
|
@db.synchronize do
|
82
75
|
cursor = @db.execute sql
|
data/lib/sequel/database.rb
CHANGED
@@ -268,19 +268,34 @@ module Sequel
|
|
268
268
|
|
269
269
|
# call-seq:
|
270
270
|
# Sequel::Database.connect(conn_string)
|
271
|
+
# Sequel::Database.connect(opts)
|
271
272
|
# Sequel.connect(conn_string)
|
273
|
+
# Sequel.connect(opts)
|
272
274
|
# Sequel.open(conn_string)
|
275
|
+
# Sequel.open(opts)
|
276
|
+
#
|
277
|
+
# Creates a new database object based on the supplied connection string
|
278
|
+
# and or options. If a URI is used, the URI scheme determines the database
|
279
|
+
# class used, and the rest of the string specifies the connection options.
|
280
|
+
# For example:
|
273
281
|
#
|
274
|
-
# Creates a new database object based on the supplied connection string.
|
275
|
-
# The specified scheme determines the database class used, and the rest
|
276
|
-
# of the string specifies the connection options. For example:
|
277
282
|
# DB = Sequel.open 'sqlite:///blog.db'
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
283
|
+
#
|
284
|
+
# The second form of this method takes an options:
|
285
|
+
#
|
286
|
+
# DB = Sequel.open :adapter => :sqlite, :database => 'blog.db'
|
287
|
+
def self.connect(conn_string, opts = nil)
|
288
|
+
if conn_string.is_a?(String)
|
289
|
+
uri = URI.parse(conn_string)
|
290
|
+
scheme = uri.scheme
|
291
|
+
scheme = :dbi if scheme =~ /^dbi-(.+)/
|
292
|
+
c = adapter_class(scheme)
|
293
|
+
c.new(c.uri_to_options(uri).merge(opts || {}))
|
294
|
+
else
|
295
|
+
opts = conn_string.merge(opts || {})
|
296
|
+
c = adapter_class(opts[:adapter])
|
297
|
+
c.new(opts)
|
298
|
+
end
|
284
299
|
end
|
285
300
|
|
286
301
|
@@single_threaded = false
|
data/lib/sequel/model/plugins.rb
CHANGED
@@ -6,7 +6,22 @@ module Sequel
|
|
6
6
|
# Loads a plugin for use with the model class, passing optional arguments
|
7
7
|
# to the plugin.
|
8
8
|
def is(plugin, *args)
|
9
|
-
plugin_module(plugin)
|
9
|
+
m = plugin_module(plugin)
|
10
|
+
if m.respond_to?(:apply)
|
11
|
+
m.apply(self, *args)
|
12
|
+
end
|
13
|
+
if m.const_defined?("InstanceMethods")
|
14
|
+
class_def(:"#{plugin}_opts") {args.first}
|
15
|
+
include(m::InstanceMethods)
|
16
|
+
end
|
17
|
+
if m.const_defined?("ClassMethods")
|
18
|
+
meta_def(:"#{plugin}_opts") {args.first}
|
19
|
+
metaclass.send(:include, m::ClassMethods)
|
20
|
+
end
|
21
|
+
if m.const_defined?("DatasetMethods")
|
22
|
+
dataset.meta_def(:"#{plugin}_opts") {args.first}
|
23
|
+
dataset.metaclass.send(:include, m::DatasetMethods)
|
24
|
+
end
|
10
25
|
end
|
11
26
|
alias_method :is_a, :is
|
12
27
|
|
data/spec/database_spec.rb
CHANGED
@@ -390,6 +390,16 @@ context "A Database adapter with a scheme" do
|
|
390
390
|
c = Sequel.ccc
|
391
391
|
c.should be_a_kind_of(CCC)
|
392
392
|
c.opts.should == {}
|
393
|
+
|
394
|
+
c = Sequel.ccc(:database => 'mydb', :host => 'localhost')
|
395
|
+
c.should be_a_kind_of(CCC)
|
396
|
+
c.opts.should == {:database => 'mydb', :host => 'localhost'}
|
397
|
+
end
|
398
|
+
|
399
|
+
specify "should be accessible through Sequel.connect with options" do
|
400
|
+
c = Sequel.connect(:adapter => :ccc, :database => 'mydb')
|
401
|
+
c.should be_a_kind_of(CCC)
|
402
|
+
c.opts.should == {:adapter => :ccc, :database => 'mydb'}
|
393
403
|
end
|
394
404
|
end
|
395
405
|
|
data/spec/model_spec.rb
CHANGED
@@ -1048,6 +1048,14 @@ module Sequel::Plugins
|
|
1048
1048
|
m.meta_def(:stamp_opts) {opts}
|
1049
1049
|
m.before_save {@values[:stamp] = Time.now}
|
1050
1050
|
end
|
1051
|
+
|
1052
|
+
module InstanceMethods
|
1053
|
+
def abc; timestamped_opts; end
|
1054
|
+
end
|
1055
|
+
|
1056
|
+
module ClassMethods
|
1057
|
+
def deff; timestamped_opts; end
|
1058
|
+
end
|
1051
1059
|
end
|
1052
1060
|
end
|
1053
1061
|
|
@@ -1073,8 +1081,13 @@ context "A model using a plugin" do
|
|
1073
1081
|
|
1074
1082
|
m = c.new
|
1075
1083
|
m.should respond_to(:get_stamp)
|
1084
|
+
m.should respond_to(:abc)
|
1085
|
+
m.abc.should == {:a => 1, :b => 2}
|
1076
1086
|
t = Time.now
|
1077
1087
|
m[:stamp] = t
|
1078
1088
|
m.get_stamp.should == t
|
1089
|
+
|
1090
|
+
c.should respond_to(:deff)
|
1091
|
+
c.deff.should == {:a => 1, :b => 2}
|
1079
1092
|
end
|
1080
1093
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.1.
|
4
|
+
version: 0.4.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2007-12-
|
12
|
+
date: 2007-12-05 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- lib/sequel/adapters/mysql.rb
|
84
84
|
- lib/sequel/adapters/odbc.rb
|
85
85
|
- lib/sequel/adapters/odbc_mssql.rb
|
86
|
+
- lib/sequel/adapters/openbase.rb
|
86
87
|
- lib/sequel/adapters/oracle.rb
|
87
88
|
- lib/sequel/adapters/postgres.rb
|
88
89
|
- lib/sequel/adapters/sqlite.rb
|