Class: Amalgalite::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/amalgalite/column.rb

Overview

a class representing the meta information about an SQLite column, this class serves both for general Schema level information, and for result set information from a SELECT query.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db, table, name, order, as_name = nil) ⇒ Column

Create a column with its name and associated table



57
58
59
60
61
62
63
64
65
66
# File 'lib/amalgalite/column.rb', line 57

def initialize( db, table, name, order, as_name = nil)
  @db                 = db
  @table              = table
  @name               = name
  @order              = Float(order).to_i
  @as_name            = as_name || name
  @declared_data_type = nil
  @normalized_declared_data_type = nil
  @default_value      = nil
end

Instance Attribute Details

#as_nameObject

The column “as” name. This is what its name is in the query, if this is part of the query, then this is the result, otherwise it is the name



32
33
34
# File 'lib/amalgalite/column.rb', line 32

def as_name
  @as_name
end

#collation_sequence_nameObject

the collation sequence name of the column



48
49
50
# File 'lib/amalgalite/column.rb', line 48

def collation_sequence_name
  @collation_sequence_name
end

#dbObject

the database name this column belongs to. This will be ‘main’ for the main database, ‘temp’ for the temp database and whatever an attached database was attached as.



22
23
24
# File 'lib/amalgalite/column.rb', line 22

def db
  @db
end

#declared_data_typeObject

the declared data type of the column in the original sql that created the column



42
43
44
# File 'lib/amalgalite/column.rb', line 42

def declared_data_type
  @declared_data_type
end

#default_valueObject

the default value of the column. This may not have a value and that either means that there is no default value, or one could not be determined.



38
39
40
# File 'lib/amalgalite/column.rb', line 38

def default_value
  @default_value
end

#nameObject

the column name



28
29
30
# File 'lib/amalgalite/column.rb', line 28

def name
  @name
end

#normalized_declared_data_typeObject (readonly)

the declared data type that is tokenized and then downcased



45
46
47
# File 'lib/amalgalite/column.rb', line 45

def normalized_declared_data_type
  @normalized_declared_data_type
end

#orderObject

The index (starting with 0) of this column in the table definition or result set



52
53
54
# File 'lib/amalgalite/column.rb', line 52

def order
  @order
end

#schemaObject

the schema object this column is associated with



17
18
19
# File 'lib/amalgalite/column.rb', line 17

def schema
  @schema
end

#tableObject

the table to which this column belongs



25
26
27
# File 'lib/amalgalite/column.rb', line 25

def table
  @table
end

Instance Method Details

#auto_increment=(other) ⇒ Object

set whether or not the column is auto increment



108
109
110
# File 'lib/amalgalite/column.rb', line 108

def auto_increment=( other )
  @auto_increment = Boolean.to_bool( other )
end

#auto_increment?Boolean

true if the column is auto increment

Returns:



113
114
115
# File 'lib/amalgalite/column.rb', line 113

def auto_increment?
  @auto_increment
end

#has_default_value?Boolean

true if the column has a default value

Returns:



78
79
80
# File 'lib/amalgalite/column.rb', line 78

def has_default_value?
  not default_value.nil?
end

#not_null_constraint=(other) ⇒ Object

set whether or not the column has a not null constraint



88
89
90
# File 'lib/amalgalite/column.rb', line 88

def not_null_constraint=( other )
  @not_null_constraint = Boolean.to_bool( other )
end

#not_null_constraint?Boolean

true if the column as a NOT NULL constraint

Returns:



93
94
95
# File 'lib/amalgalite/column.rb', line 93

def not_null_constraint?
  @not_null_constraint
end

#nullable?Boolean

true if the column may have a NULL value

Returns:



83
84
85
# File 'lib/amalgalite/column.rb', line 83

def nullable?
  @not_null_constraint == false
end

#primary_key=(other) ⇒ Object

set whether or not the column is a primary key column



98
99
100
# File 'lib/amalgalite/column.rb', line 98

def primary_key=( other )
  @primary_key = Boolean.to_bool( other )
end

#primary_key?Boolean

true if the column is a primary key column

Returns:



103
104
105
# File 'lib/amalgalite/column.rb', line 103

def primary_key?
  @primary_key
end