Class: Dart::Reflection::SequelTable::Schema

Inherits:
Object
  • Object
show all
Includes:
Dart::Reflection::Sequel::Sequelizer
Defined in:
lib/dart/reflection/sequel_table/schema.rb

Overview

Schema holds all the relations in a schema

Instance Method Summary collapse

Methods included from Dart::Reflection::Sequel::Sequelizer

#sequelize

Constructor Details

#initialize(db, db_tables = nil) ⇒ Schema

Returns a new instance of Schema.



12
13
14
15
16
17
18
# 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

Instance Method Details

#execute!(sql) ⇒ Object



20
21
22
# File 'lib/dart/reflection/sequel_table/schema.rb', line 20

def execute!(sql)
  db[sql]
end

#has_table?(table) ⇒ Boolean

Returns true if this schema has the given table

Parameters:

  • table (Symbol|String)

Returns:

  • (Boolean)


26
27
28
# File 'lib/dart/reflection/sequel_table/schema.rb', line 26

def has_table?(table)
  tables.include? sequelize(table)
end

#relation(table) ⇒ Relation Also known as: []

Returns a relation from this schema corresponding to the given table

Parameters:

  • table (Symbol|String)

    the name of the table

Returns:

  • (Relation)

    the relation corresponding to the given table



43
44
45
# File 'lib/dart/reflection/sequel_table/schema.rb', line 43

def relation(table)
  relation_map[sequelize(table)]
end

#relationsArray<Relation>

Returns list of Relations in this schema.

Returns:

  • (Array<Relation>)

    list of Relations in this schema



36
37
38
# File 'lib/dart/reflection/sequel_table/schema.rb', line 36

def relations
  relation_map.values
end

#tablesArray<Symbol>

Returns list of table names in this schema.

Returns:

  • (Array<Symbol>)

    list of table names in this schema



31
32
33
# File 'lib/dart/reflection/sequel_table/schema.rb', line 31

def tables
  relation_map.keys
end