Class: Dart::Reflection::SequelTable::Schema
- Inherits:
-
Object
- Object
- Dart::Reflection::SequelTable::Schema
- 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
- #execute!(sql) ⇒ Object
-
#has_table?(table) ⇒ Boolean
Returns true if this schema has the given table.
-
#initialize(db, db_tables = nil) ⇒ Schema
constructor
A new instance of Schema.
-
#relation(table) ⇒ Relation
(also: #[])
Returns a relation from this schema corresponding to the given table.
-
#relations ⇒ Array<Relation>
List of
Relations
in this schema. -
#tables ⇒ Array<Symbol>
List of table names in this schema.
Methods included from Dart::Reflection::Sequel::Sequelizer
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
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
43 44 45 |
# File 'lib/dart/reflection/sequel_table/schema.rb', line 43 def relation(table) relation_map[sequelize(table)] end |
#relations ⇒ Array<Relation>
Returns 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 |
#tables ⇒ Array<Symbol>
Returns 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 |