9
votes

I'm working with unit/integration tests and SQLite doesn't support completely certain SQL features (like RIGHT JOIN and FULL OUTER JOIN). Is there any way to work with MySQL (or MariaDB) where the contents of a database are completely stored in memory?

MySQL has MEMORY table engine, however, this table engine still may generate inconsistency in my tests. What I need is some alternative to :memory: from SQLite but with the same features as MySQL.

Edit:

To be more specific, my problem is related to the performance of the unit/integration tests. Several tutorials indicate using SQLite with database in-memory to speed up the testing process, however, some queries in my application aren't compatible with SQLite. I also do not find it a good practice to do the tests in SQLite if the production database is MariaDB.

My question is whether there is any alternative to testing in MySQL/MariaDB that works the same way as the SQLite :memory: option.

1
The answer to your question is the MEMORY storage engine. You need to be a bit clearer about what the issue is. You could use another storage engine on an "in-memory" virtual disk, but that depends on your operating system.Gordon Linoff
Which inconsistencies?The Impaler
First question is "Why?" as it's usually a bad plan to test in memory for what will be deployed on disk, and secondly, if you really need it in memory use a ramdisk.tadman
MySQL and MariaDB do not have FULL OUTER JOIN, but it can be easily simulated.Rick James
Usually unit tests should not touch database at all, what you're doing is probably integration tests, for such ones I'd prefer to have standalone mysql server, so test suite in setup will create db, all tables, sample data and drop all of it during finalizationIłya Bursov

1 Answers

2
votes

MariaDB has the MEMORY storage engine:

It is best-used for read-only caches of data from other tables, or for temporary work areas.

That sounds exactly right for quick setup and teardown of a database during automated testing.