mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-11 03:56:16 +00:00
LibWeb/IDB: Implement IDBObjectStore::createIndex
This commit is contained in:
parent
a235dd4300
commit
3367352991
Notes:
github-actions[bot]
2025-04-09 17:50:46 +00:00
Author: https://github.com/stelar7
Commit: 3367352991
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4178
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/AtkinsSJ
7 changed files with 88 additions and 14 deletions
|
@ -25,7 +25,7 @@ Index::Index(GC::Ref<ObjectStore> store, String name, KeyPath const& key_path, b
|
|||
, m_multi_entry(multi_entry)
|
||||
, m_key_path(key_path)
|
||||
{
|
||||
store->add_index(*this);
|
||||
store->index_set().set(name, *this);
|
||||
}
|
||||
|
||||
void Index::visit_edges(Visitor& visitor)
|
||||
|
@ -39,4 +39,13 @@ void Index::visit_edges(Visitor& visitor)
|
|||
}
|
||||
}
|
||||
|
||||
void Index::set_name(String name)
|
||||
{
|
||||
// NOTE: Update the key in the map so it still matches the name
|
||||
auto old_value = m_object_store->index_set().take(m_name).release_value();
|
||||
m_object_store->index_set().set(name, old_value);
|
||||
|
||||
m_name = move(name);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public:
|
|||
[[nodiscard]] static GC::Ref<Index> create(JS::Realm&, GC::Ref<ObjectStore>, String, KeyPath const&, bool, bool);
|
||||
virtual ~Index();
|
||||
|
||||
void set_name(String name) { m_name = move(name); }
|
||||
void set_name(String name);
|
||||
[[nodiscard]] String name() const { return m_name; }
|
||||
[[nodiscard]] bool unique() const { return m_unique; }
|
||||
[[nodiscard]] bool multi_entry() const { return m_multi_entry; }
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Variant.h>
|
||||
|
@ -37,12 +38,10 @@ public:
|
|||
bool uses_inline_keys() const { return m_key_path.has_value(); }
|
||||
bool uses_out_of_line_keys() const { return !m_key_path.has_value(); }
|
||||
Optional<KeyGenerator> key_generator() const { return m_key_generator; }
|
||||
AK::HashMap<String, GC::Ref<Index>>& index_set() { return m_indexes; }
|
||||
|
||||
GC::Ref<Database> database() const { return m_database; }
|
||||
|
||||
void add_index(GC::Ref<Index> index) { m_indexes.append(index); }
|
||||
ReadonlySpan<GC::Ref<Index>> index_set() const { return m_indexes; }
|
||||
|
||||
protected:
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
|
||||
|
@ -53,7 +52,7 @@ private:
|
|||
GC::Ref<Database> m_database;
|
||||
|
||||
// AD-HOC: An Index has referenced ObjectStores, we also need the reverse mapping
|
||||
Vector<GC::Ref<Index>> m_indexes;
|
||||
AK::HashMap<String, GC::Ref<Index>> m_indexes;
|
||||
|
||||
// An object store has a name, which is a name. At any one time, the name is unique within the database to which it belongs.
|
||||
String m_name;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue