是否可以使用sqldelight从本地资源加载预先填充的数据库 [英] Is it possible to load a pre-populated database from local resource using sqldelight

查看:93
本文介绍了是否可以使用sqldelight从本地资源加载预先填充的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相对较大的数据库,可能需要1-2分钟来初始化,是否可以在使用sqldelight(kotlin多平台)时加载预先填充的数据库,而不是在应用启动时初始化数据库?

I have a relatively large db that may take 1 to 2 minutes to initialise, is it possible to load a pre-populated db when using sqldelight (kotlin multiplatform) instead of initialising the db on app launch?

推荐答案

是的,但是可能很棘手.不仅限于"Multiplatform".您需要在尝试初始化sqldelight之前将数据库复制到db文件夹.这可能意味着应用程序启动时在主线程上进行了I/O操作.

Yes, but it can be tricky. Not just for "Multiplatform". You need to copy the db to the db folder before trying to init sqldelight. That probably means i/o on the main thread when the app starts.

目前没有标准方法可以执行此操作.在初始化sqldelight之前,您需要将db文件放在android上的资产中,并放在iOS上的捆绑软件中,然后将它们复制到各自的文件夹中.显然,您将需要检查数据库是否首先存在,或者有某种方式知道这是您的第一个应用程序运行.

There is no standard way to do this now. You'll need to put the db file in assets on android and in a bundle on iOS and copy them to their respective folders before initializing sqldelight. Obviously you'll want to check if the db exists first, or have some way of knowing this is your first app run.

如果您计划发布将具有较新数据库的更新,则您需要管理版本,而不仅仅是检查数据库的存在.

If you're planning on shipping updates that will have newer databases, you'll need to manage versions outside of just a check for the existance of the db.

尽管没有直接回答您的问题,但是1到2分钟对于sqlite来说确实非常长.你在做什么?我首先要确保您使用的交易正确.插入数据1-2分钟(可能)会导致数据库文件很大.

Although not directly answering your question, 1 to 2 minutes is really, really long for sqlite. What are you doing? I would first make sure you're using transactions properly. 1-2 minutes of inserting data would (probably) result in a huge db file.

这篇关于是否可以使用sqldelight从本地资源加载预先填充的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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