Method: Table.check_qual_column
- Defined in:
- lib/types/sequel/comp_types.rb
.check_qual_column(column_name, all_joined, type = nil) ⇒ Object
- + column_name +
-
if a symbol or SeqQualIdent Generic type of the qualified column name, e.g. :person__age
- + all_joined +
-
is an array of symbols of joined tables (must check if qualifying table is a member)
- + type +
-
is optional RDL type. If given, we check that it matches the type of the column in the schema.
returns type of given column
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 |
# File 'lib/types/sequel/comp_types.rb', line 484 def self.check_qual_column(column_name, all_joined, type=nil) case column_name when RDL::Type::GenericType cn = RDL.type_cast(column_name, "RDL::Type::GenericType", force: true) raise "Expected qualified column type." unless cn.base.name == "SeqQualIdent" qual_table, qual_column = cn.params.map { |t| RDL.type_cast(t, "RDL::Type::SingletonType<Symbol>", force: true).val } else ## symbol with name including underscores qual_table, qual_column = RDL.type_cast(column_name, "Symbol", force: true).to_s.split "__" qual_table = if qual_table.start_with?(":") then qual_table[1..-1].to_sym else qual_table.to_sym end qual_column = qual_column.to_sym end raise RDL::Typecheck::StaticTypeError, "qualified table #{qual_table} is not joined in receiver table, cannot reference its columns" unless all_joined.include?(qual_table) qual_table_schema = get_schema(RDL::Globals.seq_db_schema[qual_table].elts) raise RDL::Typecheck::StaticTypeError, "No column #{qual_column} in table #{qual_table}." if qual_table_schema[qual_column].nil? if type types = (if type.is_a?(RDL::Type::UnionType) then RDL.type_cast(type, "RDL::Type::UnionType", force: true).types else [type] end) types.each { |t| t = RDL.type_cast(t, "RDL::Type::GenericType", force: true).params[0] if t.is_a?(RDL::Type::GenericType) && (RDL.type_cast(t, "RDL::Type::GenericType", force: true).base == RDL::Globals.types[:array]) ## only happens if meth is where, don't need to check raise RDL::Typecheck::StaticTypeError, "Incompatible column types. Given #{t} but expected #{qual_table_schema[qual_column]} for column #{column_name}." unless RDL::Type::Type.leq(t, qual_table_schema[qual_column]) } end return qual_table_schema[qual_column] end |