Skip to content

Latest commit

 

History

History
80 lines (61 loc) · 3.08 KB

File metadata and controls

80 lines (61 loc) · 3.08 KB

IDBObjectStoreCreateIndexOptions

Namespace: SpawnDev.SpawnJS.JSObjects
Source: JSObjects/IDBObjectStoreCreateIndexOptions.cs
MDN Reference: IDBObjectStoreCreateIndexOptions on MDN

Options for IDBObjectStore.CreateIndex https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/createIndex#options

Properties

Property Type Access Description
IDBObjectStoreCreateIndexOptions class get Options for IDBObjectStore.CreateIndex https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/createIndex#options
MultiEntry bool? get

Examples

SpawnDev.SpawnJS Mapping Note: The JavaScript examples below show the standard Web API usage. In SpawnDev.SpawnJS, the same API is available with C# conventions:

  • Properties and methods use PascalCase (e.g., readyState becomes ReadyState)
  • Events use ActionEvent with +=/-= (e.g., addEventListener("click", fn) becomes OnClick += handler)
  • Async methods return Task<T> instead of Promise<T>
  • Objects should be disposed with using statements
  • Access via JS.Get<IDBObjectStoreCreateIndexOptions>(...) or constructor new IDBObjectStoreCreateIndexOptions(...)
let db;

// Let us open our database
const DBOpenRequest = window.indexedDB.open("toDoList", 4);

// Two event handlers for opening the database.
DBOpenRequest.onerror = (event) => {
  note.appendChild(document.createElement("li")).textContent =
    "Error loading database.";
};

DBOpenRequest.onsuccess = (event) => {
  note.appendChild(document.createElement("li")).textContent =
    "Database initialized.";

  // store the result of opening the database in the db variable.
  // This is used a lot below.
  db = request.result;

  // Run the displayData() function to populate the task list with
  // all the to-do list data already in the IDB
  displayData();
};

// This handler fires when a new database is created and indicates
// either that one has not been created before, or a new version
// was submitted with window.indexedDB.open(). (See above.)
// It is only implemented in recent browsers.
DBOpenRequest.onupgradeneeded = (event) => {
  const db = event.target.result;

  db.onerror = (event) => {
    note.appendChild(document.createElement("li")).textContent =
      "Error loading database.";
  };

  // Create an objectStore for this database
  const 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 });
};

See full example on MDN