From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/ja/web/api/idbdatabase/index.html | 196 ++++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 files/ja/web/api/idbdatabase/index.html (limited to 'files/ja/web/api/idbdatabase/index.html') diff --git a/files/ja/web/api/idbdatabase/index.html b/files/ja/web/api/idbdatabase/index.html new file mode 100644 index 0000000000..784422a490 --- /dev/null +++ b/files/ja/web/api/idbdatabase/index.html @@ -0,0 +1,196 @@ +--- +title: IDBDatabase +slug: Web/API/IDBDatabase +tags: + - API + - Database + - IDBDatabase + - IndexedDB + - Storage + - transactions +translation_of: Web/API/IDBDatabase +--- +

{{APIRef()}}

+
+

IndexedDB APIのIDBDatabaseインターフェイスは、データベースへの接続を提供します。 IDBDatabaseオブジェクトで、データベースのtransactionを開き、データベースのオブジェクト(データ)を生成したり、操作したり、削除したりできます。このインターフェイスはデータベースのバージョンを取得したり、統合したりする唯一の方法を提供します。

+
+
+

Note: Everything you do in IndexedDB always happens in the context of a transaction, representing interactions with data in the database. All objects in IndexedDB — including object stores, indexes, and cursors — are tied to a particular transaction. Thus, you cannot execute commands, access data, or open anything outside of a transaction.

+
+

メソッド

+

Inherits from: EventTarget

+
+
+ {{domxref("IDBDatabase.close")}}
+
+ 即座に応答して、別スレッドでデータベースを閉じる。
+
+ {{domxref("IDBDatabase.createObjectStore")}}
+
+ 新しくオブジェクトストアかインデックスを生成して返す。
+
+ {{domxref("IDBDatabase.deleteObjectStore")}}
+
+ 参照しているインデックスがあったとしても、接続中のデータベースで与えられた名前のオブジェクトストアを削除する。
+
+ {{domxref("IDBDatabase.transaction")}}
+
+ オブジェクトストアにアクセスできる{{domxref("IDBTransaction.objectStore")}}メソッドを含むトランザクションオブジェクト ({{domxref("IDBTransaction")}})を即座に返す。別スレッドで実行される。
+
+

プロパティ

+
+
+ {{domxref("IDBDatabase.name")}} {{readonlyInline}}
+
+ 接続しているデータベース名を含む{{ domxref("DOMString") }} 。
+
+ {{domxref("IDBDatabase.version")}} {{readonlyInline}}
+
+ 接続しているデータベースのバージョンを含む64-bit integer。データベースが初めて作られた場合、この属性は空文字である。
+
+ {{domxref("IDBDatabase.objectStoreNames")}} {{readonlyInline}}
+
+ 接続しているデータベースのobject stores名のリストを含む{{ domxref("DOMStringList") }} 。
+
+

イベントハンドラ

+
+
+ {{domxref("IDBDatabase.onabort")}}
+
+ データベースの接続が中止された場合に発生する。
+
+ {{domxref("IDBDatabase.onerror")}}
+
+ データベースへの接続が失敗した場合に発生する。
+
+ {{domxref("IDBDatabase.onversionchange")}}
+
+

データベースの構造が({{domxref("IDBOpenDBRequest.onupgradeneeded")}}イベントで変更されるか、{{domxref("IDBFactory.deleteDatabase")}} がどこかで(ほとんどの場合、同じコンピューターの他のウィンドウやタブで)要求された場合に発生します。これはversion change transaction (see {{domxref("IDBVersionChangeEvent")}})とは異なりますが、関連があります。

+
+
+

+

次のコードスニペットでは、データベースを非同期で開き({{domxref("IDBFactory")}})、成功と失敗の場合にイベントを登録し、アップグレードが必要な場合には、新しいオブジェクトストアを生成しています({{ domxref("IDBdatabase") }})。 完璧に動作する例は、 To-do Notifications app (view example live.)を見てください。

+
// Let us open our database
+  var DBOpenRequest = window.indexedDB.open("toDoList", 4);
+
+  // these two event handlers act on the IDBDatabase object, when the database is opened successfully, or not
+  DBOpenRequest.onerror = function(event) {
+    note.innerHTML += '<li>Error loading database.</li>';
+  };
+
+  DBOpenRequest.onsuccess = function(event) {
+    note.innerHTML += '<li>Database initialised.</li>';
+
+    // store the result of opening the database in the db variable. This is used a lot later on
+    db = DBOpenRequest.result;
+
+    // Run the displayData() function to populate the task list with all the to-do list data already in the IDB
+    displayData();
+  };
+
+  // This event handles the event whereby a new version of the database needs to be created
+  // Either one has not been created before, or a new version number has been submitted via the
+  // window.indexedDB.open line above
+
+  DBOpenRequest.onupgradeneeded = function(event) {
+    var db = event.target.result;
+
+    db.onerror = function(event) {
+      note.innerHTML += '<li>Error loading database.</li>';
+    };
+
+    // Create an objectStore for this database using IDBDatabase.createObjectStore
+
+    var objectStore = db.createObjectStore("toDoList", { keyPath: "taskTitle" });
+
+    // define what data items the objectStore will contain
+
+    objectStore.createIndex("hours", "hours", { unique: false });
+    objectStore.createIndex("minutes", "minutes", { unique: false });
+    objectStore.createIndex("day", "day", { unique: false });
+    objectStore.createIndex("month", "month", { unique: false });
+    objectStore.createIndex("year", "year", { unique: false });
+
+    objectStore.createIndex("notified", "notified", { unique: false });
+
+    note.innerHTML += '<li>Object store created.</li>';
+  };
+

次の行は、データベースでトランザクションを開いて、そしてオブジェクトストアを開いて、内側のデータを操作しています。

+
    var objectStore = db.transaction('toDoList').objectStore('toDoList'); 
+

仕様

+ + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('IndexedDB', '#idl-def-IDBDatabase', 'IDBDatabase')}}{{Spec2('IndexedDB')}} 
+

ブラウザ実装状況

+
+ {{CompatibilityTable}}
+
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support23{{property_prefix("webkit")}}
+ 24
10 {{property_prefix("moz")}}
+ {{CompatGeckoDesktop("16.0")}}
10, partial157.1
+
+
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari Mobile
Basic support4.4{{CompatGeckoMobile("22.0")}}1.0.11022{{CompatNo}}
+
+

関連情報

+ +

 

-- cgit v1.2.3-54-g00ecf