mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 23:09:08 +00:00
This patch adds the basic dynamic value classes used by the SQL Storage layer. The most elementary class is Value, which holds a typed Value which can be converted to standard C++ types. A Tuple is a collection of Values described by a TupleDescriptor, which specifies the names, types, and ordering of the elements in the Tuple. Tuples and Values can be serialized and deserialized to and from ByteBuffers. This is mechanism which is used to save them to disk. Tuples are used as keys in SQL indexes and rows in SQL tables. Also included is a test file.
39 lines
779 B
C++
39 lines
779 B
C++
/*
|
|
* Copyright (c) 2021, Jan de Visser <jan@de-visser.net>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Vector.h>
|
|
#include <LibSQL/AST.h>
|
|
#include <LibSQL/Type.h>
|
|
|
|
namespace SQL {
|
|
|
|
struct TupleElement {
|
|
String name { "" };
|
|
SQLType type { SQLType::Text };
|
|
Order order { Order::Ascending };
|
|
|
|
bool operator==(TupleElement const&) const = default;
|
|
};
|
|
|
|
class TupleDescriptor : public Vector<TupleElement> {
|
|
public:
|
|
TupleDescriptor() = default;
|
|
TupleDescriptor(TupleDescriptor const&) = default;
|
|
~TupleDescriptor() = default;
|
|
|
|
[[nodiscard]] size_t data_length() const
|
|
{
|
|
size_t sz = sizeof(u32);
|
|
for (auto& part : *this) {
|
|
sz += size_of(part.type);
|
|
}
|
|
return sz;
|
|
}
|
|
};
|
|
|
|
}
|