class
CQL::Column(Type)
- CQL::Column(Type)
- CQL::BaseColumn
- Reference
- Object
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.crConstructors
-
.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)).
Instance Method Summary
-
#copy_to(table : Table) : BaseColumn
A copy of this column owned by table (used for CTEs and derived tables).
-
#expression(table_alias : String | Nil) : Expression::BaseColumn
Builds the expression qualified by a table alias (e.g.
-
#expression : Expression::BaseColumn
Expressions for this column - @return [Expression::BaseColumn] the column expression builder
-
#size : Int32 | Nil
The declared length of a String column (
VARCHAR(size)); SQLite and other types ignore it. - #strict_type
- #type
Instance methods inherited from class CQL::BaseColumn
copy_to(table : Table) : BaseColumn
copy_to
Constructor Detail
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)
Instance Method Detail
A copy of this column owned by table (used for CTEs and derived tables).
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.
Expressions for this column
- @return [Expression::BaseColumn] the column expression builder
Example
column = schema.users.name
column.expression.eq("John")
The declared length of a String column (VARCHAR(size)); SQLite and other types ignore it.