class Dart::Reflection::SequelTable::Schema

Schema holds all the relations in a schema

Attributes

db[R]
relation_map[R]

Public Class Methods

new(db, db_tables=nil) click to toggle source
# File lib/dart/reflection/sequel_table/schema.rb, line 12
def initialize(db, db_tables=nil)
  @db = db

  # default to using all tables unless db_tables is passed in
  table_names   = (db_tables || db.tables).map(&method(:sequelize))
  @relation_map = Hash[table_names.map { |table| [table, Database::Relation.new(table, db[table].columns)] }]
end

Public Instance Methods

[](table)
Alias for: relation
execute!(sql) click to toggle source
# File lib/dart/reflection/sequel_table/schema.rb, line 20
def execute!(sql)
  db[sql]
end
has_table?(table) click to toggle source

Returns true if this schema has the given table @param [Symbol|String] table

# File lib/dart/reflection/sequel_table/schema.rb, line 26
def has_table?(table)
  tables.include? sequelize(table)
end
relation(table) click to toggle source

Returns a relation from this schema corresponding to the given table @param [Symbol|String] table the name of the table @return [Relation] the relation corresponding to the given table

# File lib/dart/reflection/sequel_table/schema.rb, line 43
def relation(table)
  relation_map[sequelize(table)]
end
Also aliased as: []
relations() click to toggle source

@return [Array<Relation>] list of Relations in this schema

# File lib/dart/reflection/sequel_table/schema.rb, line 36
def relations
  relation_map.values
end
tables() click to toggle source

@return [Array<Symbol>] list of table names in this schema

# File lib/dart/reflection/sequel_table/schema.rb, line 31
def tables
  relation_map.keys
end