class CQL::Column(Type)

Overview

A typed column in a table: its name, type, default value and constraints, and the expression used to reference it in queries.

Example Declaring columns

schema.table :members do
  primary :id, Int64
  column :name, String, null: false, default: "John"
  column :age, Int32, null: true
end

Direct Known Subclasses

Defined in:

column.cr

Constructors

Instance Method Summary

Instance methods inherited from class CQL::BaseColumn

copy_to(table : Table) : BaseColumn copy_to

Constructor Detail

def self.new(name : Symbol, as_name : String | Nil = nil, null : Bool = false, default : DB::Any = nil, unique : Bool = false, size : Int32 | Nil = nil, index : Index | Nil = nil, version_number : Bool = false) #

Create a new column instance; the type is the class's type argument (Column(String)). Tables add columns with Table#column instead.

  • @param : name (Symbol) - The name of the column
  • @param : as_name (String, nil) - An optional alias for the column
  • @param : null (Bool) - Whether the column allows null values (default: false)
  • @param : default (DB::Any) - The default value for the column (default: nil)
  • @param : unique (Bool) - Whether the column should have a unique constraint (default: false)
  • @param : size (Int32, nil) - The size of the column (default: nil)
  • @param : index (Index, nil) - The index for the column (default: nil)
  • @param : version_number (Bool) - Whether this column is used for optimistic locking (default: false)

Example

column = CQL::Column(String).new(:name)

[View source]

Instance Method Detail

def copy_to(table : Table) : BaseColumn #
Description copied from class CQL::BaseColumn

A copy of this column owned by table (used for CTEs and derived tables).


[View source]
def expression(table_alias : String | Nil) : Expression::BaseColumn #

Builds the expression qualified by a table alias (e.g. c.name for FROM customers AS c). The column's own as: name is a select-list alias, never a table qualifier, so it is not used here.


[View source]
def expression : Expression::BaseColumn #

Expressions for this column

  • @return [Expression::BaseColumn] the column expression builder

Example

column = schema.users.name
column.expression.eq("John")

[View source]
def size : Int32 | Nil #

The declared length of a String column (VARCHAR(size)); SQLite and other types ignore it.


[View source]
def strict_type #

[View source]
def type #

[View source]