mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 13:19:05 +00:00
LibWeb/IDB: Implement store_a_record_into_an_object_store
This commit is contained in:
parent
afe7951af4
commit
fb17dae42b
Notes:
github-actions[bot]
2025-04-23 18:37:08 +00:00
Author: https://github.com/stelar7
Commit: fb17dae42b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4317
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/kennethmyhra ✅
6 changed files with 147 additions and 0 deletions
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue