Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7871511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:55:41+00:00 2026-06-03T01:55:41+00:00

I want to write a database wrapper that can operate different types of databases

  • 0

I want to write a database wrapper that can operate different types of databases (e.g. sqlite, postgres, etc.), so the code that users are writing does not change regardless of what database they actually are using.

In my head, this calls for an abstract base class like:

class database {
public:
    virtual bool query(const std::string &q) = 0;
    // Other stuff
};

class sqlite : public database {
public:
    bool query(const std::string &q) {
        // Implementation
    }
};

This looks good, but I am using variadic templates for escaping arguments inside queries (and I really like this idea, so I would want to hang on to it!), so unfortunately my base class rather looks like:

class database {
public:
    template <typename... Args>
    bool query(const std::string &q, const Args &... args) {
        // Implementation
    }
};

This stands in the way of creating an abstract class however, because templated functions cannot be virtual. The only thing I came up with so far is this construct

template <class DatabaseType>
class database {
public:
    template <typename... Args>
    bool query(const std::string &q, const Args &... args) {
        return database_.query(q, args...);
    }
private:
    DatabaseType database_;
};

While this seems to work, with all the wrappers that do nothing but call the identically named database_ functions it does not look like a very good style to me. Is this the design pattern of choice here, or is there a cleaner, or more idiomatic way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:55:44+00:00Added an answer on June 3, 2026 at 1:55 am

    You can build a query object out of the arguments to the query function, and pass it to a virtual query_impl function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a DBI wrapper, provide select/insert/update/delete, and users can choose which
I want to write a code to backup my Sql Server 2008 Database using
Suppose you want to write into a database that something is 30 meters long,
When you want to write a query in Python that will select (from SQLite
I have whole page HTML in my database and i want write that html
I want to write Java code to work with a database, no matter which
I want to write a python script that populates a database with some information.
I want to write unit tests with NUnit that hit the database. I'd like
I want to write a service (probably in c#) that monitors a database table.
I want to write a php script to compare rows from the database and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.