Giter Site home page Giter Site logo

orm-qt's Introduction

Missing Object Relation Mapping realisation in Qt framework

This library presents you a simple way to work with database tables like some script languages do.

Features:

  • easy use and integrate with your project
  • full CRUD support with ActiveRecord pattern
  • deep integration with Qt
  • easy SQL select/insert/update/delete manipulation

Example code:

Let we have created a table foobar with fields foo and bar:

// ... other Qt includes
#include <activerecord.h>

// create empty record
orm::ActiveRecord ar_obj("foobar");

// set values
ar_obj.setValue("foo", "this is test string");
ar_obj.setValue("bar", 123);

// save this record
bool ok = ar_obj.save();

// get result primary key
QVariant pk = ar_obj.primaryKey().value();

// load second obj
orm::ActiveRecord ar2_obj("foobar");
ar2_obj.load(pk);

// get value
int val = ar2_obj.value("bar").toInt();

// remove object
ar2_obj.remove();

Notes

"Where are other features?" you can ask. As I noted before, this is light library, all your need exists in Qt already.

For example you need to select many records. Your example code:

QSqlQuery qr = orm::Query::select("foobar").where("id > ?", 100).make();
if (qr.exec()) {
        while (qr.next()) {
                orm::ActiveRecord ar_obj("foobar");
                ar_obj.setRecord(qr.record());
                ar_obj.setValue("foo", "new_foo_value");
                ar_obj.save();
        }
}

As you can see, any wrapper only complicate code. orm-qt aim to efficiently manipulate standart Qt classes and try not to reinvent the wheel. Another example, you need to create some model. Your example code:

// ...
QTableView *view = new QTableView;
QSqlQueryModel *model = new QSqlQueryModel;
// ...
QSqlQuery qr = orm::Query::select("foobar").where("id > ?", 100).make();
if (qr.exec()) {
        model->setQuery(qr);
        view->setModel(model);
}
// get ActiveRecord from 1st row
QSqlRecord rec = model.record(0);
if (!rec.isEmpty()) {
        orm::ActiveRecord ar_obj("foobar");
        ar_obj.setRecord(rec);
        // some actions...
}

If you work need any other functions or classies your can email me. Unfortunately this time documentation is empty. I fix it neares time, you can see test folder for code examples.

License

This code under MIT license
Home: https://github.com/victorzhuk/orm-qt
Author: Victor Zhuk [email protected]

orm-qt's People

Contributors

victorzhuk avatar

Watchers

 avatar

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.