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:
parent
267eb3b329
commit
87bd69559f
7 changed files with 511 additions and 0 deletions
52
Userland/Libraries/LibSQL/Row.cpp
Normal file
52
Userland/Libraries/LibSQL/Row.cpp
Normal 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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue