在2011年为iOS / Android开发HTML5离线存储解决方案 [英] Developing a HTML5 offline storage solution for iOS/Android in 2011

查看:118
本文介绍了在2011年为iOS / Android开发HTML5离线存储解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

我需要一个设备无关(例如HTML5)解决方案,用于在线上存储和查询250,000多行数据手机或平板电脑类型的设备(例如iOS / Android)。我的想法是让人们在没有任何蜂窝数据连接的偏远地区工作,他们需要对这些数据运行查询并在离线时进行编辑。部分地,它将基于地理位置,因此如果他们所在的区域中有资产(使用GPS),那么它将显示这些资产并让它们被编辑。当他们返回办公室时,他们可以将数据同步回办公室服务器。

I need a device agnostic (e.g. HTML5) solution for storing and querying 250,000+ rows of data offline on a phone or tablet type device (e.g. iOS/Android). The idea being I have people working in remote areas without any cellular data connection and they need to run queries on this data and edit it while offline. Partly it will be geo-location based so if there are assets in the area they are in (uses GPS) then it will show those assets and let them be edited. When they return to the office they can sync the data back to the office server.

从网络标准的角度来看,我接近这个的原因基本上是通过在HTML5中编写一次来节省金钱和时间,然后它可以跨多个平台工作,而不是在Objective C和Java中编写两次。此外,如果你写的是与平台无关的东西,那么你就不会被锁定,并且当每个人都搬到新的船上时,不要随船停下来。我们有一个类似的应用程序为Windows Mobile 5编写,现在它没用,因为该平台已经死了。

The reason that I'm approaching this from a web standard point of view is basically to save money and time by writing it once in HTML5 and then it works across multiple platforms rather than writing it twice in Objective C and Java. Also if you write something that's platform agnostic then you're not locked in and don't go down with the ship when everyone moves to a newer one. We had a similar app written for Windows Mobile 5, now it's useless as that platform is dead.

设备上的脱机数据库需要:

The offline database on the device needs to be:


  • 快速(2秒内的响应)

  • 可能执行联接并与能够查询数据库的其他表有关系

  • 选择特定范围内的数据或标准,例如由x& y基于GPS阅读进行协调。

选项:

HTML5本地存储:

HTML5 local storage:

少量数据< 5,000 key / values,如果将数组转换为JSON,甚至可以在其中存储数组/对象。

Fine for small amounts of data <5,000 key/values, you can even store arrays/objects in it if you convert it to JSON.

缺点:


  • 即使在高端机器上超过10,000行,浏览器也会慢慢爬行。$ / b>
  • 可以不要对数据进行复杂的查询以获取所需的数据,因为您必须遍历整个存储并手动搜索它。

  • 存储量可能限制已存储

Web SQL数据库:

Web SQL Database:


  • 满足要求。

  • 快速运行250,000行(1-2秒)的查询

  • 可以创建复杂的查询,加入等

  • 由Safari,Android和Opera支持,因此可以在iOS上运行Android设备

  • Meets the requirements.
  • Fast to run a query on 250,000 rows (1-2secs)
  • Can create complex queries, joins etc
  • Supported by Safari, Android and Opera so will work on iOS and Android devices

缺点:


  • 截至2010年11月已弃用

  • 跨目录攻击的安全漏洞。不是真正的问题,因为我们不会在共享主机上

IndexedDB:

IndexedDB:

键/值对象存储类似于本地存储,但索引除外。

Key/value object store similar to local storage except with indexes.

缺点:


  • 在200,000行(15-18秒)上运行查询的速度慢

  • 无法运行复杂查询

  • 无法与其他表进行联接

  • 主要手机或平板电脑设备不支持,例如iPad / Android

  • 标准不完整

  • Slow to run a query on 200,000 rows (15-18secs)
  • Can't run complex queries
  • Can't do joins with other tables
  • Not supported by main phone or tablet devices e.g. iPad/Android
  • Standard not complete

这是实现弃用Web的唯一选择SQL方法,可能只工作一年左右。 IndexedDB和本地存储目前无法使用。

This leaves the only option of implementing the deprecated Web SQL method which may only work for another year or so. IndexedDB and local storage are unusable at present.

我不确定Mozilla和Microsoft如何推荐Web SQL数据库标准以及为什么W3C会让它发生。据称他们之间拥有77%的桌面浏览器市场。在高级移动设备上,由于 Safari,Opera和Android拥有超过90%的市场份额,Mozilla和微软几乎没有影响力。 Mozilla&微软可以决定在移动市场中应该使用哪种标准,这是最有可能使用离线存储的标准。

I'm not sure how Mozilla and Microsoft got the Web SQL Database standard deprecated and why the W3C let it happen. Supposedly between them they have 77% of the desktop browser market. On advanced mobile devices Mozilla and Microsoft have nearly zero influence as Safari, Opera and Android have over 90% of the market share. How Mozilla & Microsoft can dictate which standard should be used in the mobile market which is where offline storage is most likely to be used doesn't make any sense.

来自Mozilla的评论关于他们为什么要这样做IndexedDB主要是关于'开发者美学',他们不喜欢在JavaScript中运行SQL的想法。我不是买它。

