1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:18:13 +00:00

LibSQL: Database layer

This patch implements the beginnings of a database API allowing for the
creation of tables, inserting rows in those tables, and retrieving those
rows.
This commit is contained in:
Jan de Visser 2021-06-17 14:12:46 -04:00 committed by Andreas Kling
parent 267eb3b329
commit 87bd69559f
7 changed files with 511 additions and 0 deletions

View file

@ -0,0 +1,52 @@
/*
* Copyright (c) 2021, Jan de Visser <jan@de-visser.net>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibSQL/Meta.h>
#include <LibSQL/Row.h>
#include <LibSQL/Serialize.h>
#include <LibSQL/Tuple.h>
namespace SQL {
Row::Row()
: Tuple()
{
}
Row::Row(TupleDescriptor const& descriptor)
: Tuple(descriptor)
{
}
Row::Row(RefPtr<TableDef> table)
: Tuple(table->to_tuple_descriptor())
, m_table(table)
{
}
Row::Row(RefPtr<TableDef> table, u32 pointer, ByteBuffer& buffer)
: Tuple(table->to_tuple_descriptor())
{
// FIXME Sanitize constructor situation in Tuple so this can be better
size_t offset = 0;
deserialize(buffer, offset);
deserialize_from<u32>(buffer, offset, m_next_pointer);
set_pointer(pointer);
}
void Row::serialize(ByteBuffer& buffer) const
{
Tuple::serialize(buffer);
serialize_to<u32>(buffer, next_pointer());
}
void Row::copy_from(Row const& other)
{
Tuple::copy_from(other);
m_next_pointer = other.next_pointer();
}
}