Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/miska/zxdb
Template for creating C++ database abstraction classes using tntdb.
https://github.com/miska/zxdb
Last synced: 1 day ago
JSON representation
Template for creating C++ database abstraction classes using tntdb.
- Host: GitHub
- URL: https://github.com/miska/zxdb
- Owner: miska
- License: gpl-3.0
- Created: 2015-01-26T23:17:36.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-10-21T16:21:04.000Z (about 9 years ago)
- Last Synced: 2024-12-06T06:59:03.735Z (about 1 month ago)
- Language: C++
- Size: 211 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.asciidoc
- License: LICENSE
Awesome Lists containing this project
README
ZXDB
====What is this?
-------------ZXDB is a GSL template that generates class based abstraction on top of
database tables to simplify working with data structures that are at some
point destined to be stored in database.FAQ
~~~Why C++ ?
^^^^^^^^^C++ is nice from integration point of view, you will get generated classes,
inherit them and override any virtual methods you don't like. This way it is
easy to take advantage of generated code and be able to extend it as well.Why generating it?
^^^^^^^^^^^^^^^^^^Whenever you alter your model, it is quite some work to modify everything to be
able to use all the fancy C++ features. You have to modify constructors,
private properties, setters and getters, serialization and more. With
generation, you can do it really easily, just by modifying one line of XML,
you can regenerate your class and get all the fancy stuff for free.Dependencies
------------There two main types of dependencies. One are generation time and other ones
are compile time. This is due to the fact that you need to generate C++ code
first and than compile it. But once you generated it, you no longer need a code
generator for building, so you can ship generated files and no need to bother
your users with some generation...Generation
~~~~~~~~~~What do you need for generating C++ code.
GSL
^^^link:https://github.com/imatix/gsl[GSL] is nice system for generating stuff. It
is used by various projects related to ZeroMQ and was developed by company
called iMatix. You can find more information about it on it's
link:https://github.com/imatix/gsl[github page].Compilation
~~~~~~~~~~~Actual dependencies of generated classes. Following thing will be needed on top
of C\++ compiler compatible with C\++ 11 standard. Why C++ 11? There is plenty
of really awesome features you probably want to learn if you haven't done so
already. And once you learn at least few, you never want to go back to anything
older.TNTDB & CXXTools
~~~~~~~~~~~~~~~~link:http://www.tntnet.org/tntdb.html[TNTDB] is database abstraction library.
It has nice C++ API and provides uniform abstraction on top of SQLite, MySQL
and PostgreSQL (and some more and weirder like Oracle). Therefore you can
develop your application against SQLite and deploy it against MySQL. And
link:http://www.tntnet.org/cxxtools.html[CXXTools] is just handy library with
everything that is actually dependency of TNTDB.Catch
~~~~~link:https://github.com/philsquared/Catch[Catc]h is actually not all that
necessary. Catch is unit testing framework and autogenerated tests are written
in it, just expecting that you will provide main somewhere and link everything
together. So if you don't care about unit testing, you don't need Catch.Usage
-----First of all you need to create an +.xml+ file with description of your data. It
can look something like this:[source,xml]
--------------------------------------------------------------------------------Size of the file
Hash of the filePaths on which this file can be found
Project this file belongs to--------------------------------------------------------------------------------
Than you need to generate your actual C++ files. This ca be done by running
--------------------------------------------------------------------------------
$ gsl file.xml
--------------------------------------------------------------------------------GSL will generate three files for you. +file.hpp+, +file.cpp+ and
+file_test.cpp+. First one contains definition of your newly generated _File_
class. Next one, +file.cpp+, contains actual implementation and the last one -
+file_test.cpp+ - is implementation of unit test for your new class.This class has properties as specified in XML with all the setters and getters
you want. It can serialize itself and you can query database for instances of
this class. Check the generate files to see the possibilities. And most
importantly, every method is documented ;-)Also you don't need to worry about database scheme as tables will be created
during the first use of the class.If you are interested, see example folder where is an example of few simple
xmls and of the generated code.