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 30 30: def columns 31: return @columns if @columns 32: if (pcs = probable_columns) && pcs.all? 33: self.columns = pcs 34: else 35: super 36: end 37: 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 44 44: def probable_columns 45: if (cols = opts[:select]) && !cols.empty? 46: cols.map{|c| probable_column_name(c)} 47: elsif !opts[:join] && !opts[:with] && (from = opts[:from]) && from.length == 1 && (from = from.first) 48: if from.is_a?(SQL::AliasedExpression) 49: from = from.expression 50: end 51: 52: case from 53: when Dataset 54: from.probable_columns 55: when Symbol, SQL::Identifier, SQL::QualifiedIdentifier 56: schemas = db.instance_variable_get(:@schemas) 57: if schemas && (table = literal(from)) && (sch = Sequel.synchronize{schemas[table]}) 58: sch.map{|c,_| c} 59: end 60: end 61: end 62: end