Module: PgRest::Schema

Defined in:
app/services/pg_rest/schema.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#tablesObject

Returns the value of attribute tables.



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

def tables
  @tables
end

Class Method Details

.pg_schemaObject



22
23
24
25
26
27
28
29
30
31
# File 'app/services/pg_rest/schema.rb', line 22

def self.pg_schema 
  @tables = table_names
  schema = {
    tables: @tables
  }
  @tables.each do |table_name|
    schema[table_name] = table_schema(table_name)
  end      
  schema   
end

.render_column(column) ⇒ Object



33
34
35
36
37
38
39
40
# File 'app/services/pg_rest/schema.rb', line 33

def self.render_column(column)
  {
    name: column.name,
    type: column..type,
    limit: column..limit,
    precision: column..precision,
  }
end

.table_namesObject



6
7
8
9
# File 'app/services/pg_rest/schema.rb', line 6

def self.table_names
  #ActiveRecord::Base.connection.query_cache.clear
  @tables = ActiveRecord::Base.connection.tables
end

.table_schema(table_name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'app/services/pg_rest/schema.rb', line 11

def self.table_schema(table_name) 
  @tables = table_names 
  pg_table = PgRest::PgTable.modelize(table_name) 
  pg_table.reset_column_information      
  columns = []
  pg_table.columns.each do |column|
    columns << render_column(column) 
  end 
  columns
end