sequel_oracle_extensions 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/lib/sequel/oracle_extensions/schemata.rb +90 -46
- data/sequel_oracle_extensions.gemspec +23 -31
- metadata +19 -15
- data/.gitignore +0 -21
data/Rakefile
CHANGED
@@ -11,7 +11,7 @@ begin
|
|
11
11
|
gem.homepage = "http://github.com/joekhoobyar/sequel_oracle_extensions"
|
12
12
|
gem.authors = ["Joe Khoobyar"]
|
13
13
|
gem.add_dependency "sequel", ">= 3.10.0"
|
14
|
-
gem.add_development_dependency "rspec", ">= 2.0.0
|
14
|
+
gem.add_development_dependency "rspec", ">= 2.0.0"
|
15
15
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
16
|
end
|
17
17
|
Jeweler::GemcutterTasks.new
|
@@ -20,10 +20,10 @@ rescue LoadError
|
|
20
20
|
end
|
21
21
|
|
22
22
|
require 'rspec/core/rake_task'
|
23
|
-
|
23
|
+
RSpec::Core::RakeTask.new(:rspec) do |spec|
|
24
24
|
spec.pattern = FileList['spec/**/*_spec.rb']
|
25
25
|
end
|
26
|
-
|
26
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
27
27
|
spec.pattern = 'spec/**/*_spec.rb'
|
28
28
|
spec.rcov = true
|
29
29
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.2
|
@@ -9,27 +9,28 @@ module Sequel
|
|
9
9
|
SELECT_INDEXES_SQL = %q{
|
10
10
|
SELECT i.index_name, i.status, i.uniqueness, ic.column_name
|
11
11
|
FROM all_indexes i
|
12
|
-
INNER JOIN all_ind_columns ic
|
13
|
-
|
14
|
-
|
15
|
-
WHERE uc.index_name = i.index_name AND uc.owner = i.owner AND uc.constraint_type = 'P'
|
16
|
-
)
|
12
|
+
INNER JOIN all_ind_columns ic
|
13
|
+
ON ic.index_owner = i.owner AND ic.index_name = i.index_name
|
14
|
+
WHERE i.table_name = ? AND i.dropped = 'NO'
|
17
15
|
ORDER BY status DESC, index_name, ic.column_position
|
18
16
|
}.freeze
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
ORDER BY status DESC, constraint_name, cc.position
|
26
|
-
}.freeze
|
27
|
-
|
28
|
-
# Returns the indexes for the given table, excluding any primary keys.
|
29
|
-
def indexes(table)
|
30
|
-
m = output_identifier_meth
|
18
|
+
# Returns the indexes for the given table. By default, it does not return primary keys.
|
19
|
+
#
|
20
|
+
# * <tt>:all</tt> - Returns all indexes, even primary keys.
|
21
|
+
def indexes(table, options={})
|
22
|
+
sql, m = SELECT_INDEXES_SQL, output_identifier_meth
|
31
23
|
table = m[table]
|
32
24
|
ixs = Hash.new{|h,k| h[k] = {:table_name=>table, :columns=>[]}}
|
25
|
+
|
26
|
+
if options[:all]
|
27
|
+
sql = sql.sub /ORDER BY /, %q{ AND NOT EXISTS (
|
28
|
+
SELECT uc.index_name FROM all_constraints uc
|
29
|
+
WHERE uc.index_name = i.index_name AND uc.owner = i.owner AND uc.constraint_type = 'P'
|
30
|
+
)
|
31
|
+
ORDER BY }
|
32
|
+
end
|
33
|
+
|
33
34
|
metadata_dataset.with_sql(SELECT_INDEXES_SQL, table.to_s.upcase).each do |r|
|
34
35
|
r = Hash[ r.map{|k,v| [k, (k==:index_name || k==:column_name) ? m[v] : v]} ]
|
35
36
|
ix = ixs[m.call r.delete(:index_name)]
|
@@ -40,40 +41,83 @@ ORDER BY status DESC, constraint_name, cc.position
|
|
40
41
|
end
|
41
42
|
ixs
|
42
43
|
end
|
43
|
-
|
44
|
-
# Returns the primary key for the given table, as a hash.
|
44
|
+
|
45
|
+
# Returns the primary key for the given +table+ (or +schema.table+), as a hash.
|
45
46
|
#
|
46
47
|
# * <tt>:enabled</tt> - Only look for keys that are enabled (true) or disabled (false). By default (nil),
|
47
|
-
# looks for
|
48
|
-
# * <tt>:all</tt>
|
49
|
-
#
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
sql = sql.sub /WHERE /, "WHERE c.status = #{z ? 'ENABLED' : 'DISABLED'}"
|
58
|
-
end
|
59
|
-
|
60
|
-
metadata_dataset.with_sql(sql, table.to_s.upcase).each do |r|
|
61
|
-
if options[:first] && pks.length==1 && r[:constraint_name] != pks[:constraint_name]
|
62
|
-
return pks.first
|
63
|
-
end
|
64
|
-
|
65
|
-
r = Hash[ r.map{|k,v| [k, (k==:status || v.nil? || v=='') ? v : m[v]]} ]
|
66
|
-
pk = pkh[m.call r[:constraint_name]]
|
67
|
-
pk[:enabled] = r.delete(:status)=='ENABLED'
|
68
|
-
pk[:columns] << r.delete(:column_name)
|
69
|
-
pk.update r
|
70
|
-
end
|
48
|
+
# looks for any matching key.
|
49
|
+
# * <tt>:all</tt> - Return an array of matching keys, instead of the first matching key.
|
50
|
+
#
|
51
|
+
def primary_key(qualified_table, options={})
|
52
|
+
result = table_constraints(qualified_table, options) do |ds,table_name,x_cons|
|
53
|
+
ds.where(:c__constraint_type=>'P', :c__table_name=>table_name).
|
54
|
+
order(:status.desc, :index_name, :cc__position)
|
55
|
+
end
|
56
|
+
options[:all] ? result : result.first
|
57
|
+
end
|
71
58
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
59
|
+
# Returns the foreign keys defined on the given +table+ (or +schema.table+), as an array of hashes.
|
60
|
+
#
|
61
|
+
# * <tt>:enabled</tt> - Only look for keys that are enabled (true) or disabled (false). By default (nil),
|
62
|
+
# looks for all matching keys.
|
63
|
+
def foreign_keys(qualified_table, options={})
|
64
|
+
table_constraints(qualified_table, options) do |ds,table_name,x_cons|
|
65
|
+
ds.where(:c__constraint_type=>'R', :c__table_name=>table_name).
|
66
|
+
order(:table_name, :constraint_name, :cc__position)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Returns foreign keys that refer to the given +table+ (or +schema.table+), as an array of hashes.
|
71
|
+
#
|
72
|
+
# * <tt>:enabled</tt> - Only look for keys that are enabled (true) or disabled (false). By default (nil),
|
73
|
+
# looks for all matching keys.
|
74
|
+
def references(qualified_table, options={})
|
75
|
+
table_constraints(qualified_table, options) do |ds,table_name,x_cons|
|
76
|
+
ds.join(:"#{x_cons}traints___t", [[:owner,:c__r_owner], [:constraint_name,:c__r_constraint_name]]).
|
77
|
+
where(:c__constraint_type=>'R', :t__constraint_type=>'P', :t__table_name=>table_name).
|
78
|
+
order(:table_name, :constraint_name, :cc__position)
|
79
|
+
end
|
76
80
|
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
# Internal helper method for introspection of table constraints.
|
85
|
+
def table_constraints(qualified_table,options={})
|
86
|
+
ds, result = metadata_dataset, []
|
87
|
+
schema, table = ds.schema_and_table(qualified_table)
|
88
|
+
x_cons = schema.nil? ? 'user_cons' : 'all_cons'
|
89
|
+
inm = ds.identifier_input_method
|
90
|
+
|
91
|
+
# Build the dataset and apply filters for introspection of constraints.
|
92
|
+
# Also allows the caller to customize the dataset.
|
93
|
+
ds = ds.select(:c__constraint_name, :c__table_name, :c__rely, :c__status, :c__validated,
|
94
|
+
:cc__column_name, :c__index_name, :c__constraint_type).
|
95
|
+
from(:"#{x_cons}traints___c").
|
96
|
+
join(:"#{x_cons}_columns___cc", [[:owner,:owner], [:constraint_name,:constraint_name]])
|
97
|
+
unless schema.nil?
|
98
|
+
ds = ds.where :c__owner => schema.to_s.send(inm)
|
99
|
+
end
|
100
|
+
unless (z = options[:enabled]).nil?
|
101
|
+
ds = ds.where :status => (z ? 'ENABLED' : 'DISABLED')
|
102
|
+
end
|
103
|
+
ds = yield ds, table.to_s.send(inm), x_cons
|
104
|
+
|
105
|
+
# Return the table constraints as an array of hashes, including a column list.
|
106
|
+
hash = Hash.new do |h,k|
|
107
|
+
result.push :constraint_name=>ds.send(:output_identifier,k), :columns=>[]
|
108
|
+
h[k] = result.last
|
109
|
+
end
|
110
|
+
ds.each do |row|
|
111
|
+
ref = hash[row[:constraint_name]]
|
112
|
+
ref[:table_name]||= ds.send(:output_identifier,row.delete(:table_name))
|
113
|
+
ref[:columns] << ds.send(:output_identifier,row.delete(:column_name))
|
114
|
+
ref[:rely] ||= row.delete(:rely)=='RELY'
|
115
|
+
ref[:enabled] ||= row.delete(:status)=='ENABLED'
|
116
|
+
ref[:validated] ||= row.delete(:validated)=='VALIDATED'
|
117
|
+
ref[:index_name]||= ds.send(:output_identifier,row.delete(:index_name)) if row[:index_name]
|
118
|
+
end
|
119
|
+
result
|
120
|
+
end
|
77
121
|
end
|
78
122
|
end
|
79
123
|
end
|
@@ -1,64 +1,56 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sequel_oracle_extensions}
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Joe Khoobyar"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-08-16}
|
13
13
|
s.description = %q{Oracle extensions for Sequel, including MERGE statements, optimizer hints, and schema extensions.}
|
14
14
|
s.email = %q{joe@ankhcraft.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
|
17
|
+
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
"spec/spec_helper.rb"
|
21
|
+
".rspec",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/sequel/oracle_extensions.rb",
|
27
|
+
"lib/sequel/oracle_extensions/hints.rb",
|
28
|
+
"lib/sequel/oracle_extensions/merge.rb",
|
29
|
+
"lib/sequel/oracle_extensions/schemata.rb",
|
30
|
+
"lib/sequel_oracle_extensions.rb",
|
31
|
+
"sequel_oracle_extensions.gemspec",
|
32
|
+
"spec/sequel/oracle_extensions/hints_spec.rb",
|
33
|
+
"spec/sequel/oracle_extensions/merge_spec.rb",
|
34
|
+
"spec/spec_helper.rb"
|
36
35
|
]
|
37
36
|
s.homepage = %q{http://github.com/joekhoobyar/sequel_oracle_extensions}
|
38
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
39
37
|
s.require_paths = ["lib"]
|
40
|
-
s.rubygems_version = %q{1.
|
38
|
+
s.rubygems_version = %q{1.5.2}
|
41
39
|
s.summary = %q{Oracle MERGE, optimizer hints, an schema extensions for Sequel}
|
42
|
-
s.test_files = [
|
43
|
-
"spec/sequel/oracle_extensions/hints_spec.rb",
|
44
|
-
"spec/sequel/oracle_extensions/merge_spec.rb",
|
45
|
-
"spec/spec_helper.rb"
|
46
|
-
]
|
47
40
|
|
48
41
|
if s.respond_to? :specification_version then
|
49
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
42
|
s.specification_version = 3
|
51
43
|
|
52
|
-
if Gem::Version.new(Gem::
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
53
45
|
s.add_runtime_dependency(%q<sequel>, [">= 3.10.0"])
|
54
|
-
s.add_development_dependency(%q<rspec>, [">= 2.0.0
|
46
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
|
55
47
|
else
|
56
48
|
s.add_dependency(%q<sequel>, [">= 3.10.0"])
|
57
|
-
s.add_dependency(%q<rspec>, [">= 2.0.0
|
49
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
58
50
|
end
|
59
51
|
else
|
60
52
|
s.add_dependency(%q<sequel>, [">= 3.10.0"])
|
61
|
-
s.add_dependency(%q<rspec>, [">= 2.0.0
|
53
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
62
54
|
end
|
63
55
|
end
|
64
56
|
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel_oracle_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 5
|
8
|
-
-
|
9
|
-
version: 0.5.
|
9
|
+
- 2
|
10
|
+
version: 0.5.2
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Joe Khoobyar
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
+
date: 2011-08-16 00:00:00 -04:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: sequel
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 47
|
27
30
|
segments:
|
28
31
|
- 3
|
29
32
|
- 10
|
@@ -35,16 +38,16 @@ dependencies:
|
|
35
38
|
name: rspec
|
36
39
|
prerelease: false
|
37
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
38
42
|
requirements:
|
39
43
|
- - ">="
|
40
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 15
|
41
46
|
segments:
|
42
47
|
- 2
|
43
48
|
- 0
|
44
49
|
- 0
|
45
|
-
|
46
|
-
- 8
|
47
|
-
version: 2.0.0.beta.8
|
50
|
+
version: 2.0.0
|
48
51
|
type: :development
|
49
52
|
version_requirements: *id002
|
50
53
|
description: Oracle extensions for Sequel, including MERGE statements, optimizer hints, and schema extensions.
|
@@ -58,7 +61,6 @@ extra_rdoc_files:
|
|
58
61
|
- README.rdoc
|
59
62
|
files:
|
60
63
|
- .document
|
61
|
-
- .gitignore
|
62
64
|
- .rspec
|
63
65
|
- LICENSE
|
64
66
|
- README.rdoc
|
@@ -78,32 +80,34 @@ homepage: http://github.com/joekhoobyar/sequel_oracle_extensions
|
|
78
80
|
licenses: []
|
79
81
|
|
80
82
|
post_install_message:
|
81
|
-
rdoc_options:
|
82
|
-
|
83
|
+
rdoc_options: []
|
84
|
+
|
83
85
|
require_paths:
|
84
86
|
- lib
|
85
87
|
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
86
89
|
requirements:
|
87
90
|
- - ">="
|
88
91
|
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
89
93
|
segments:
|
90
94
|
- 0
|
91
95
|
version: "0"
|
92
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
93
98
|
requirements:
|
94
99
|
- - ">="
|
95
100
|
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
96
102
|
segments:
|
97
103
|
- 0
|
98
104
|
version: "0"
|
99
105
|
requirements: []
|
100
106
|
|
101
107
|
rubyforge_project:
|
102
|
-
rubygems_version: 1.
|
108
|
+
rubygems_version: 1.5.2
|
103
109
|
signing_key:
|
104
110
|
specification_version: 3
|
105
111
|
summary: Oracle MERGE, optimizer hints, an schema extensions for Sequel
|
106
|
-
test_files:
|
107
|
-
|
108
|
-
- spec/sequel/oracle_extensions/merge_spec.rb
|
109
|
-
- spec/spec_helper.rb
|
112
|
+
test_files: []
|
113
|
+
|