Skip to content

Commit 16a00bd

Browse files
committed
Add SQL module
1 parent 52e1bff commit 16a00bd

File tree

7 files changed

+147
-0
lines changed

7 files changed

+147
-0
lines changed

lib/sql/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#================= Add Component ==========================
2+
qx_add_component("Sql"
3+
HEADERS_API
4+
qx-common-sql.h
5+
IMPLEMENTATION
6+
qx-common-sql.cpp
7+
#DOC_ONLY
8+
LINKS
9+
PUBLIC
10+
${Qt}::Sql
11+
Qx::Core
12+
)

lib/sql/cmake/depends_qt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Core
2+
Sql

lib/sql/cmake/depends_siblings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Core
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
Qx Declarative JSON {#declarativejson}
2+
======================================
3+
4+
FIXME
5+
6+
Qx features a highly flexible, simple to use, declarative mechanism for parsing/serializing JSON data into user structs and other types.
7+
8+
For example, the following JSON data:
9+
10+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.json}
11+
{
12+
"title": "Sample JSON Data",
13+
"info": {
14+
"rating": 10,
15+
"cool": true
16+
},
17+
"reviews": [
18+
"Wicked!",
19+
"Awesome!",
20+
"Fantastic!"
21+
]
22+
}
23+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24+
25+
can easily be parsed into a corresponding set of C++ data structures like so:
26+
27+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
28+
#include <qx/core/qx-json.h>
29+
30+
struct Info
31+
{
32+
int rating;
33+
bool cool;
34+
35+
QX_JSON_STRUCT(rating, cool);
36+
};
37+
38+
struct MyJson
39+
{
40+
QString title;
41+
Info info;
42+
QList<QString> reviews;
43+
44+
QX_JSON_STRUCT(title, info, reviews);
45+
};
46+
47+
int main()
48+
{
49+
QFile jsonFile("data.json");
50+
MyJson myJsonDoc;
51+
52+
// Parse into custom structures
53+
Qx::JsonError je = Qx::parseJson(myJsonDoc, jsonFile);
54+
Q_ASSERT(!je.isValid());
55+
56+
...
57+
}
58+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59+
60+
Likewise, the structure can be serialized back out into textual JSON data with:
61+
62+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
63+
int main()
64+
{
65+
...
66+
67+
// Serialize to JSON
68+
je = Qx::serializeJson(jsonFile, myJsonDoc);
69+
Q_ASSERT(!je.isValid());
70+
}
71+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72+
73+
This system is accessed through the qx-json.h header, predominantly with QX_JSON_STRUCT().

lib/sql/doc/general/sql.dox

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*!
2+
* @defgroup qx-sql Qx SQL
3+
*
4+
* @brief The SQL component is a module dedicated to interacting with SQL relational databases.
5+
*
6+
* @component{Sql,sql.h}
7+
*
8+
* Qx SQL extends the Qt SQL module to allow for easier use of databases for some of the most
9+
* common use-cases.
10+
*/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef QX_SQL_COMMON_H
2+
#define QX_SQL_COMMON_H
3+
4+
// Shared Lib Support
5+
#include "qx/sql/qx_sql_export.h"
6+
7+
// Qt Includes
8+
9+
10+
//Intra-component Includes
11+
12+
13+
// Extra-component Includes
14+
15+
16+
namespace Qx
17+
{
18+
//-Namespace Enums-----------------------------------------------------------------------------------------------------
19+
20+
21+
//-Namespace Variables-------------------------------------------------------------------------------------------------
22+
23+
//-Namespace Functions-------------------------------------------------------------------------------------------------
24+
25+
}
26+
27+
#endif // QX_SQL_COMMON_H

lib/sql/src/qx-common-sql.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Unit Includes
2+
#include "qx/io/qx-common-sql.h"
3+
4+
// Qt Includes
5+
6+
// Intra-component Includes
7+
8+
// Extra-component Includes
9+
10+
/*!
11+
* @file qx-common-sql.h
12+
* @ingroup qx-sql
13+
*
14+
* @brief The qx-common-sql header file
15+
*
16+
* ...
17+
*/
18+
19+
namespace Qx
20+
{
21+
22+
}

0 commit comments

Comments
 (0)