1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Make db a global instance

This commit is contained in:
Laurent Cozic 2017-01-01 23:03:42 +01:00
parent 959e5be871
commit 2491a8dab5
6 changed files with 36 additions and 5 deletions

View File

@ -12,13 +12,15 @@ using namespace jop;
Application::Application(int &argc, char **argv) :
QGuiApplication(argc, argv),
db_("D:/Web/www/joplin/QtClient/data/notes.sqlite"),
db_(jop::db()),
api_("http://joplin.local"),
synchronizer_(api_, db_),
folderModel_(db_)
{
jop::db().initialize("D:/Web/www/joplin/QtClient/data/notes.sqlite");
// This is linked to where the QSettings will be saved. In other words,
// if these values are changed, the settings will be reset and saved
// somewhere else.

View File

@ -24,7 +24,7 @@ public:
private:
QQuickView view_;
Database db_;
Database& db_;
NoteCollection noteCollection_;
FolderModel folderModel_;
NoteModel noteModel_;

View File

@ -3,6 +3,25 @@
using namespace jop;
Database::Database(const QString &path) {
// version_ = -1;
// // QFile::remove(path);
// db_ = QSqlDatabase::addDatabase("QSQLITE");
// db_.setDatabaseName(path);
// if (!db_.open()) {
// qDebug() << "Error: connection with database fail";
// } else {
// qDebug() << "Database: connection ok";
// }
// upgrade();
}
Database::Database() {}
void Database::initialize(const QString &path) {
version_ = -1;
// QFile::remove(path);
@ -19,8 +38,6 @@ Database::Database(const QString &path) {
upgrade();
}
Database::Database() {}
QSqlQuery Database::query(const QString &sql) const {
QSqlQuery output(db_);
output.prepare(sql);
@ -190,3 +207,9 @@ void Database::upgrade() {
versionIndex++;
}
}
Database databaseInstance_;
Database& jop::db() {
return databaseInstance_;
}

View File

@ -14,6 +14,7 @@ public:
Database(const QString& path);
Database();
void initialize(const QString& path);
QSqlQuery query(const QString& sql) const;
QSqlDatabase& database();
QSqlQuery buildSqlQuery(Database::QueryType type, const QString& tableName, const QStringList& fields, const VariantVector& values, const QString& whereCondition = "");
@ -31,6 +32,9 @@ private:
};
Database& db();
}
#endif // DATABASE_H

View File

@ -2,6 +2,6 @@
using namespace jop;
Change::Change(Database &database) {
Change::Change(Database &database) : database_(database) {
}

View File

@ -12,6 +12,8 @@ public:
Folder();
private:
};