2

I'm an SQL person but I've now started programming offline apps in Dart and using IndexedDB seems to be the recommended method of storing local data. I'm using LawnDart to work with these IndexedDB databases and generating my own unique key (just a unix timestamp) and storing the data in the value column as a JSON string.

My question is how do I then order this data by a column contained in the JSON string? Or am I using this database in the wrong way entirely?

Cheers!

Deni Spasovski
  • 4,004
  • 3
  • 35
  • 52
trvo
  • 665
  • 1
  • 10
  • 23

2 Answers2

1

I think what you want is WebSQL (which uses SQLite).

  • IndexedDB in Dart

    WebSQL is a SQLite database in the browser, supported by Webkit based browsers. WebSQL is powerful and fairly well understood, but will not be implemented in Firefox or Internet Explorer, and the spec is in limbo.

IndexedDB seems to be only a KeyValue store. You have to create additional indexes in IndexedDb (and probably store the object in each) to sort the same values in different orders.
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • I did originally consider using WebSQL but since only WebKit browsers support it then the offline functionality could only be made available when using them. I suppose it doesn't really matter since the only place where it will be run offline (at the moment) will be in Chrome. Thanks! – trvo Feb 21 '14 at 12:05
  • @trvo WebSQL has been deprecated for many years. I know this answer was written several years before my comment, but it was already banned several years before that. – AviD Jun 26 '17 at 12:07
  • You are right about official standards, Chrome still officially supports it AFAIK. – Günter Zöchbauer Jun 27 '17 at 04:05
0

You just need to index timestamp field to order by timestamp.

Kyaw Tun
  • 12,447
  • 10
  • 56
  • 83
  • I already do index by timestamp, the date field however can be any date, plus I need to be able to sort by other columns too - key value db's don't seem to be the way forward for my current use. – trvo Feb 23 '14 at 12:27