Turn PgAttribute::Key into class instead of alias for a std::tuple.
This improves readability as the fields are now named instead of numbered.
This commit is contained in:
parent
5bdd3fa95d
commit
39927bbadf
1 changed files with 28 additions and 3 deletions
|
|
@ -21,7 +21,19 @@ public:
|
||||||
Stored
|
Stored
|
||||||
};
|
};
|
||||||
|
|
||||||
using Key = std::tuple<Oid, int16_t>;
|
class Key {
|
||||||
|
public:
|
||||||
|
Key() = default;
|
||||||
|
Key(Oid relationId, int16_t num)
|
||||||
|
: RelationId(relationId)
|
||||||
|
, Num(num)
|
||||||
|
{}
|
||||||
|
|
||||||
|
std::strong_ordering operator <=> (const Key &rhs) const = default;
|
||||||
|
private:
|
||||||
|
Oid RelationId = InvalidOid;
|
||||||
|
int16_t Num = 0;
|
||||||
|
};
|
||||||
|
|
||||||
Oid relid = InvalidOid;
|
Oid relid = InvalidOid;
|
||||||
QString name;
|
QString name;
|
||||||
|
|
@ -47,9 +59,22 @@ public:
|
||||||
QString sername, serschema; // serial sequence name and schema
|
QString sername, serschema; // serial sequence name and schema
|
||||||
QString description; ///< from pg_description
|
QString description; ///< from pg_description
|
||||||
|
|
||||||
bool operator==(Key _k) const { return relid == std::get<0>(_k) && num == std::get<1>(_k); }
|
Key key() const
|
||||||
|
{
|
||||||
|
return Key(relid, num);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::strong_ordering operator <=> (const Key& rhs) const
|
||||||
|
{
|
||||||
|
return key() <=> rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const Key &k) const
|
||||||
|
{
|
||||||
|
return key() == k;
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==(const QString &n) const { return name == n; }
|
bool operator==(const QString &n) const { return name == n; }
|
||||||
bool operator<(Key _k) const { return relid < std::get<0>(_k) || (relid == std::get<0>(_k) && num < std::get<1>(_k)); }
|
|
||||||
bool operator<(const PgAttribute &rhs) const { return relid < rhs.relid || (relid == rhs.relid && num < rhs.num); }
|
bool operator<(const PgAttribute &rhs) const { return relid < rhs.relid || (relid == rhs.relid && num < rhs.num); }
|
||||||
|
|
||||||
/// Return the part of the SQL create statement that can be reused for both the CREATE TABLE and ALTER TABLE ADD COLUMN
|
/// Return the part of the SQL create statement that can be reused for both the CREATE TABLE and ALTER TABLE ADD COLUMN
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue