Reference
< Object
Represents a table in the database. This class is responsible for handling table creation, modification, and deletion.
(table_name : Symbol, schema : Schema, as_name : String | Nil = nil)
(columns : Array(Symbol), unique : Bool = false, table : Table = self)
Adds a new column to the table.
@param columns [Array(Symbol)] the columns to be indexed
@param unique [Bool] whether the index should be unique (default: false)
@param table [Table] the table to add the index to (default: self)
@return [Index] the new index
Example Adding a new index
(name : Symbol, as as_name : String | Nil = nil, null : Bool = false, default : DB::Any = nil, unique : Bool = false, index : Bool = false)
Adds a new column to the table.
@param name [Symbol] the name of the column to be added
@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, nil] the default value for the column (default: nil)
@param unique [Bool] whether the column should have a unique constraint (default: false)
@param index [Bool] whether the column should be indexed (default: false)
@return [Column] the new column
Example Adding a new column with default options
(name : Symbol, as as_name : String | Nil = nil, null : Bool = false, default : DB::Any = nil, unique : Bool = false, size : Int32 | Nil = nil, index : Bool = false)
Adds a new column to the table.
@param name [Symbol] the name of the column to be added
@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, nil] the default value for the column (default: nil)
@param unique [Bool] whether the column should have a unique constraint (default: false)
@param index [Bool] whether the column should be indexed (default: false)
@return [Column] the new column
Example Adding a new column with default options
(name : Symbol, as as_name : String | Nil = nil, null : Bool = false, default : DB::Any = nil, unique : Bool = false, index : Bool = false)
Adds a new column to the table.
@param name [Symbol] the name of the column to be added
@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, nil] the default value for the column (default: nil)
@param unique [Bool] whether the column should have a unique constraint (default: false)
@param index [Bool] whether the column should be indexed (default: false)
@return [Column] the new column
Example Adding a new column with default options
(name : Symbol, type : T.class, as as_name : String | Nil = nil, null : Bool = false, default : DB::Any = nil, unique : Bool = false, size : Int32 | Nil = nil, index : Bool = false) forall T
Adds a new column to the table.
@param name [Symbol] the name of the column to be added
@param type [T.class] the data type 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, nil] 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 [Bool] whether the column should be indexed (default: false)
@return [Column] the new column
Example Adding a new column with default options
Creates the table in the database.
@return [Nil]
Example
Generates the SQL to create the table.
Example
(name : Symbol, as as_name : String | Nil = nil, null : Bool = false, default : DB::Any = nil, unique : Bool = false, index : Bool = false)
Adds a new column to the table.
@param name [Symbol] the name of the column to be added
@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, nil] the default value for the column (default: nil)
@param unique [Bool] whether the column should have a unique constraint (default: false)
@param index [Bool] whether the column should be indexed (default: false)
@return [Column] the new column
Example Adding a new column with default options
(name : Symbol, as as_name : String | Nil = nil, null : Bool = false, default : DB::Any = nil, unique : Bool = false, index : Bool = false)
Adds a new column to the table.
@param name [Symbol] the name of the column to be added
@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, nil] the default value for the column (default: nil)
@param unique [Bool] whether the column should have a unique constraint (default: false)
@param index [Bool] whether the column should be indexed (default: false)
@return [Column] the new column
Example Adding a new column with default options
Drops the table from the database.
@return [Nil]
Example
Generates the SQL to drop the table.
@return [String] the SQL query
Example
Gets table expression for Sql query generation
@return [Expression::Table] the table expression
Example
(name : Symbol, as as_name : String | Nil = nil, null : Bool = false, default : DB::Any = nil, unique : Bool = false, index : Bool = false)
Adds a new column to the table.
@param name [Symbol] the name of the column to be added
@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, nil] the default value for the column (default: nil)
@param unique [Bool] whether the column should have a unique constraint (default: false)
@param index [Bool] whether the column should be indexed (default: false)
@return [Column] the new column
Example Adding a new column with default options
(name : Symbol, as as_name : String | Nil = nil, null : Bool = false, default : DB::Any = nil, unique : Bool = false, index : Bool = false)
Adds a new column to the table.
@param name [Symbol] the name of the column to be added
@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, nil] the default value for the column (default: nil)
@param unique [Bool] whether the column should have a unique constraint (default: false)
@param index [Bool] whether the column should be indexed (default: false)
@return [Column] the new column
Example Adding a new column with default options
(name : Symbol, as as_name : String | Nil = nil, null : Bool = false, default : DB::Any = nil, unique : Bool = false, index : Bool = false)
Adds a new column to the table.
@param name [Symbol] the name of the column to be added
@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, nil] the default value for the column (default: nil)
@param unique [Bool] whether the column should have a unique constraint (default: false)
@param index [Bool] whether the column should be indexed (default: false)
@return [Column] the new column
Example Adding a new column with default options
(name : Symbol = :id, type : T.class = Int64, auto_increment : Bool = true, as as_name = nil, unique : Bool = true) forall T
Adds a new column to the table.
@param name [Symbol] the name of the column to be added
@param type [Any] the data type of the column
@param auto_increment [Bool] whether the column should auto increment (default: true)
@param as_name [String, nil] an optional alias for the column
@param unique [Bool] whether the column should have a unique constraint (default: true)
Example Adding a new primary key column
(table_name : Symbol)
(name : Symbol, as as_name : String | Nil = nil, null : Bool = false, default : DB::Any = nil, unique : Bool = false, size : Int32 | Nil = nil, index : Bool = false)
Adds a new column to the table.
@param name [Symbol] the name of the column to be added
@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, nil] the default value for the column (default: nil)
@param unique [Bool] whether the column should have a unique constraint (default: false)
@param index [Bool] whether the column should be indexed (default: false)
@return [Column] the new column
Example Adding a new column with default options
(name : Symbol, as as_name : String | Nil = nil, null : Bool = false, default : DB::Any = nil, unique : Bool = false, index : Bool = false)
Adds a new column to the table.
@param name [Symbol] the name of the column to be added
@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, nil] the default value for the column (default: nil)
@param unique [Bool] whether the column should have a unique constraint (default: false)
@param index [Bool] whether the column should be indexed (default: false)
@return [Column] the new column
Example Adding a new column with default options
Adds a new column to the table.
Example Adding timestamps to the table
Truncates the table in the database.
@return [Nil]
Example
Generates the SQL to truncate the table.
@return [String] the SQL query
Example
(call)