1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:27:43 +00:00

LibSQL: Basic dynamic value classes for SQL Storage layer

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.
This commit is contained in:
Jan de Visser 2021-06-17 13:23:52 -04:00 committed by Andreas Kling
parent a6ba05b02b
commit 2a46529170
10 changed files with 1186 additions and 5 deletions

View file

@ -0,0 +1,39 @@
/*
* 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;
}
};
}