In the comments from Mozilla about why they wanted to go with IndexedDB instead are mainly about 'developer aesthetics' and they don't like the idea of running SQL in JavaScript. I'm not buying it.


  1. 目前提议的标准是劣质的,而且非常基本的NoSQL实现很慢而且没有甚至支持人们在数据库中需要的高级功能。有许多样板代码来建立数据库并获取数据,但他们声称人们会在其顶部编写一些很好的抽象库,它们将提供更高级的功能。截至2011年10月,它们无处可见。

  1. Currently the proposed standard is inferior and an extremely basic NoSQL implementation that is slow and doesn't even support the advanced features people need in a database. There is a lot of boilerplate code to establish the database and get data out but they claim people will write some nice abstraction libraries over the top of it that will provide more advanced features. As of Oct 2011 they're nowhere to be seen.

他们已经弃用了现有的Web SQL标准,该标准实际上可以在主要的移动设备上实现/平板浏览器。而主流移动浏览器无法提供新和更好的标准。

They've deprecated the existing Web SQL standard which actually works and is implemented in the main mobile/tablet browsers. Whereas their 'new' and 'better' standard is not available in the major mobile browsers.

我们作为开发人员应该用于下一个3- 5年的时间,IndexedDB规范可能会变得标准化,有更多的功能,在主要的移动/平板电脑浏览器中实现,还有一些很好的库可以让事情变得更容易吗?

What are we as developers supposed to use for the next 3-5 years which is when the IndexedDB specification might get around to being standardised, have more features, implemented in the main mobile/tablet browsers and there's some nice libraries to make things easier?

W3C应保持Web SQL数据库标准并行运行并解决问题。它已经支持主要的移动平台,并且运行良好。事实上,Mozilla和微软作为拥有最多桌面浏览器份额的两家公司能够取消这一标准是非常可疑的,可能会被视为阻碍移动网络平台进展的尝试,直到他们能够赶上并提供针对iOS / Safari和Android的竞争解决方案。

The W3C should keep the Web SQL Database standard running in parallel and just fix the issues. It already has support for the major mobile platforms and it works pretty well. The fact that Mozilla and Microsoft as the two players with the most desktop browser share were able to get this standard scrapped is pretty dubious and could be seen as an attempt to hinder progress on the mobile web platforms until they are able to catch up and offer competing solutions against iOS/Safari and Android.

总之,任何人都有解决我的问题的解决方案,适用于iOS / Android手机/平板电脑设备。也许是一个很好的包装器API,它可以在后台使用多个数据库实现并具有查询功能,它允许您选择哪个数据库具有优先级。我见过像草坪椅这样的东西,但我很确定它只允许你默认使用本地存储,然后再回到其他。我想我更倾向于使用Web SQL(默认情况下)然后选择较慢的选项。

In conclusion does anyone have a solution for my problem that will work for iOS/Android for phone/tablet devices. Maybe a nice wrapper API that can use multiple database implementations in the background with querying capability and it lets you choose which database has priority. I've seen things like lawnchair but I'm pretty sure it only lets you use local storage by default and falls back to the to the others. I think I'd rather it used Web SQL (by default) then the slower options.

非常感谢任何解决方案的帮助,谢谢!

Any help for a solution much appreciated, thanks!

推荐答案

我建议查看 JayData 库,实际上具有为移动设备创建存储不可知数据访问层的确切目的。 JayData提供了一个带有 JavaScript语言查询(JSLQ)和JavaScript CRUD支持的抽象层,让你以完全相同的方式工作具有不同的离线和在线数据存储类型。 JayData支持本地或远程处理复杂实体以及实体关系。

I would recommend checking out the JayData library, that actually has the exact purpose of creating a storage agnostic data access layer for mobile devices. JayData provides an abstraction layer with JavaScript Language Query (JSLQ) and JavaScript CRUD support and let's you work on the exact same way with different offline and online data store types. JayData supports dealing with complex entities and also entity relationships either locally or remotely.

在撰写本文时,JayData支持以下存储或协议:webSQL(sqLite)/ IndexedDB /的OData / YQL / FBQL。

At the time of writing JayData supports the following stores or protocols: webSQL(sqLite)/IndexedDB/OData/YQL/FBQL.

使用JayData的提供程序回退功能可以轻松解决提供不同存储引擎的不同系统的特定问题:它将使用它可以找到的任何存储层,同时仍提供与消费者代码相同的API。

Your particular problem with different systems providing different storage engines can be easily addressed with the provider fallback feature of JayData: it will use whatever storage layer it can find while still provides the same API toward the consumer code.

关于WebSQL在2012年被弃用:在撰写本文时,WebSQL仍然拥有95%的设备覆盖率,包括三星智能电视和亚马逊Kindle。 查看执行WebSQL单元测试的kindle与JayData

With regarding WebSQL being deprecated by 2012: at the time of writing it is WebSQL that still has a 95% device coverage including Samsung SmartTV and amazon Kindle. Check out kindle executing WebSQL unit tests with JayData.

这篇关于在2011年为iOS / Android开发HTML5离线存储解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