Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

indexedDb can save only Map type. The limitation is not described in Dart API. #17371

Closed
DartBot opened this issue Mar 10, 2014 · 5 comments
Closed
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-obsolete Closed as the reported issue is no longer relevant docs-api library-html P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@DartBot
Copy link

DartBot commented Mar 10, 2014

This issue was originally filed by igor.ko...@mailvision.com


indexedDB can store object in Map form, but cannot store object instance.
The limitation is not described in dart API.

What steps will reproduce the problem?
start the Web program (as dart or as javascript), and see console log.

------------ web application ------------------------
import 'dart:html';
import 'dart:indexed_db';

class Record {
  List<int> data;
  String str;
  double value;
  Record(this.data, this.str, this.value);
  Map toMap()=>{"data":data, "str":str, "value":value };
}

void main(){
  Record record = new Record([1,2,3], "Hello", 5.7);
  
  Database db;
  IdbFactory idb = window.indexedDB;
  idb.open("test_db", version: 1, onUpgradeNeeded: onUpgradeNeeded)
  .then((Database v){
    db = v;
  })
  .then((){
    print("put1");
    Transaction trn = db.transaction("store_one", "readwrite");
    ObjectStore st = trn.objectStore("store_one");
    return st.put(record.toMap(), "key1"); /// It's OK.
  })
  .then((
){
    print("put2");
    Transaction trn = db.transaction("store_one", "readwrite");
    ObjectStore st = trn.objectStore("store_one");
    return st.put(record, "key2"); /// !!!!!!!!!!!!! Exception !!!!!!!!!!!!!!
  });
}

void onUpgradeNeeded(VersionChangeEvent vce){
  print("onUpgradeNeeded");
  Database db = (vce.target as OpenDBRequest).result;
  if( vce.oldVersion == 0 ){
    db.createObjectStore("store_one");
  }
}

--------------- console log (dartium) ------------------------------

put1
put2
Uncaught Error: unsupported object type for conversion


As you can see in console log, or checking result DB in Chrome dev tools/resources:
data in Map form successfully inserted,
the same data throw exception, then put() called with class instance.


@DartBot
Copy link
Author

DartBot commented Mar 10, 2014

This comment was originally written by igor.ko...@mailvision.com


Not only Map, but also String and numbers can be used as record.

store.put("hello", "key2"); /// It's OK
store.put(15, "key3"); /// It's OK
store.put(5.7, "key4"); /// It's OK

   

@kasperl
Copy link

kasperl commented Mar 12, 2014

Added Area-HTML, Triaged labels.

@kevmoo
Copy link
Member

kevmoo commented Apr 7, 2014

Removed Area-HTML label.
Added Area-Library, Library-Html labels.

@efortuna
Copy link
Contributor

documentation bug


Removed Priority-Unassigned label.
Added Priority-Low, Community-StarterBug labels.

@alan-knight
Copy link
Contributor

Assuming this is just a docs issue, but possibly it ought to be able to do it.


Added Docs-API label.

@DartBot DartBot added Type-Defect P3 A lower priority bug or feature request area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-html docs-api labels Jan 13, 2015
@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed triaged labels Mar 1, 2016
@matanlurey matanlurey added the closed-obsolete Closed as the reported issue is no longer relevant label Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-obsolete Closed as the reported issue is no longer relevant docs-api library-html P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

7 participants