SQLite中的临时内存数据库 [英] Temporary in-memory database in SQLite

查看:132
本文介绍了SQLite中的临时内存数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在SQLite中创建内存数据库,然后仅通过某些查询销毁它?

Is it possible somehow to create in-memory database in SQLite and then destroy it just by some query?

我需要对数据库层进行单元测试.到目前为止,我仅通过创建普通的SQLite db文件并在进行完所有测试后才删除来进行工作,但是在内存中进行所有操作会更好.

I need to do this for unit testing my db layer. So far I've only worked by creating normal SQLite db file and delete if after all tests, but doing it all in memory would be much better.

那么有可能仅在内存中实例化数据库而不向磁盘写入任何内容吗? 我不能只使用事务,因为我想创建整个新数据库.

So is it possible to instanciate database only in memory without writing anything to disc? I can't use just transactions, because I want to create whole new database.

推荐答案

使用文件名:memory:"创建它:

Create it with the filename ":memory:": In-Memory Databases.

与它的连接关闭后,它将不再存在.

It'll cease to exist as soon as the connection to it is closed.

这篇关于SQLite中的临时内存数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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