http://www.perlmonks.org?node_id=704504


in reply to Considering future support for different databases.

Mogilefs is a significant perl app which is database-independent between MySQL, Postgres and SQLite.

Basically, the approach is to have a 'store' base class which encapsulates all db access.

There are capability flags set by each concrete derived store. e.g. 'can_replace' returns true in MogileFS::Store::MySQL, but false in MogileFS::Store::Postgres.

This allows methods like:

sub ignore_replace { my $self = shift; return "INSERT IGNORE " if $self->can_insertignore; return "REPLACE " if $self->can_replace; die "Can't INSERT IGNORE or REPLACE?"; }
to try and do something sensible depending on the back-end.

But frankly, you're going to have db-specific bugs unless you've got good test coverage. And db independence gets harder the more of the db features you use (both because you have to check for more variation and because such things are less standardised).