### Home Classes Methods

### In Files

- lib/amalgalite/table.rb

### Parent

Object

### Methods

- ::new
- #column_names
- #columns_in_order
- #primary_key
- #primary_key_columns
- #temporary?

### Files

- HISTORY.rdoc
- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- Amalgalite
- Amalgalite::Aggregate
- Amalgalite::Blob
- Amalgalite::Blob::Error
- Amalgalite::Boolean
- Amalgalite::BusyHandler
- Amalgalite::BusyTimeout
- Amalgalite::CSVTableImporter
- Amalgalite::Column
- Amalgalite::Database
- Amalgalite::Database::AggregateError
- Amalgalite::Database::BusyHandlerError
- Amalgalite::Database::FunctionError
- Amalgalite::Database::InvalidModeError
- Amalgalite::Database::ProgressHandlerError
- Amalgalite::Database::TransactionBehavior
- Amalgalite::Error
- Amalgalite::Function
- Amalgalite::Index
- Amalgalite::MemoryDatabase
- Amalgalite::Packer
- Amalgalite::Paths
- Amalgalite::ProfileSampler
- Amalgalite::ProfileTap
- Amalgalite::ProgressHandler
- Amalgalite::Requires
- Amalgalite::SQLite3
- Amalgalite::SQLite3::Constants
- Amalgalite::SQLite3::Constants::Config
- Amalgalite::SQLite3::Constants::DBStatus
- Amalgalite::SQLite3::Constants::DataType
- Amalgalite::SQLite3::Constants::Helpers
- Amalgalite::SQLite3::Constants::Open
- Amalgalite::SQLite3::Constants::ResultCode
- Amalgalite::SQLite3::Constants::StatementStatus
- Amalgalite::SQLite3::Constants::Status
- Amalgalite::SQLite3::Database
- Amalgalite::SQLite3::Database::DBStatus
- Amalgalite::SQLite3::Database::Function
- Amalgalite::SQLite3::Database::Stat
- Amalgalite::SQLite3::Stat
- Amalgalite::SQLite3::Status
- Amalgalite::SQLite3::Version
- Amalgalite::Schema
- Amalgalite::Statement
- Amalgalite::Table
- Amalgalite::Taps
- Amalgalite::Taps::IO
- Amalgalite::Taps::Stderr
- Amalgalite::Taps::Stdout
- Amalgalite::Taps::StringIO
- Amalgalite::TraceTap
- Amalgalite::TypeMap
- Amalgalite::TypeMaps
- Amalgalite::TypeMaps::DefaultMap
- Amalgalite::TypeMaps::StorageMap
- Amalgalite::TypeMaps::TextMap
- Amalgalite::Version
- Amalgalite::View
- Kernel
- Object

No matching classes.

# 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.