1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-02-01 19:15:01 +02:00

Get folders by path

This commit is contained in:
Laurent Cozic 2017-02-03 20:47:45 +00:00
parent f0c0bfdea1
commit 83f5bc2916
5 changed files with 31 additions and 13 deletions

View File

@ -132,15 +132,18 @@ int CliApplication::exec() {
}
if (command == "touch") {
// QString path = args.size() ? args[0] : QString();
// if (path == "") {
// std::vector<std::unique_ptr<Folder>> folders = Folder::all();
// for (size_t i = 0; i < folders.size(); i++) {
// qDebug().noquote() << folders[i].get()->value("title").toString();
// }
// } else {
// // TODO: Get folder by name
// }
QString path = args.size() ? args[0] : QString();
if (path == "") {
// std::vector<std::unique_ptr<Folder>> folders = Folder::all();
// for (size_t i = 0; i < folders.size(); i++) {
// qDebug().noquote() << folders[i].get()->value("title").toString();
// }
} else {
std::vector<std::unique_ptr<Folder>> folders = Folder::pathToFolders(path, true);
for (size_t i = 0; i < folders.size(); i++) {
qDebug() << folders[i]->value("title").toString();
}
}
}
qDebug() << "===========================================";

View File

@ -13,7 +13,7 @@ Database::~Database() {
void Database::initialize(const QString &path) {
version_ = -1;
transactionCount_ = 0;
logQueries_ = !false;
logQueries_ = true;
//QFile::remove(path);
@ -137,7 +137,7 @@ bool Database::commit() {
bool Database::execQuery(QSqlQuery &query) {
if (logQueries_) {
QString sql = query.lastQuery();
if (sql.startsWith("insert", Qt::CaseInsensitive)) {
// if (sql.startsWith("insert", Qt::CaseInsensitive)) {
qDebug().noquote() << "SQL:" << sql;
QMapIterator<QString, QVariant> i(query.boundValues());
@ -145,7 +145,7 @@ bool Database::execQuery(QSqlQuery &query) {
i.next();
qDebug().noquote() << "SQL:" << i.key() << "=" << i.value().toString();
}
}
// }
}
return query.exec();

View File

@ -49,7 +49,7 @@ bool BaseModel::load(const QString &id) {
bool BaseModel::loadByField(const QString& parentId, const QString& field, const QString& fieldValue) {
QSqlQuery q(jop::db().database());
QString sql = QString("SELECT %1 FROM %2 WHERE %3 = :field_value AND parent_id = :parent_id LIMIT 1")
QString sql = QString("SELECT %1 FROM %2 WHERE `%3` = :field_value AND parent_id = :parent_id LIMIT 1")
.arg(BaseModel::tableFieldNames(table()).join(","))
.arg(BaseModel::tableName(table()))
.arg(field);

View File

@ -49,6 +49,19 @@ std::vector<std::unique_ptr<Note>> Folder::notes(const QString &orderBy, int lim
return output;
}
std::vector<std::unique_ptr<Folder>> Folder::pathToFolders(const QString& path, bool isNotePath) {
std::vector<std::unique_ptr<Folder>> output;
QStringList parts = path.split('/');
QString parentId = "";
for (int i = 0; i < parts.size(); i++) {
std::unique_ptr<Folder> folder(new Folder());
bool ok = folder->loadByField(parentId, "title", parts[i]);
qWarning() << "Folder does not exist" << parts[i];
output.push_back(std::move(folder));
}
return output;
}
int Folder::noteIndexById(const QString &orderBy, const QString& id) const {
qDebug() << "Folder::noteIndexById" << orderBy << id;

View File

@ -15,6 +15,7 @@ public:
static int count();
static std::vector<std::unique_ptr<Folder>> all(const QString& orderBy = "title");
static std::vector<std::unique_ptr<Folder>> pathToFolders(const QString& path, bool isNotePath);
//Table table() const;
bool primaryKeyIsUuid() const;
@ -23,6 +24,7 @@ public:
std::vector<std::unique_ptr<Note> > notes(const QString& orderBy, int limit, int offset) const;
int noteIndexById(const QString& orderBy, const QString &id) const;
};
}