问题描述
我有一个现有的数据库,结构用于翻过整个应用程序。数据库的实例定期轮换。我有被用作所有新创建的数据库模板的数据库文件 template.sqlite
。我想用它,而不是创建脚本,所以我要保持只有一个文件,空数据库模板本身。
I have an existing database which structure is used accross the whole application. Instances of the databases are periodically rotated. I have a database file template.sqlite
which is used as a template for all newly created databases. I want to use it, not a creation script, so that I have to maintain only one file, the empty database template itself.
我想创建一个内存数据库具有相同的结构基于该模板文件。
I would like to create an in-memory database with the same structure based on that template file.
我知道我能打开数据库,读它的结构,然后在内存中手动创建数据库。如果可能的话,我希望能够做到这一点更自动的方式。
I know I can open the database and read it's structure, then create the database manually in memory. If possible, I would like to be able to do it in a more automatic way.
推荐答案
您可以使用的确实创造了一堆SQL命令,就可以执行。
You could use the .dump
command of the command-line shell do create a bunch of SQL commands that you can execute.
另外,您也可以使用的模板复制到一个新的数据库。
Alternatively, you can use the backup API to copy the template into a new database.
这篇关于如何创建一个内存数据库架构基于现有文件数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!