Scala Slick Lazy Fetch [英] Scala Slick Lazy Fetch

查看:42
本文介绍了Scala Slick Lazy Fetch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够使用 Slick 从一个非常大的表中获取所有记录.如果我尝试通过 foreach、for 或 list 获取来执行此操作;我收到内存不足异常.

I want to be able to fetch all records from a very big table using Slick. If I try to do this through foreach, for or list fetching; I get an Out Of Memory Exception.

有什么方法可以在 Slick 或延迟加载中使用游标",只在需要减少内存使用量时才获取对象?

Is there any way to use "cursors" with Slick or lazy loading that only fetch the object when needed reducing the amount of memory used?

推荐答案

不知道你说的游标是什么意思,但你可以使用分页获取部分数据:

Not sure what do you mean by cursors, but you can fetch partial data using pagination:

query.drop(0).take(1000) will take the first 1000 records

query.drop(1000).take(1000) will take from 1001 to 2000 lines of the table.

但是这个查询效率将取决于你的数据库,它是否支持它,表是否正确索引.

But this query efficiency will depend on your database, if it will support it, if the table is right indexed.

这篇关于Scala Slick Lazy Fetch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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