firfuorida  0.0.1
Qt based database migration library
Public Member Functions | List of all members
Firfuorida::Column Class Reference

Contains information about a single column, either to creaste or to modify. More...

#include <Firfuorida/Column>

Inheritance diagram for Firfuorida::Column:
Inheritance graph
[legend]

Public Member Functions

 ~Column () override
 Deconstructs the Column object. More...
 
void after (const QString &otherColumn)
 Put/move this column after otherColumn. More...
 
ColumnautoIncrement (bool autoIncrement=true)
 Enables or disables the auto increment feature for this column. More...
 
void change ()
 Mark this column as a column to change instead of creating it. More...
 
Columncharset (const QString &charset)
 Sets the character set used for this column. More...
 
Columncollation (const QString &collation)
 Sets the collation used for this column. More...
 
Columncomment (const QString &comment)
 Add a comment to the column. More...
 
ColumndefaultValue (const QVariant &defVal)
 Sets the default value for this column. More...
 
void first ()
 Add/move this column to the beginning as first column. More...
 
Columnnullable (bool isNullable=true)
 Sets the columns to nullable or not. More...
 
ColumnonDelete (const QString &referenceOption)
 Adds the onDelete action to a foreign key column. More...
 
ColumnonUpdate (const QString &referenceOption)
 Adds the onUpdate action to a foreign key column. More...
 
Columnprimary (bool primary=true)
 Makes the column a primary key column or not. More...
 
Columnunique (bool unique=true)
 Makes the column a unique key column or not. More...
 
ColumnunSigned (bool unSigned=true)
 Sets the column to signed or unsigned. More...
 

Detailed Description

Contains information about a single column, either to creaste or to modify.

The Column object can only be created by functions of the Table class.

Example

example.cpp

/*
* SPDX-FileCopyrightText: (C) 2019-2022 Matthias Fehring <https://www.huessenbergnetz.de>
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include "example.h"
M20190121T174100_Example::M20190121T174100_Example(Firfuorida::Migrator *parent) :
Firefuorida::Migration(parent)
{
}
M20190121T174100_Example::~M20190121T174100_Example()
{
}
void M20190121T174100_Example::up()
{
// create a new table named "ExampleTable" if it not already exists
auto t = createTableIfNotExists(QStringLiteral("ExampleTable"));
// create a new unsigned tiny integer column on that table with the
// default name "id" and auto incrementation enabled
t->tinyIncrements();
// create a new signed tiny integer column on that table with the
// name "tinyIntCol" and UNIQUE KEY index.
t->tinyInteger(QStringLiteral("tinyIntCol"))->unique();
// create a new nullable tiny blob column on that table with the name
// "tinyBlobCol"
t->tinyBlob(QStringLiteral("tinyBlobCol"))->nullable();
// create a new tiny text column on that table with the name "tinyTextCol"
// and the default value "foobar"
t->tinyText(QStringLiteral("tinyTextCol"))->defaultValue(QStringLiteral("foobar"));
}
void M20190121T174100_Example::down()
{
// drop the table named "ExampleTable" if it exists
dropIfExists(QStringLiteral("ExampleTable"));
}

Constructor & Destructor Documentation

◆ ~Column()

Column::~Column ( )
overridedefault

Deconstructs the Column object.

Member Function Documentation

◆ after()

void Column::after ( const QString otherColumn)

Put/move this column after otherColumn.

◆ autoIncrement()

Column * Column::autoIncrement ( bool  autoIncrement = true)

Enables or disables the auto increment feature for this column.

◆ change()

void Column::change ( )

Mark this column as a column to change instead of creating it.

◆ charset()

Column * Column::charset ( const QString charset)

Sets the character set used for this column.

◆ collation()

Column * Column::collation ( const QString collation)

Sets the collation used for this column.

◆ comment()

Column * Column::comment ( const QString comment)

Add a comment to the column.

Note
The maximum size for a column comment on MySQL/MariaDB is 1024 characters.

◆ defaultValue()

Column * Column::defaultValue ( const QVariant defVal)

Sets the default value for this column.

◆ first()

void Column::first ( )

Add/move this column to the beginning as first column.

◆ nullable()

Column * Column::nullable ( bool  isNullable = true)

Sets the columns to nullable or not.

◆ onDelete()

Column * Column::onDelete ( const QString referenceOption)

Adds the onDelete action to a foreign key column.

◆ onUpdate()

Column * Column::onUpdate ( const QString referenceOption)

Adds the onUpdate action to a foreign key column.

◆ primary()

Column * Column::primary ( bool  primary = true)

Makes the column a primary key column or not.

◆ unique()

Column * Column::unique ( bool  unique = true)

Makes the column a unique key column or not.

◆ unSigned()

Column * Column::unSigned ( bool  unSigned = true)

Sets the column to signed or unsigned.