sequel_oracle_extensions 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/sequel/oracle_extensions/hints.rb +71 -71
- data/lib/sequel/oracle_extensions/merge.rb +204 -204
- data/lib/sequel/oracle_extensions/schemata.rb +148 -123
- data/lib/sequel/oracle_extensions.rb +4 -4
- data/lib/sequel_oracle_extensions.rb +1 -1
- data/sequel_oracle_extensions.gemspec +62 -56
- data/spec/sequel/oracle_extensions/hints_spec.rb +148 -148
- data/spec/sequel/oracle_extensions/merge_spec.rb +8 -8
- data/spec/spec_helper.rb +24 -24
- metadata +10 -8
@@ -1,123 +1,148 @@
|
|
1
|
-
require 'sequel'
|
2
|
-
Sequel.require 'adapters/shared/oracle'
|
3
|
-
|
4
|
-
# The oracle_schemata extension adds some schema related methods to the Oracle database adapater.
|
5
|
-
module Sequel
|
6
|
-
module Oracle
|
7
|
-
module DatabaseMethods
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
#
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
1
|
+
require 'sequel'
|
2
|
+
Sequel.require 'adapters/shared/oracle'
|
3
|
+
|
4
|
+
# The oracle_schemata extension adds some schema related methods to the Oracle database adapater.
|
5
|
+
module Sequel
|
6
|
+
module Oracle
|
7
|
+
module DatabaseMethods
|
8
|
+
|
9
|
+
# Returns the indexes for the given +table+ (or +schema.table+), as an array of hashes.
|
10
|
+
# By default, it does not return primary keys.
|
11
|
+
#
|
12
|
+
# * <tt>:valid</tt> - Only look for indexes that are valid (true) or unusable (false). By default (nil),
|
13
|
+
# looks for any matching index.
|
14
|
+
# * <tt>:all</tt> - Returns all indexes, even ones used for primary keys.
|
15
|
+
def indexes(qualified_table, options={})
|
16
|
+
ds, result = metadata_dataset, []
|
17
|
+
outm = lambda{|k| ds.send :output_identifier, k}
|
18
|
+
schema, table = ds.schema_and_table(qualified_table).map{|k| k.to_s.send(ds.identifier_input_method) if k}
|
19
|
+
|
20
|
+
# Build the dataset and apply filters for introspection of indexes.
|
21
|
+
ds = ds.select(:i__index_name, :i__status, :i__uniqueness, :i__visibility,
|
22
|
+
:i__index_type, :i__join_index, :ic__column_name).
|
23
|
+
from(:"all_indexes___i").
|
24
|
+
join(:"all_ind_columns___ic", [ [:index_owner,:owner], [:index_name,:index_name] ]).
|
25
|
+
where(:i__table_name=>table, :i__dropped=>'NO').
|
26
|
+
order(:status.desc, :index_name, :ic__column_position)
|
27
|
+
unless schema.nil?
|
28
|
+
ds = ds.where :i__owner => schema
|
29
|
+
end
|
30
|
+
unless (z = options[:valid]).nil?
|
31
|
+
ds = ds.where :i__status => (z ? 'VALID' : 'UNUSABLE')
|
32
|
+
end
|
33
|
+
if options[:all]
|
34
|
+
pk = from(:all_constraints.as(:c)).where(:c__constraint_type=>'P').
|
35
|
+
where(:c__index_name=>:i__index_name, :c__owner=>:i__owner)
|
36
|
+
ds = ds.where ~pk.exists
|
37
|
+
end
|
38
|
+
|
39
|
+
# Return the table constraints as an array of hashes, including a column list.
|
40
|
+
hash = Hash.new do |h,k|
|
41
|
+
result.push :index_name=>outm[k], :table_name=>outm[table], :columns=>[]
|
42
|
+
h[k] = result.last
|
43
|
+
end
|
44
|
+
ds.each do |row|
|
45
|
+
ref = hash[row[:index_name]]
|
46
|
+
ref[:index_type] ||= row[:index_type]
|
47
|
+
ref[:join_index] ||= row[:join_index]=='YES'
|
48
|
+
ref[:status] ||= row[:status]=='VALID'
|
49
|
+
ref[:uniqueness] ||= row[:uniqueness]=='UNIQUE'
|
50
|
+
ref[:visibility] ||= row[:visibility]=='VISIBLE'
|
51
|
+
ref[:columns] << outm[row[:column_name]]
|
52
|
+
end
|
53
|
+
result
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns the primary key for the given +table+ (or +schema.table+), as a hash.
|
57
|
+
#
|
58
|
+
# * <tt>:enabled</tt> - Only look for keys that are enabled (true) or disabled (false). By default (nil),
|
59
|
+
# looks for any matching key.
|
60
|
+
# * <tt>:all</tt> - Return an array of matching keys, instead of the first matching key.
|
61
|
+
#
|
62
|
+
def primary_key(qualified_table, options={})
|
63
|
+
result = table_constraints qualified_table, 'P', options
|
64
|
+
options[:all] ? result : result.first
|
65
|
+
end
|
66
|
+
|
67
|
+
# Returns unique constraints defined on the given +table+ (or +schema.table+), as an array of hashes.
|
68
|
+
#
|
69
|
+
# * <tt>:enabled</tt> - Only look for keys that are enabled (true) or disabled (false). By default (nil),
|
70
|
+
# looks for all matching keys.
|
71
|
+
def unique_keys(qualified_table, options={})
|
72
|
+
table_constraints qualified_table, 'U', options
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns foreign keys defined on the given +table+ (or +schema.table+), as an array of hashes.
|
76
|
+
#
|
77
|
+
# * <tt>:enabled</tt> - Only look for keys that are enabled (true) or disabled (false). By default (nil),
|
78
|
+
# looks for all matching keys.
|
79
|
+
def foreign_keys(qualified_table, options={})
|
80
|
+
table_constraints qualified_table, 'R', options
|
81
|
+
end
|
82
|
+
|
83
|
+
# Returns foreign keys that refer to the given +table+ (or +schema.table+), as an array of hashes.
|
84
|
+
#
|
85
|
+
# * <tt>:enabled</tt> - Only look for keys that are enabled (true) or disabled (false). By default (nil),
|
86
|
+
# looks for all matching keys.
|
87
|
+
def references(qualified_table, options={})
|
88
|
+
table_constraints qualified_table, 'R', options.merge(:table_name_column=>:t__table_name)
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
# Internal helper method for introspection of table constraints.
|
94
|
+
def table_constraints(qualified_table, constraint_type, options={})
|
95
|
+
ds, result = metadata_dataset, []
|
96
|
+
outm = lambda{|k| ds.send :output_identifier, k}
|
97
|
+
schema, table = ds.schema_and_table(qualified_table).map{|k| k.to_s.send(ds.identifier_input_method) if k}
|
98
|
+
x_cons = schema.nil? ? 'user_cons' : 'all_cons'
|
99
|
+
|
100
|
+
# Build the dataset and apply filters for introspection of constraints.
|
101
|
+
# Also allows the caller to customize the dataset.
|
102
|
+
ds = ds.select(:c__constraint_name, :c__table_name, :c__rely, :c__status, :c__validated, :cc__column_name).
|
103
|
+
from(:"#{x_cons}traints___c").
|
104
|
+
join(:"#{x_cons}_columns___cc", [ [:owner,:owner], [:constraint_name,:constraint_name] ]).
|
105
|
+
where((options[:table_name_column]||:c__table_name)=>table, :c__constraint_type=>constraint_type).
|
106
|
+
order(:table_name, :status.desc, :constraint_name, :cc__position)
|
107
|
+
unless schema.nil?
|
108
|
+
ds = ds.where :c__owner => schema
|
109
|
+
end
|
110
|
+
unless (z = options[:enabled]).nil?
|
111
|
+
ds = ds.where :c__status => (z ? 'ENABLED' : 'DISABLED')
|
112
|
+
end
|
113
|
+
|
114
|
+
if constraint_type == 'R'
|
115
|
+
ds = ds.select_more(:c__r_constraint_name, :t__table_name.as(:r_table_name)).
|
116
|
+
join(:"#{x_cons}traints___t", [ [:owner,:c__r_owner], [:constraint_name,:c__r_constraint_name] ]).
|
117
|
+
where(:t__constraint_type=>'P')
|
118
|
+
else
|
119
|
+
ds = ds.select_more(:c__index_name)
|
120
|
+
end
|
121
|
+
ds = yield ds, table if block_given?
|
122
|
+
|
123
|
+
# Return the table constraints as an array of hashes, including a column list.
|
124
|
+
hash = Hash.new do |h,k|
|
125
|
+
result.push :constraint_name=>outm[k], :constraint_type=>constraint_type, :columns=>[]
|
126
|
+
h[k] = result.last
|
127
|
+
end
|
128
|
+
ds.each do |row|
|
129
|
+
ref = hash[row[:constraint_name]]
|
130
|
+
ref[:table_name] ||= outm[row[:table_name]]
|
131
|
+
ref[:rely] ||= row[:rely]=='RELY'
|
132
|
+
ref[:enabled] ||= row[:status]=='ENABLED'
|
133
|
+
ref[:validated] ||= row[:validated]=='VALIDATED'
|
134
|
+
ref[:columns] << outm[row[:column_name]]
|
135
|
+
|
136
|
+
if row.include? :r_constraint_name
|
137
|
+
ref[:r_constraint_name] ||= outm[row[:r_constraint_name]]
|
138
|
+
ref[:r_table_name] ||= outm[row[:r_table_name]]
|
139
|
+
end
|
140
|
+
if row[:index_name]
|
141
|
+
ref[:index_name] ||= outm[row[:index_name]]
|
142
|
+
end
|
143
|
+
end
|
144
|
+
result
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'sequel'
|
2
|
-
require 'sequel/oracle_extensions/schemata'
|
3
|
-
require 'sequel/oracle_extensions/merge'
|
4
|
-
require 'sequel/oracle_extensions/hints'
|
1
|
+
require 'sequel'
|
2
|
+
require 'sequel/oracle_extensions/schemata'
|
3
|
+
require 'sequel/oracle_extensions/merge'
|
4
|
+
require 'sequel/oracle_extensions/hints'
|
@@ -1 +1 @@
|
|
1
|
-
require 'sequel/oracle_extensions'
|
1
|
+
require 'sequel/oracle_extensions'
|
@@ -1,56 +1,62 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{sequel_oracle_extensions}
|
8
|
-
s.version = "0.5.
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Joe Khoobyar"]
|
12
|
-
s.date = %q{2011-08-
|
13
|
-
s.description = %q{Oracle extensions for Sequel, including MERGE statements, optimizer hints, and schema extensions.}
|
14
|
-
s.email = %q{joe@ankhcraft.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
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"
|
35
|
-
]
|
36
|
-
s.homepage = %q{http://github.com/joekhoobyar/sequel_oracle_extensions}
|
37
|
-
s.require_paths = ["lib"]
|
38
|
-
s.rubygems_version = %q{1.
|
39
|
-
s.summary = %q{Oracle MERGE, optimizer hints, an schema extensions for Sequel}
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{sequel_oracle_extensions}
|
8
|
+
s.version = "0.5.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Joe Khoobyar"]
|
12
|
+
s.date = %q{2011-08-17}
|
13
|
+
s.description = %q{Oracle extensions for Sequel, including MERGE statements, optimizer hints, and schema extensions.}
|
14
|
+
s.email = %q{joe@ankhcraft.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
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"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/joekhoobyar/sequel_oracle_extensions}
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.7}
|
39
|
+
s.summary = %q{Oracle MERGE, optimizer hints, an schema extensions for Sequel}
|
40
|
+
s.test_files = [
|
41
|
+
"spec/sequel/oracle_extensions/hints_spec.rb",
|
42
|
+
"spec/sequel/oracle_extensions/merge_spec.rb",
|
43
|
+
"spec/spec_helper.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_runtime_dependency(%q<sequel>, [">= 3.10.0"])
|
52
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<sequel>, [">= 3.10.0"])
|
55
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
56
|
+
end
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<sequel>, [">= 3.10.0"])
|
59
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|