Skip to content

Migration guide from 0.x to 1.x

1999 edited this page Oct 16, 2014 · 6 revisions

DOMError

0.x

// open connection
sklad.open('dbName', function (err, conn) {
  if (err) {
    throw new Error(err);
  }

  // ...
});

// insert data
conn.insert('dbName', {foo: 'bar'}, function (err, insertedKey) {
  if (err) {
    throw new Error(err);
  }

  // ...
});

1.x

// open connection
sklad.open('dbName', function (err, conn) {
  if (err) {
    switch (err.name) {
      case 'InvalidStateError': // database is blocked
      default: // some other error
    }

    throw new Error(err.message);
  }

  // ...
});

// insert data
conn.insert('dbName', {foo: 'bar'}, function (err, insertedKey) {
  if (err) {
    switch (err.name) {
      case 'NotFoundError': // object store is missing
      case 'InvalidStateError': // passed data is invalid
      case 'ConstraintError': // same unique key
      default: // @see https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore.add#Exceptions
    }

    throw new Error(err.message);
  }

  // ...
});

skladConnection.get()

0.x

conn.get('objStoreName', {
  range: IDBKeyRange.bound('lower', 'upper', true, true),
  index: 'index_name'
}, function (err, records) {
  if (err) {
    throw new Error(err);
  }

  // records in an object with structure:
  // {
  //     key1: object1,
  //     key2: object2,
  //     ...
  // }
});

1.x

conn.get('objStoreName', {
  range: IDBKeyRange.bound('lower', 'upper', true, true),
  index: 'index_name'
}, function (err, records) {
  if (err) {
    switch (err.name) {
      // @see https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore.get#Exceptions
    }
  }

  // records in an array containing objects with structure:
  // {
  //     key: ...,
  //     value: object1
  // },
  // ...
});