LibWeb/IDB: Implement store_a_record_into_an_object_store

This commit is contained in:
stelar7 2025-04-11 11:38:29 +02:00 committed by Andrew Kaster
commit fb17dae42b
Notes: github-actions[bot] 2025-04-23 18:37:08 +00:00
6 changed files with 147 additions and 0 deletions

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/QuickSort.h>
#include <LibWeb/IndexedDB/IDBKeyRange.h>
#include <LibWeb/IndexedDB/Internal/ObjectStore.h>
@ -47,4 +48,23 @@ void ObjectStore::remove_records_in_range(GC::Ref<IDBKeyRange> range)
});
}
bool ObjectStore::has_record_with_key(GC::Ref<Key> key)
{
auto index = m_records.find_if([&key](auto const& record) {
return record.key == key;
});
return index != m_records.end();
}
void ObjectStore::store_a_record(Record const& record)
{
m_records.append(record);
// NOTE: The record is stored in the object stores list of records such that the list is sorted according to the key of the records in ascending order.
AK::quick_sort(m_records, [](auto const& a, auto const& b) {
return Key::compare_two_keys(a.key, b.key) < 0;
});
}
}