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:
parent
959e5be871
commit
2491a8dab5
@ -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.
|
||||
|
@ -24,7 +24,7 @@ public:
|
||||
private:
|
||||
|
||||
QQuickView view_;
|
||||
Database db_;
|
||||
Database& db_;
|
||||
NoteCollection noteCollection_;
|
||||
FolderModel folderModel_;
|
||||
NoteModel noteModel_;
|
||||
|
@ -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_;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -2,6 +2,6 @@
|
||||
|
||||
using namespace jop;
|
||||
|
||||
Change::Change(Database &database) {
|
||||
Change::Change(Database &database) : database_(database) {
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ public:
|
||||
|
||||
Folder();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user