Sinatra datamapper 从某个条目中提取信息
我是 Sinatra 的新手,我想为移动应用程序创建一项服务。我创建了一个小项目,将条目记录到数据映射器中,并且能够提取所有信息并返回 json 对象。问题是,当您向数据库中添加更多数据时,响应会变得更大,并且需要一段时间才能在移动设备上下载。所以我想以不同的方式提取数据,通过给它序列号,我想只根据completed_at时间提取接下来的10个条目(见下文)。
class NewsObject include DataMapper::Resource property :id, Serial property :title, String property :completed_at, DateTime, :default => DateTime.now end
到目前为止,我设法以正确的顺序提取信息并限制响应(见下文),我只需要弄清楚如何从某个序列号开始
NewsObject.all(:order => [:completed_at] , :限制 => 2)
I'm new to Sinatra and I want to create a service for a mobile application. I've created a small project that records entries into the datamapper, and am able to extract all the information and return a json object. The problem is, is that as you add in more data to the database the response will get larger and will take a while to download on a mobile device. So I would like to extract the data in a different way, by giving it the Serial id, I would like to only extract the next 10 entries based on completed_at time (see below).
class NewsObject include DataMapper::Resource property :id, Serial property :title, String property :completed_at, DateTime, :default => DateTime.now end
So far I'm manged to extract the information in the correct order and limit the response (see below), I just need to figure out how to start at a certain Serial id
NewsObject.all(:order => [:completed_at], :limit => 2)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你试过这个吗?
Have you tried this?