Class: PgRest::PgService

Inherits:
Object
  • Object
show all
Defined in:
app/services/pg_rest/pg_service.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePgService

Returns a new instance of PgService.



6
7
# File 'app/services/pg_rest/pg_service.rb', line 6

def initialize
end

Instance Attribute Details

#uriObject

Returns the value of attribute uri.



4
5
6
# File 'app/services/pg_rest/pg_service.rb', line 4

def uri
  @uri
end

Class Method Details

.add_column(table_name:, name:, type:, primary_key: false, foreign_key: false, null: true, default: nil, array: false) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/services/pg_rest/pg_service.rb', line 23

def self.add_column(
    table_name:, 
    name:, 
    type:, 
    primary_key: false,
    foreign_key: false, 
    null: true, 
    default: nil, 
    array: false
  )
  self.with_transaction do  
    ActiveRecord::Migration[6.0].add_column table_name.to_sym, name.to_sym, type.to_sym, null: null, default: default, array: array, foreign_key: foreign_key 
  end
end

.create_table(table_name:) ⇒ Object



9
10
11
12
13
14
15
# File 'app/services/pg_rest/pg_service.rb', line 9

def self.create_table(table_name:)
  self.with_transaction do  
    ActiveRecord::Migration[6.0].create_table table_name.to_sym do |t|
      t.timestamps
    end
  end 
end

.drop_table(table_name:) ⇒ Object



17
18
19
20
21
# File 'app/services/pg_rest/pg_service.rb', line 17

def self.drop_table(table_name:)
  self.with_transaction do  
    ActiveRecord::Migration[6.0].drop_table table_name.to_sym
  end 
end

.remove_column(table_name:, name:) ⇒ Object



38
39
40
41
42
# File 'app/services/pg_rest/pg_service.rb', line 38

def self.remove_column(table_name:, name:)
  self.with_transaction do  
    ActiveRecord::Migration[6.0].remove_column table_name.to_sym, name.to_sym
  end 
end

.with_transactionObject



44
45
46
47
48
# File 'app/services/pg_rest/pg_service.rb', line 44

def self.with_transaction
  ActiveRecord::Base.transaction do 
    yield 
  end        
end