summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibSQL/Row.h
blob: fcd4cc3da99f10bd8f6dec7a076779904fb8efb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
 * Copyright (c) 2021, Jan de Visser <jan@de-visser.net>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/NonnullRefPtr.h>
#include <LibSQL/Forward.h>
#include <LibSQL/Meta.h>
#include <LibSQL/Tuple.h>
#include <LibSQL/Value.h>

namespace SQL {

/**
 * A Tuple is an element of a sequential-access persistence data structure
 * like a flat table. Like a key it has a definition for all its parts,
 * but unlike a key this definition is not optional.
 *
 * FIXME Tuples should logically belong to a TupleStore object, but right now
 * they stand by themselves; they contain a row's worth of data and a pointer
 * to the next Tuple.
 */
class Row : public Tuple {
public:
    explicit Row(NonnullRefPtr<TableDef>, Block::Index block_index = 0);
    virtual ~Row() override = default;

    [[nodiscard]] Block::Index next_block_index() const { return m_next_block_index; }
    void set_next_block_index(Block::Index index) { m_next_block_index = index; }

    TableDef const& table() const { return *m_table; }
    TableDef& table() { return *m_table; }

    [[nodiscard]] virtual size_t length() const override { return Tuple::length() + sizeof(Block::Index); }
    virtual void serialize(Serializer&) const override;
    virtual void deserialize(Serializer&) override;

private:
    NonnullRefPtr<TableDef> m_table;
    Block::Index m_next_block_index { 0 };
};

}