Shaka Player Embedded
database.h
Go to the documentation of this file.
1 // Copyright 2016 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SHAKA_EMBEDDED_JS_IDB_DATABASE_H_
16 #define SHAKA_EMBEDDED_JS_IDB_DATABASE_H_
17 
18 #include <memory>
19 #include <string>
20 #include <vector>
21 
22 #include "shaka/optional.h"
23 #include "shaka/variant.h"
24 #include "src/core/member.h"
25 #include "src/core/ref_ptr.h"
28 #include "src/js/idb/sqlite.h"
29 #include "src/js/idb/transaction.h"
32 #include "src/mapping/struct.h"
33 
34 namespace shaka {
35 namespace js {
36 namespace idb {
37 
38 class IDBObjectStore;
39 
42 
43  ADD_DICT_FIELD(keyPath, std::string);
44  ADD_DICT_FIELD(autoIncrement, bool);
45 };
46 
49 
50  public:
51  IDBDatabase(std::shared_ptr<SqliteConnection> connection,
52  const std::string& name, int64_t version,
53  const std::vector<std::string>& store_names);
54 
55  void Trace(memory::HeapTracer* tracer) const override;
56 
57  Listener on_abort;
58  Listener on_error;
60 
61  bool is_closed() const {
62  return close_pending_;
63  }
64 
65  const std::string db_name; // JavaScript "name"
67  const int64_t version;
68 
69  ExceptionOr<RefPtr<IDBObjectStore>> CreateObjectStore(
70  const std::string& name, optional<IDBObjectStoreParameters> parameters);
71  ExceptionOr<void> DeleteObjectStore(const std::string& name);
72 
74  variant<std::string, std::vector<std::string>> store_names,
76  void Close();
77 
79  version_change_trans_ = trans;
80  }
81 
82  private:
83  Member<IDBTransaction> version_change_trans_;
84  std::shared_ptr<SqliteConnection> connection_;
85  bool close_pending_ = false;
86 };
87 
89  : public BackingObjectFactory<IDBDatabase, events::EventTarget> {
90  public:
92 };
93 
94 } // namespace idb
95 } // namespace js
96 } // namespace shaka
97 
98 #endif // SHAKA_EMBEDDED_JS_IDB_DATABASE_H_
bool is_closed() const
Definition: database.h:61
const char * name
DECLARE_STRUCT_SPECIAL_METHODS_COPYABLE(IDBObjectStoreParameters)
const int64_t version
Definition: database.h:67
Member< dom::DOMStringList > object_store_names
Definition: database.h:66
void VersionChangeTransaction(RefPtr< IDBTransaction > trans)
Definition: database.h:78
const std::string db_name
Definition: database.h:65
void Trace(memory::HeapTracer *tracer) const override
Definition: struct.cc:49
#define DECLARE_TYPE_INFO(type)