Parent

Class/Module Index [+]

Quicksearch

Amalgalite::Table

a class representing the meta information about an SQLite table

Attributes

columns[RW]

a hash of Column objects holding the meta information about the columns in this table. keys are the column names

indexes[RW]

hash of Index objects holding the meta informationa about the indexes on this table. The keys of the indexes variable is the index name

name[R]

the table name

schema[RW]

the schema object the table is associated with

sql[R]

the original sql that was used to create this table

Public Class Methods

new( name, sql = nil ) click to toggle source
# File lib/amalgalite/table.rb, line 28
def initialize( name, sql = nil ) 
  @name    = name
  @sql     = sql
  @indexes = {}
  @columns = {}
end

Public Instance Methods

column_names() click to toggle source

the column names in original definition order

# File lib/amalgalite/table.rb, line 47
def column_names
  columns_in_order.map { |c| c.name }
end
columns_in_order() click to toggle source

the Columns in original definition order

# File lib/amalgalite/table.rb, line 42
def columns_in_order
  @columns.values.sort_by { |c| c.order }
end
primary_key() click to toggle source

the array of colmuns that make up the primary key of the table since a primary key has an index, we loop over all the indexes for the table and pick the first one that is unique, and all the columns in the index have primary_key? as true.

we do this instead of just looking for the columns where primary key is true because we want the columns in primary key order

# File lib/amalgalite/table.rb, line 63
def primary_key
  unless @primary_key
    pk_column_names = Set.new( primary_key_columns.collect { |c| c.name } )
    unique_indexes  = indexes.values.find_all { |i| i.unique? }

    pk_result = []

    unique_indexes.each do |idx|
      idx_column_names = Set.new( idx.columns.collect { |c| c.name } )
      r = idx_column_names ^ pk_column_names
      if r.size == 0 then
        pk_result = idx.columns
        break
      end
    end

    # no joy, see about just using all the columns that say the are primary
    # keys
    if pk_result.empty? then
      pk_result = self.primary_key_columns
    end
    @primary_key = pk_result
  end
  return @primary_key
end
primary_key_columns() click to toggle source

the columns that make up the primary key

# File lib/amalgalite/table.rb, line 52
def primary_key_columns
  @columns.values.find_all { |c| c.primary_key? }
end
temporary?() click to toggle source

Is the table a temporary table or not

# File lib/amalgalite/table.rb, line 36
def temporary?
  !sql
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.