| Class | Database |
| In: |
app/models/database.rb
|
| Parent: | ActiveRecord::Base |
This method switches ActiveRecord‘s connection to the actual database this database model represents, creates a table, then switches back to the RailsDB database.
Only the first field is included in the create_table call. The rest are added using add_column.
# File app/models/database.rb, line 63
63: def create_tbl( params )
64: switch( self ) do
65: options = {}
66: options[:id] = false if params[:add_id] == '0'
67: col_options = mangle_column_options( params, '1' )
68: ActiveRecord::Base.connection.create_table( params[:name].to_sym, options ) do |t|
69: t.column params[:fields]['1'][:name].to_sym, params[:fields]['1'][:type].to_sym, col_options
70: end
71: table = self.get_table( params[:name] )
72: table.add_fields( params ) if table
73: end
74: end
# File app/models/database.rb, line 49
49: def del_table( table )
50: switch( self ) do
51: ActiveRecord::Base.connection.drop_table( table.to_sym )
52: end
53: end
# File app/models/database.rb, line 76
76: def get_table( name )
77: switch( self ) do
78: return Table.new( self, name ) if ActiveRecord::Base.connection.tables.include? name
79: end
80: nil
81: end
Does this database contain a table with passed name?
# File app/models/database.rb, line 108
108: def has_table?( name )
109: self.table_names.each { |t| return true if t == name }
110: false
111: end
This provides just the table names, not table objects
# File app/models/database.rb, line 101
101: def table_names
102: self.tables.collect { |t| t.name }
103: end
This method switches ActiveRecord‘s connection to the actual database this database model represents, grabs a table list, then switches back to the RailsDB database.
# File app/models/database.rb, line 88
88: def tables
89: tables = []
90: switch( self ) do
91: ActiveRecord::Base.connection.tables.each do |t|
92: tables << Table.new( self, t )
93: end
94: end
95: tables
96: end