RESOLVED WONTFIX 18807
Support storing JavaScript objects as BLOB
https://bugs.webkit.org/show_bug.cgi?id=18807
Summary Support storing JavaScript objects as BLOB
Jayant Sai
Reported 2008-04-29 22:52:20 PDT
According to http://www.sqlite.org/datatype3.html, 'BLOB. The value is a blob of data, stored exactly as it was input.'. Currently in WebKit & Safari, the implementation seems to convert the JavaScript object to a string "[object Object]". It would be great if it were possible to store JavaScript objects and JSON objects within the database as BLOB and as objects and not as string representations. Currently, only a string de/serialization would work, but that can be expensive, especially when trying to run Safari on iPhone which has very limited JavaScript execution time.
Attachments
Test page (1.64 KB, text/html)
2008-04-29 22:54 PDT, Jayant Sai
no flags
Jayant Sai
Comment 1 2008-04-29 22:54:26 PDT
Created attachment 20897 [details] Test page A simple test page showing storing an object literal as BLOB. Currently the alert displays the type of data after SELECT as string.
Alexey Proskuryakov
Comment 2 2008-05-05 12:02:36 PDT
SQLite documentation is only tangentially related to HTML5 storage, because there are at least two other type systems to consider - first, there is JavaScript, and then, there is DOM. And anyway, BLOB is not magic - it's just a special kind of string suitable for storing large amounts of data. Yet, it does seem a little weird that a function is stringified like "[object Object]" in this test case - e.g. alert(selectData) successfully shows its source, and one could expect the same here.
Jayant Sai
Comment 3 2008-05-07 16:23:50 PDT
Thank you for clarifying about the SQLite & HTML5 storage differences. Do you have any recommendations on how I should store the object, without converting it to a String. In my current app, this conversion takes too long. Or is this a bug which will need to be fixed in WebKit? thanks Jayant (In reply to comment #2) > SQLite documentation is only tangentially related to HTML5 storage, because > there are at least two other type systems to consider - first, there is > JavaScript, and then, there is DOM. And anyway, BLOB is not magic - it's just a > special kind of string suitable for storing large amounts of data. > > Yet, it does seem a little weird that a function is stringified like "[object > Object]" in this test case - e.g. alert(selectData) successfully shows its > source, and one could expect the same here. >
Alexey Proskuryakov
Comment 4 2008-05-11 03:37:05 PDT
I don't think there is any way to store an object without turning it into a string. You may want to join WHATWG <http://www.whatwg.org/> and describe your use case in an e-mail to its list for people working on the specification to consider it. Brady, what do you think? Does our implicit stringification appear broken, as I wondered in comment 2?
Oliver Hunt
Comment 5 2009-07-07 22:51:15 PDT
JSON.stringify would appear to accomplish what is being requested here
Oliver Hunt
Comment 6 2011-06-24 12:07:49 PDT
(In reply to comment #5) > JSON.stringify would appear to accomplish what is being requested here As an addendum, our postMesage serialisation is a flat binary storage system that supports avariety of dom objects and allows cyclic graphs, maybe that would be superior?
Anne van Kesteren
Comment 7 2023-08-24 03:53:37 PDT
This should be standardized first as suggested above. But also, as suggested above, there's ample alternatives available.
Note You need to log in before you can comment on or make changes to this bug.