Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Brainstorm
  4. Looking for a good SQL DSL
Forum Updated to NodeBB v4.3 + New Features

Looking for a good SQL DSL

Scheduled Pinned Locked Moved Brainstorm
3 Posts 2 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    agabor
    wrote on last edited by
    #1

    I am working on a project where I use SQLite to store the application data. I use the built in "QSql..." classes to access it. As I did not like to embedd the queries as strings in my code, I started to wrap around the in build classes, creating query builders.

    This is an example of a select:

    @
    SQLSelect select{"rules"};
    select.field("id");
    select.field("column");
    select.field("value");
    select.field("category");
    select.field("type");
    select.where(QString("country = %2").arg(_country));
    @

    I also try to reason about the structure of the database, so I created the TableStructure class:

    @
    TableStructure rules{"rules"};
    rules.addField("id", SQLType::Integer().PK().NotNull());
    rules.addField("column", SQLType::Integer().NotNull());
    rules.addField("value", SQLType::Text().NotNull());
    rules.addField("category", SQLType::Integer().NotNull());
    rules.addField("type", SQLType::Integer().NotNull());
    @

    and the DataBaseSchema class:

    @
    DataBaseSchema schema;
    schema.addTable(rulse);

    TableStructure countries{"countries"};
    countries.addField("ID", SQLType::Integer().PK());
    countries.addField("Code", SQLType::Text());
    schema.addTable(countries);
    

    @

    Database schemas are comperable, so it is really convinient to check from the application if the database is exactly what was expacted, or an update is needed, or someone accidently opened somethig totally unrelated SQLite database.

    Now, all these work good enough, but I keep thinking that this must have been implemented a few times before, and I am making a research for similar libraries.

    I have found similar things for C#, Java:
    http://www.codeproject.com/Articles/13419/SelectQueryBuilder-Building-complex-and-flexible-S
    http://sqlorm.sourceforge.net/dynamic_query_builder_doc.html

    But sadly not much for C++. Someone else also asked it on stackowerflow:
    http://stackoverflow.com/questions/18346357/c-sql-query-building-library
    The answer is good, but sadly not quite what I Am looking for. Am I maybe using the wrong terminology?

    So if anyone has any ideas about this, know some libraries (GPL compatible preffered!), I would be happy to hear about it. I also would like to hear your opinion in general about that you find this a good approach, or you would do something else in my place.

    Every idea is appreciated!

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      Have you tried sqlate? It's a typesafe sql query builder that uses expression templates for doing as much work as possible at compile time. It's freely available from

      https://github.com/KDAB/sqlate/

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • A Offline
        A Offline
        agabor
        wrote on last edited by
        #3

        This looks really good! Thank you very much!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved