File indexing completed on 2025-01-05 04:47:01

0001 /***************************************************************************
0002  *   SPDX-FileCopyrightText: 2006 Tobias Koenig <tokoe@kde.org>            *
0003  *   SPDX-FileCopyrightText: 2013 Volker Krause <vkrause@kde.org>          *
0004  *                                                                         *
0005  *   SPDX-License-Identifier: LGPL-2.0-or-later                            *
0006  ***************************************************************************/
0007 
0008 #include "schematypes.h"
0009 
0010 #include <algorithm>
0011 
0012 using namespace Akonadi::Server;
0013 
0014 int TableDescription::primaryKeyColumnCount() const
0015 {
0016     return std::count_if(columns.constBegin(), columns.constEnd(), [](const ColumnDescription &col) {
0017         return col.isPrimaryKey;
0018     });
0019 }
0020 
0021 RelationTableDescription::RelationTableDescription(const RelationDescription &relation)
0022     : TableDescription()
0023 {
0024     name = relation.firstTable + relation.secondTable + QStringLiteral("Relation");
0025 
0026     columns = {ColumnDescription{.name = QStringLiteral("%1_%2").arg(relation.firstTable, relation.firstColumn),
0027                                  .type = QStringLiteral("qint64"),
0028                                  .allowNull = false,
0029                                  .isPrimaryKey = true,
0030                                  .refTable = relation.firstTable,
0031                                  .refColumn = relation.firstColumn},
0032                ColumnDescription{.name = QStringLiteral("%1_%2").arg(relation.secondTable, relation.secondColumn),
0033                                  .type = QStringLiteral("qint64"),
0034                                  .allowNull = false,
0035                                  .isPrimaryKey = true,
0036                                  .refTable = relation.secondTable,
0037                                  .refColumn = relation.secondColumn}};
0038     indexes = {IndexDescription{.name = QStringLiteral("%1Index").arg(columns[0].name), .columns = {columns[0].name}, .isUnique = false},
0039                IndexDescription{.name = QStringLiteral("%1Index").arg(columns[1].name), .columns = {columns[1].name}, .isUnique = false}};
0040     indexes += relation.indexes;
0041 }