mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 16:35:08 +00:00
LibSQL: Use Block::Index
everywhere; rename pointer
to block_index
No functional changes.
This commit is contained in:
parent
6601ff9d65
commit
fdac8331cc
19 changed files with 202 additions and 203 deletions
|
@ -158,7 +158,7 @@ ResultOr<NonnullRefPtr<TableDef>> Database::get_table(DeprecatedString const& sc
|
|||
|
||||
auto schema_def = TRY(get_schema(schema));
|
||||
auto table_def = TableDef::construct(schema_def, name);
|
||||
table_def->set_pointer((*table_iterator).pointer());
|
||||
table_def->set_block_index((*table_iterator).block_index());
|
||||
m_table_cache.set(key.hash(), table_def);
|
||||
|
||||
auto table_hash = table_def->hash();
|
||||
|
@ -173,8 +173,8 @@ ErrorOr<Vector<Row>> Database::select_all(TableDef& table)
|
|||
{
|
||||
VERIFY(m_table_cache.get(table.key().hash()).has_value());
|
||||
Vector<Row> ret;
|
||||
for (auto pointer = table.pointer(); pointer; pointer = ret.last().next_pointer())
|
||||
ret.append(m_serializer.deserialize_block<Row>(pointer, table, pointer));
|
||||
for (auto block_index = table.block_index(); block_index; block_index = ret.last().next_block_index())
|
||||
ret.append(m_serializer.deserialize_block<Row>(block_index, table, block_index));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -185,11 +185,11 @@ ErrorOr<Vector<Row>> Database::match(TableDef& table, Key const& key)
|
|||
|
||||
// TODO Match key against indexes defined on table. If found,
|
||||
// use the index instead of scanning the table.
|
||||
for (auto pointer = table.pointer(); pointer;) {
|
||||
auto row = m_serializer.deserialize_block<Row>(pointer, table, pointer);
|
||||
for (auto block_index = table.block_index(); block_index;) {
|
||||
auto row = m_serializer.deserialize_block<Row>(block_index, table, block_index);
|
||||
if (row.match(key))
|
||||
ret.append(row);
|
||||
pointer = ret.last().next_pointer();
|
||||
block_index = ret.last().next_block_index();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -199,16 +199,16 @@ ErrorOr<void> Database::insert(Row& row)
|
|||
VERIFY(m_table_cache.get(row.table().key().hash()).has_value());
|
||||
// TODO: implement table constraints such as unique, foreign key, etc.
|
||||
|
||||
row.set_pointer(m_heap->request_new_block_index());
|
||||
row.set_next_pointer(row.table().pointer());
|
||||
row.set_block_index(m_heap->request_new_block_index());
|
||||
row.set_next_block_index(row.table().block_index());
|
||||
TRY(update(row));
|
||||
|
||||
// TODO update indexes defined on table.
|
||||
|
||||
auto table_key = row.table().key();
|
||||
table_key.set_pointer(row.pointer());
|
||||
table_key.set_block_index(row.block_index());
|
||||
VERIFY(m_tables->update_key_pointer(table_key));
|
||||
row.table().set_pointer(row.pointer());
|
||||
row.table().set_block_index(row.block_index());
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -217,25 +217,25 @@ ErrorOr<void> Database::remove(Row& row)
|
|||
auto& table = row.table();
|
||||
VERIFY(m_table_cache.get(table.key().hash()).has_value());
|
||||
|
||||
if (table.pointer() == row.pointer()) {
|
||||
if (table.block_index() == row.block_index()) {
|
||||
auto table_key = table.key();
|
||||
table_key.set_pointer(row.next_pointer());
|
||||
table_key.set_block_index(row.next_block_index());
|
||||
m_tables->update_key_pointer(table_key);
|
||||
|
||||
table.set_pointer(row.next_pointer());
|
||||
table.set_block_index(row.next_block_index());
|
||||
return {};
|
||||
}
|
||||
|
||||
for (auto pointer = table.pointer(); pointer;) {
|
||||
auto current = m_serializer.deserialize_block<Row>(pointer, table, pointer);
|
||||
for (auto block_index = table.block_index(); block_index;) {
|
||||
auto current = m_serializer.deserialize_block<Row>(block_index, table, block_index);
|
||||
|
||||
if (current.next_pointer() == row.pointer()) {
|
||||
current.set_next_pointer(row.next_pointer());
|
||||
if (current.next_block_index() == row.block_index()) {
|
||||
current.set_next_block_index(row.next_block_index());
|
||||
TRY(update(current));
|
||||
break;
|
||||
}
|
||||
|
||||
pointer = current.next_pointer();
|
||||
block_index = current.next_block_index();
|
||||
}
|
||||
|
||||
return {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue