Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Represents a database primary key column type.
Reference
< Object
A foreign key constraint This class represents a foreign key constraint It provides methods for setting the columns, table, and references It also provides methods for setting the on delete and on update actions
Example Creating a new foreign key
(name : Symbol, columns : Array(Symbol), table : Symbol, references : Array(Symbol), on_delete : String = "NO ACTION", on_update : String = "NO ACTION")
Cql::BaseColumn
< Reference
< Object
A column in a table This class represents a column in a table It provides methods for setting the column type, default value, and constraints It also provides methods for building expressions
Example Creating a new column
(name : Symbol, type : T.class, as_name : String | Nil = nil, null : Bool = false, default : DB::Any = nil, unique : Bool = false, size : Int32 | Nil = nil, index : Index | Nil = nil)
Create a new column instance
@param : name (Symbol) - The name of the column
@param : type (Any) - 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) - 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)
@return : Nil
@raise : Cql::Error if the column type is not valid
Example
Expressions for this column
@return [Expression::ColumnBuilder] the column expression builder
Example
(value)
Validate the value
@param value [DB::Any] The value to validate
Example
Reference
< Object
This module is part of the Cql namespace and is responsible for handling database alterations. This class represents an AlterTable object.
Example :
(table : Cql::Table, schema : Cql::Schema)
(name : Symbol, type : Any, as as_name : String | Nil = nil, null : Bool = true, 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 type [Any] 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: true)
@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)
Example Adding a new column with default options
Example Adding a new column with custom options
(name : Symbol, type : Any)
Changes the type of a column in the table.
@param name [Symbol] the name of the column to be changed
@param type [Any] the new data type for the column
Example Changing the type of a column
(name : Symbol, columns : Array(Symbol), unique : Bool = false)
Creates an index on the table.
@param name [Symbol] the name of the index
@param columns [Array(Symbol)] the columns to be indexed
@param unique [Bool] whether the index should be unique (default: false)
Example Creating an index
(column : Symbol)
Drops a column from the table.
@param column [Symbol] the name of the column to be dropped
Example Dropping a column
(name : Symbol)
Drops a foreign key from the table.
@param name [Symbol] the name of the foreign key to be dropped
Example Dropping a foreign key
(name : Symbol)
Drops an index from the table.
@param name [Symbol] the name of the index to be dropped
Example Dropping an index
(name : Symbol, columns : Array(Symbol), table : Symbol, references : Array(Symbol), on_delete : String = "NO ACTION", on_update : String = "NO ACTION")
Adds a foreign key to the table.
@param name [Symbol] the name of the foreign key
@param columns [Array(Symbol)] the columns in the current table
@param table [Symbol] the referenced table
@param references [Array(Symbol)] the columns in the referenced table
@param on_delete [String] the action on delete (default: "NO ACTION")
@param on_update [String] the action on update (default: "NO ACTION")
Example Adding a foreign key
(old_name : Symbol, new_name : Symbol)
Renames a column in the table.
@param old_name [Symbol] the current name of the column
@param new_name [Symbol] the new name for the column
Example Renaming a column
(new_name : Symbol)
Renames the table.
@param new_name [Symbol] the new name for the table
Example Renaming the table
(visitor : Expression::Visitor)
Converts the alter table actions to SQL.
@param visitor [Expression::Visitor] the visitor to generate SQL
@return [String] the generated SQL
Example Generating SQL for alter table actions
Reference
< Object
The Schema
class represents a database schema.
This class provides methods to build and manage a database schema, including creating tables, executing SQL statements, and generating queries.
Example Creating a new schema
Example Executing a SQL statement
Example Creating a new query
The Schema
class represents a database schema.
(name : Symbol, uri : String, adapter : Adapter = Adapter::Sqlite, version : String = "1.0")
Initializes a new schema.
@param name [Symbol] the name of the schema
@param uri [String] the URI of the database
@param adapter [Adapter] the database adapter (default: Adapter::Sqlite
)
@param version [String] the version of the schema (default: "1.0")
Example Initializing a new schema
(name : Symbol, uri : String, adapter : Adapter = Adapter::Sqlite, version : String = "1.0", &)
Builds a new schema.
@param name [Symbol] the name of the schema
@param uri [String] the URI of the database
@param adapter [Adapter] the database adapter (default: Adapter::Sqlite
)
@param version [String] the version of the schema (default: "1.0")
@yield [Schema] the schema being built
@return [Schema] the built schema
Example
@return [Adapter] the database adapter (default: Adapter::Sqlite
)
(table_name : Symbol, &)
Alter a table in the schema.
@param table_name [Symbol] the name of the table
@yield [AlterTable] the table being altered Example
Example
@return [DB::Connection] the database connection
Creates a new delete query for the schema.
@return [Delete] the new delete query Example
(sql : String)
Executes a SQL statement.
@param sql [String] the SQL statement to execute
Example
@return [Expression::Generator] the expression generator
Creates a new insert query for the schema.
@return [Insert] the new insert query Example
Creates a new migrator for the schema.
@return [Migrator] the new migrator Example
@return [Symbol] the name of the schema
Creates a new query for the schema.
@return [Query] the new query
Example
(name : Symbol, as as_name = nil, &)
Creates a new table in the schema.
@param name [Symbol] the name of the table
@param as_name [Symbol] the alias of the table
@yield [Table] the table being created
@return [Table] the created table Example
@return [Hash(Symbol, Table)] the tables in the schema
Creates a new update query for the schema.
@return [Update] the new update query Example
@return [String] the URI of the database
@return [String] the version of the schema
(call)
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)
Reference
< Object
An index on a table This class represents an index on a table It provides methods for setting the columns and unique constraint It also provides methods for generating the index name
Example Creating a new index
(table : Table, columns : Array(Symbol), unique : Bool = false, name : String | Nil = nil)
Create a new index instance on a table
@param : table (Table) - The table to create the index on
@param : columns (Array(Symbol)) - The columns to index
@param : unique (Bool) - Whether the index should be unique (default: false)
@param : name (String, nil) - The name of the index (default: nil)
@return : Nil
@raise : Cql::Error if the table does not exist
@raise : Cql::Error if the column does not exist
Example
Generate the index name
@return : String
@raise : Nil
Example
(name : String | Nil)
Enum
< Comparable
< Value
< Object
Represents a database adapter module.
(type) : String
Returns the SQL type for the given type. @param type [Type] the type @return [String] the SQL type Example Getting the SQL type
Cql::Column
< Cql::BaseColumn
< Reference
< Object
Primary key column definition
Example:
(name : Symbol = :id, type : PrimaryKeyType = Int64.class, as_name : String | Nil = nil, auto_increment : Bool = true, unique : Bool = true, default : DB::Any = nil)
:nodoc: