I am developing a javascript (Node.js) desktop program that works with an existing MySQL database. I would like to (eventually) distribute to others with based on SQLite, or MySQL if they need (or possibly some other database).
What is a good strategy for writing database agnostic code? I'm baking in switches like the pseudo-code below, but I think there's a better way to abstract this out:
result = query1();
function query1(){
DbType = getDbType(); // Returns MySQL or SQLite
if DbType == 'MySQL'{
query = ""; // MySQL Query
result = mysqlconnector.doquery(query);
}else{
if DbType == 'SQLite'{
query = ""; // SQLite Query
result = sqliteconnector.doquery(query);
}
return result;
}
I don't think I want a full-blows ORM as they seem annoyingly restrictive.