Module: PG::FTS::Index
Defined Under Namespace
Modules: Module
Class Method Summary collapse
- .build(*indices, &executor) ⇒ Object
- .clear(*indices, &executor) ⇒ Object
- .create(*indices, &executor) ⇒ Object
- .drop(*indices, &executor) ⇒ Object
- .drop_all(&executor) ⇒ Object
- .drop_all_procedures ⇒ Object
- .drop_all_triggers ⇒ Object
- .rebuild(*indices, &executor) ⇒ Object
- .recreate(*indices, &executor) ⇒ Object
- .reset(*indices, &executor) ⇒ Object
Instance Method Summary collapse
- #build {|build_query| ... } ⇒ Object
- #clear {|on_document_truncate_query| ... } ⇒ Object
- #create ⇒ Object
- #drop ⇒ Object
- #drop_procedure_query(name) ⇒ Object
- #drop_trigger_query(name, type) ⇒ Object
- #rebuild(&executor) ⇒ Object
Class Method Details
.build(*indices, &executor) ⇒ Object
103 104 105 |
# File 'lib/pg/fts/index.rb', line 103 def build(*indices, &executor) indices.each { |index| index.build(&executor) } end |
.clear(*indices, &executor) ⇒ Object
99 100 101 |
# File 'lib/pg/fts/index.rb', line 99 def clear(*indices, &executor) indices.each { |index| index.clear(&executor) } end |
.create(*indices, &executor) ⇒ Object
91 92 93 |
# File 'lib/pg/fts/index.rb', line 91 def create(*indices, &executor) indices.each { |index| index.create(&executor) } end |
.drop(*indices, &executor) ⇒ Object
95 96 97 |
# File 'lib/pg/fts/index.rb', line 95 def drop(*indices, &executor) indices.each { |index| index.drop(&executor) } end |
.drop_all(&executor) ⇒ Object
86 87 88 89 |
# File 'lib/pg/fts/index.rb', line 86 def drop_all(&executor) drop_all_triggers(&executor) drop_all_procedures(&executor) end |
.drop_all_procedures ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/pg/fts/index.rb', line 56 def drop_all_procedures procedures = yield <<-SQL.gsub(/^ {6}/, '') SELECT routine_name AS name FROM information_schema.routines WHERE routine_name LIKE '%_tsv' AND routine_type = 'FUNCTION'; SQL procedures.each do |procedure| yield <<-SQL.gsub(/^ {8}/, '') DROP FUNCTION IF EXISTS "#{procedure['name']}" (); SQL end end |
.drop_all_triggers ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/pg/fts/index.rb', line 71 def drop_all_triggers triggers = yield <<-SQL.gsub(/^ {6}/, '') SELECT tgname AS name, relname AS table FROM pg_trigger INNER JOIN pg_class ON pg_class.oid = tgrelid WHERE tgname like '%_tsv'; SQL triggers.each do |trigger| yield <<-SQL.gsub(/^ {8}/, '') DROP TRIGGER IF EXISTS "#{trigger['name']}" ON "#{trigger['table']}"; SQL end end |
.rebuild(*indices, &executor) ⇒ Object
107 108 109 |
# File 'lib/pg/fts/index.rb', line 107 def rebuild(*indices, &executor) indices.each { |index| index.rebuild(&executor) } end |
.recreate(*indices, &executor) ⇒ Object
111 112 113 114 |
# File 'lib/pg/fts/index.rb', line 111 def recreate(*indices, &executor) drop_all(&executor) create(*indices, &executor) end |
.reset(*indices, &executor) ⇒ Object
116 117 118 119 |
# File 'lib/pg/fts/index.rb', line 116 def reset(*indices, &executor) recreate(*indices, &executor) PG::FTS.clear(&executor) end |
Instance Method Details
#build {|build_query| ... } ⇒ Object
46 47 48 |
# File 'lib/pg/fts/index.rb', line 46 def build yield(build_query) end |
#clear {|on_document_truncate_query| ... } ⇒ Object
42 43 44 |
# File 'lib/pg/fts/index.rb', line 42 def clear yield(on_document_truncate_query) end |
#create ⇒ Object
2 3 4 5 6 7 8 9 10 11 |
# File 'lib/pg/fts/index.rb', line 2 def create [:document, :source, :link].each do |type| [:insert, :update, :delete, :truncate].each do |op| [:procedure, :trigger].each do |item| name = "on_#{type}_#{op}_#{item}" yield(send(name)) if respond_to?(name) end end end end |
#drop ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pg/fts/index.rb', line 31 def drop [:document, :source, :link].each do |type| [:insert, :update, :delete, :truncate].each do |op| name = "on_#{type}_#{op}_trigger" yield(drop_trigger_query(name, type)) if respond_to?(name) name = "on_#{type}_#{op}_procedure" yield(drop_procedure_query(name)) if respond_to?(name) end end end |
#drop_procedure_query(name) ⇒ Object
13 14 15 16 17 |
# File 'lib/pg/fts/index.rb', line 13 def drop_procedure_query(name) <<-SQL.gsub(/^ {4}/, '') DROP FUNCTION IF EXISTS "#{send(name + '_name')}" (); SQL end |
#drop_trigger_query(name, type) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pg/fts/index.rb', line 19 def drop_trigger_query(name, type) t = case type when :document then document when :source then source when :link then link end <<-SQL.gsub(/^ {4}/, '') DROP TRIGGER IF EXISTS "#{send(name + '_name')}" ON "#{t}"; SQL end |
#rebuild(&executor) ⇒ Object
50 51 52 53 |
# File 'lib/pg/fts/index.rb', line 50 def rebuild(&executor) clear(&executor) build(&executor) end |