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) ⇒ Column

Create a column with its name and associated table



50
51
52
53
54
55
56
57
# File 'lib/amalgalite/column.rb', line 50

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

Instance Attribute Details

#collation_sequence_nameObject

the collation sequence name of the column



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

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



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

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.



34
35
36
# File 'lib/amalgalite/column.rb', line 34

def default_value
  @default_value
end

#nameObject

the column name



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

def name
  @name
end

#orderObject

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



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

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



90
91
92
# File 'lib/amalgalite/column.rb', line 90

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

#auto_increment?Boolean

true if the column is auto increment

Returns:



95
96
97
# File 'lib/amalgalite/column.rb', line 95

def auto_increment?
  @auto_increment
end

#has_default_value?Boolean

true if the column has a default value

Returns:



60
61
62
# File 'lib/amalgalite/column.rb', line 60

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



70
71
72
# File 'lib/amalgalite/column.rb', line 70

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:



75
76
77
# File 'lib/amalgalite/column.rb', line 75

def not_null_constraint?
  @not_null_constraint
end

#nullable?Boolean

true if the column may have a NULL value

Returns:



65
66
67
# File 'lib/amalgalite/column.rb', line 65

def nullable?
  @not_null_constraint == false
end

#primary_key=(other) ⇒ Object

set whether or not the column is a primary key column



80
81
82
# File 'lib/amalgalite/column.rb', line 80

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

#primary_key?Boolean

true if the column is a primary key column

Returns:



85
86
87
# File 'lib/amalgalite/column.rb', line 85

def primary_key?
  @primary_key
end