Class: PgRest::PgService
- Inherits:
-
Object
- Object
- PgRest::PgService
- Defined in:
- app/services/pg_rest/pg_service.rb
Instance Attribute Summary collapse
-
#uri ⇒ Object
Returns the value of attribute uri.
Class Method Summary collapse
- .add_column(table_name:, name:, type:, primary_key: false, foreign_key: false, null: true, default: nil, array: false) ⇒ Object
- .create_table(table_name:) ⇒ Object
- .drop_table(table_name:) ⇒ Object
- .remove_column(table_name:, name:) ⇒ Object
- .with_transaction ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ PgService
constructor
A new instance of PgService.
Constructor Details
#initialize ⇒ PgService
Returns a new instance of PgService.
6 7 |
# File 'app/services/pg_rest/pg_service.rb', line 6 def initialize end |
Instance Attribute Details
#uri ⇒ Object
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. 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_transaction ⇒ Object
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 |