StormByte C++ Library: Database module 1.0.0
StormByte-Database is a StormByte library module for handling database connections
Loading...
Searching...
No Matches
row.hxx
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte.
5 *
6 * StormByte is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * StormByte is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with StormByte. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <StormByte/database/named_value.hxx>
23#include <StormByte/iterable.hxx>
24
25#include <unordered_map>
26#include <vector>
27#include <optional>
28
33namespace StormByte::Database {
38 class STORMBYTE_DATABASE_PUBLIC Row: public Iterable<std::vector<NamedValue>> {
39 public:
43 Row() noexcept = default;
44
49 Row(const Row& other);
50
54 Row(Row&& other) noexcept = default;
55
59 ~Row() noexcept override = default;
60
66 Row& operator=(const Row& other);
67
71 Row& operator=(Row&& other) noexcept = default;
72
79 const Value& operator[](const std::string& columnName) const &;
80
87 Value& operator[](const std::string& columnName) &;
88
95 Value operator[](const std::string& columnName) &&;
96
97 using Iterable::operator[];
98
104 inline void add(std::string&& columnName, Value&& value) {
105 m_data.emplace_back(std::move(columnName), std::move(value));
106 m_name_index.reset();
107 }
108
112 inline std::size_t Count() const noexcept {
113 return size();
114 }
115
116 private:
117 mutable std::optional<std::unordered_map<std::string, std::size_t>> m_name_index;
118
122 void BuildNameIndex() const;
123 };
124}
Single result row: ordered NamedValues with lookup by column name.
Definition row.hxx:38
std::size_t Count() const noexcept
Definition row.hxx:112
Row() noexcept=default
Type-erased SQL value (NULL, integers, double, text, blob, bool).
Definition value.hxx:39
Contains classes and functions for database operations.
Definition database.hxx:35