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 25 25: def columns 26: return @columns if @columns 27: if (pcs = probable_columns) && pcs.all? 28: @columns = pcs 29: else 30: super 31: end 32: 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 39 39: def probable_columns 40: if (cols = opts[:select]) && !cols.empty? 41: cols.map{|c| probable_column_name(c)} 42: elsif !opts[:join] && !opts[:with] && (from = opts[:from]) && from.length == 1 && (from = from.first) 43: if from.is_a?(SQL::AliasedExpression) 44: from = from.expression 45: end 46: 47: case from 48: when Dataset 49: from.probable_columns 50: when Symbol, SQL::Identifier, SQL::QualifiedIdentifier 51: schemas = db.instance_variable_get(:@schemas) 52: if schemas && (sch = Sequel.synchronize{schemas[literal(from)]}) 53: sch.map{|c,_| c} 54: end 55: end 56: end 57: end