CQL
AzuAuthorityGithub
  • README
  • Introduction
  • Installation
  • Core Concepts
    • Schema Definition
    • Inisitalizing Schema
    • Altering Schema
    • Migrations
    • CRUD Operations
      • Creating Records
      • Reading Records
      • Updating Records
      • Deleting Records
    • Patterns
      • Active Record
      • Entity Framework
      • Repository
  • API
    • enum CQL::Adapter
    • class CQL::AlterTable
    • class CQL::Column(T)
    • class CQL::Delete
    • class CQL::Error
    • class CQL::ForeignKey
    • class CQL::Insert
    • class CQL::Migration
      • MigrationRecord
      • Migrator
    • class CQL::Migrator
    • class CQL::PrimaryKey(T)
    • alias CQL::PrimaryKeyType
    • class CQL::Query
    • module CQL::Record(Pk)
    • module CQL::Relations
      • module CQL::Relations::BelongsTo
      • class CQL::Relations::Collection(Target, Pk)
      • module CQL::Relations::HasMany
      • module CQL::Relations::HasOne
      • module CQL::Relations::ManyToMany
      • class CQL::Relations::ManyCollection(Target, Through, Pk)
      • Relations
    • class CQL::Repository(T, Pk)
    • class CQL::Schema
    • class CQL::Table
    • class CQL::Update
    • class CQL::Index
  • Guides
    • Active Record
      • Record Models
      • Belongs To
      • Has Many
      • Has One
      • Many To Many
    • Getting Started
    • Complex Queries
    • Transaction Management
    • Handling Migrations
  • Troubleshooting
  • FAQs
Powered by GitBook
On this page
  • Example: Creating a Table
  • Methods
  • def new(name : Symbol, schema : Schema)
  • def column(name : Symbol, type : Type, primary : Bool = false)
  • def create_sql
  • def drop

Was this helpful?

Export as PDF
  1. API

class CQL::Table

Reference < Object

The CQL::Table class represents a table in the database and is responsible for handling table creation, modification, and deletion.

Example: Creating a Table

table = Table.new(:users, schema)
table.column(:id, Int64, primary: true)
table.column(:name, String)
table.create_sql
# => "CREATE TABLE users (id BIGINT PRIMARY KEY, name TEXT);"

Methods

def new(name : Symbol, schema : Schema)

Initializes a new table with the specified name and schema.

  • @param name [Symbol] The name of the table.

  • @param schema [Schema] The schema to which the table belongs.

  • @return [Table] The created table object.

Example:

table = Table.new(:users, schema)

def column(name : Symbol, type : Type, primary : Bool = false)

Defines a column for the table.

  • @param name [Symbol] The name of the column.

  • @param type [Type] The data type of the column.

  • @param primary [Bool] Whether the column is the primary key (default: false).

  • @return [Table] The updated table object.

Example:

table.column(:id, Int64, primary: true)
table.column(:name, String)

def create_sql

Generates the SQL statement to create the table.

  • @return [String] The SQL CREATE TABLE statement.

Example:

table.create_sql
# => "CREATE TABLE users (id BIGINT PRIMARY KEY, name TEXT);"

def drop

Drops the table from the database.

  • @return [String] The SQL DROP TABLE statement.

Example:

table.drop
# => "DROP TABLE users;"
Previousclass CQL::SchemaNextclass CQL::Update

Was this helpful?