IDBKeyRange: lowerBound() 静的メソッド

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2021.

メモ: この機能はウェブワーカー内で利用可能です。

lowerBound()IDBKeyRange インターフェイスのメソッドで、下限のみを持つ新しいキーの範囲を生成します。既定では、端点の値を含む「閉」です。

構文

js
IDBKeyRange.lowerBound(lower)
IDBKeyRange.lowerBound(lower, open)

引数

lower

新しいキーの範囲の下限を指定します。

open 省略可

下限が端点の値を除くかどうかを表します。既定値は false です。

返値

新しく生成されたキーの範囲を表す IDBKeyRange です。

例外

DataError DOMException

引数 lower に割り当てられたキーが有効なキーでないとき投げられます。

以下の例では、下限が指定されたキーの範囲の使用法を示します。keyRangeValue = IDBKeyRange.lowerBound("F", false); と宣言します。これは、値 "F" とそれより後の全てを含む範囲です。(IDBTransaction により) トランザクションを開き、オブジェクトストアを開き、省略可能なキーの範囲の値を keyRangeValue として IDBObjectStore.openCursor でカーソルを開きます。これにより、このカーソルはキーの値が "F" のレコードと、それより後の全てのレコードのみを取得します。IDBKeyRange.lowerBound("F", true); を用いた場合、範囲に "F" は含まれず、それより後の値のみを含みます。

メモ: キーの範囲に関する実験ができるより完全な例は、IDBKeyRange-example リポジトリーを参照してください。(動く例も見る)

js
function displayData() {
  const keyRangeValue = IDBKeyRange.lowerBound("F");

  const transaction = db.transaction(["fThings"], "readonly");
  const objectStore = transaction.objectStore("fThings");

  objectStore.openCursor(keyRangeValue).onsuccess = (event) => {
    const cursor = event.target.result;
    if (cursor) {
      const listItem = document.createElement("li");
      listItem.textContent = `${cursor.value.fThing}, ${cursor.value.fRating}`;
      list.appendChild(listItem);

      cursor.continue();
    } else {
      console.log("全項目を表示しました。");
    }
  };
}

仕様書

Specification
Indexed Database API 3.0
# ref-for-dom-idbkeyrange-lowerbound①

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
lowerBound() static method

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報