Module | Sequel::ColumnsIntrospection |
In: |
lib/sequel/extensions/columns_introspection.rb
|
Attempt to guess the columns that will be returned if there are columns selected, in order to skip a database query to retrieve the columns. This should work with Symbols, SQL::Identifiers, SQL::QualifiedIdentifiers, and SQL::AliasedExpressions.
# File lib/sequel/extensions/columns_introspection.rb, line 26 26: def columns 27: return @columns if @columns 28: if (pcs = probable_columns) && pcs.all? 29: @columns = pcs 30: else 31: super 32: end 33: end
Return an array of probable column names for the dataset, or nil if it is not possible to determine that through introspection.
# File lib/sequel/extensions/columns_introspection.rb, line 40 40: def probable_columns 41: if (cols = opts[:select]) && !cols.empty? 42: cols.map{|c| probable_column_name(c)} 43: elsif !opts[:join] && !opts[:with] && (from = opts[:from]) && from.length == 1 && (from = from.first) 44: if from.is_a?(SQL::AliasedExpression) 45: from = from.expression 46: end 47: 48: case from 49: when Dataset 50: from.probable_columns 51: when Symbol, SQL::Identifier, SQL::QualifiedIdentifier 52: schemas = db.instance_variable_get(:@schemas) 53: if schemas && (table = literal(from)) && (sch = Sequel.synchronize{schemas[table]}) 54: sch.map{|c,_| c} 55: end 56: end 57: end 58: end