-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.cpp
32 lines (27 loc) · 833 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <bits/stdc++.h>
#include "model.h"
#include "db.h"
using namespace std;
class User : public Model
{
INLOQUENT_MODEL(User, users, id);
};
int main(int, char *[])
{
if (DB::initialize("QMYSQL", "localhost", 3306, "test", "root", "secret") == false)
cout << DB::lastErrorMessage().toStdString() << endl;
bool ok = DB::createIfNotExists("users", [](BluePrint *table){
table->increment("id");
table->string("name")->unique();
table->timestamps();
});
if (ok == false)
qDebug() << DB::lastErrorMessage();
User user;
user.set("name", "Infinity");
if (user.save() == false)
qDebug() << DB::lastErrorMessage();
Q_ASSERT(User::find(1).get("name") == "Infinity");
Q_ASSERT(User::where("name", "Infinity").first()["id"] == 1);
return 0;
}