Public Instance methods
columns()
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.
[show source]
# File lib/sequel/extensions/columns_introspection.rb 30 def columns 31 if cols = _columns 32 return cols 33 end 34 if (pcs = probable_columns) && pcs.all? 35 self.columns = pcs 36 else 37 super 38 end 39 end
Protected Instance methods
probable_columns()
Return an array of probable column names for the dataset, or nil if it is not possible to determine that through introspection.
[show source]
# File lib/sequel/extensions/columns_introspection.rb 46 def probable_columns 47 if (cols = opts[:select]) && !cols.empty? 48 cols.map{|c| probable_column_name(c)} 49 elsif !opts[:join] && !opts[:with] && (from = opts[:from]) && from.length == 1 && (from = from.first) 50 if from.is_a?(SQL::AliasedExpression) 51 from = from.expression 52 end 53 54 case from 55 when Dataset 56 from.probable_columns 57 when Symbol, SQL::Identifier, SQL::QualifiedIdentifier 58 schemas = db.instance_variable_get(:@schemas) 59 if schemas && (table = literal(from)) && (sch = Sequel.synchronize{schemas[table]}) 60 sch.map{|c,_| c} 61 end 62 end 63 end 64 end