firfuorida 0.0.1
Qt based database migration library
Loading...
Searching...
No Matches
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:

Public Member Functions

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

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()
{
}
{
// 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"));
}
{
// drop the table named "ExampleTable" if it exists
dropIfExists(QStringLiteral("ExampleTable"));
}
Contains a single migration instance.
Definition migration.h:46
void dropIfExists(const QString &tableName)
Drops the table identified by tableName if it exists.
Definition migration.cpp:150
Table * createTableIfNotExists(const QString &tableName)
Creates a new table with the given tableName if it not exists already.
Definition migration.cpp:124
virtual void up()=0
Reimplement this function to perform database operations when performing migrations.
virtual void down()=0
Reimplement this function to perform database operations when performing migration rollback.
Manages multiple migrations.
Definition migrator.h:40
QObject * parent() const const

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.