Code Monkey home page Code Monkey logo

gdi's Introduction

gdi

Generic Database Interface

This library aims to provide C++11 with a generic interface to manage databases via entity classes, in order to function it is built up based on 4 parts: Entity, EntityManager, Query Builder and Executor.

Entity

Via using the supported macros an entity can be declared as a class that represents a table in the database like:

ENTITY(MyEntity)
ADD(MyEntity, Id, int)
ADD(MyEntity, Number, double)
ADD(MyEntity, Name, std::string)
ADD_VAR(MyEntity, Phone, std::string, 20)
PRIMARY(MyEntity, "Id")
END

After that declaration MyEntity class can be used regularly:

MyEntity entity;
entity.SetId(1);
entity.SetName("MyName");
entity.SetPhone("12345");
entity.SetNumber(3.14);

EntityManager

This class needs an Executor as a dependency. EntityManager manages entity objects and is used to look for, update, insert and delete entities:

  • Find(Entity e): This returns an entity from the database which primary key equals e primary key.
  • FindBy(Entity e, …): This returns a set of entity objects which have the same e attributes values where are those attributes names.
  • Insert(Entity e): Inserts the entity e into the database.
  • Update(Entity e): Updates a row in DB based on the values of e attributes.
  • UpdateBy(Entity e, …): Updates DB rows which have same e attributes values where are those attributes names.
  • Delete(Entity e): Deletes a row from the DB based on the primary key.

Query Builder

This builder contains the query to be executed, and it builds queries like:

Select("Country").Count("CustomerID").
        From("Customers").
        GroupBy("Country").
        Having("COUNT(CustomerID)", WhereCondition::GREATER_THAN, "5").
        OrderBy("COUNT(CustomerID) DESC");

Executor

This class is to be implemented for each DBMS differently, here I have written 2 implementations one for MySQL and one for Postgres, it is used to execute the queries and to get the results as entity objects, it should implement 2 methods: Execute and ExecuteQuery.

gdi's People

Contributors

muazsh avatar

Stargazers

Haldun Matar avatar

Watchers

 avatar

gdi's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.