mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-28 02:27:19 +02:00
LibWeb/IDB: Implement store_a_record_into_an_object_store
This commit is contained in:
Notes:
github-actions[bot]
2025-04-23 18:37:08 +00:00
Author: https://github.com/stelar7 Commit: https://github.com/LadybirdBrowser/ladybird/commit/fb17dae42ba Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4317 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/kennethmyhra ✅
@@ -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 store’s 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;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user