forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_webstorage.h
More file actions
62 lines (49 loc) · 1.7 KB
/
node_webstorage.h
File metadata and controls
62 lines (49 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef SRC_NODE_WEBSTORAGE_H_
#define SRC_NODE_WEBSTORAGE_H_
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include <unordered_map>
#include "base_object.h"
#include "node_mem.h"
#include "sqlite3.h"
#include "util.h"
namespace node {
namespace webstorage {
struct conn_deleter {
void operator()(sqlite3* conn) const noexcept {
CHECK_EQ(sqlite3_close(conn), SQLITE_OK);
}
};
using conn_unique_ptr = std::unique_ptr<sqlite3, conn_deleter>;
struct stmt_deleter {
void operator()(sqlite3_stmt* stmt) const noexcept { sqlite3_finalize(stmt); }
};
using stmt_unique_ptr = std::unique_ptr<sqlite3_stmt, stmt_deleter>;
static constexpr std::string_view kInMemoryPath = ":memory:";
class Storage : public BaseObject {
public:
Storage(Environment* env,
v8::Local<v8::Object> object,
std::string_view location);
void MemoryInfo(MemoryTracker* tracker) const override;
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
v8::Maybe<void> Clear();
v8::MaybeLocal<v8::Array> Enumerate();
v8::MaybeLocal<v8::Value> Length();
v8::MaybeLocal<v8::Value> Load(v8::Local<v8::Name> key);
v8::MaybeLocal<v8::Value> LoadKey(const int index);
v8::Maybe<void> Remove(v8::Local<v8::Name> key);
v8::Maybe<void> Store(v8::Local<v8::Name> key, v8::Local<v8::Value> value);
std::unordered_map<std::u16string, std::u16string> GetAll();
SET_MEMORY_INFO_NAME(Storage)
SET_SELF_SIZE(Storage)
private:
v8::Maybe<void> Open();
~Storage() override;
std::string location_;
conn_unique_ptr db_;
v8::Global<v8::Map> symbols_;
};
} // namespace webstorage
} // namespace node
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#endif // SRC_NODE_WEBSTORAGE_H_