From 314f3bd2a043c8e8175372769c53e9614287d40e Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Wed, 30 Jul 2025 19:22:03 +0200 Subject: [PATCH] load repositories on startup --- application/store.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/application/store.c b/application/store.c index cdd1735..4694991 100644 --- a/application/store.c +++ b/application/store.c @@ -47,6 +47,8 @@ #include "../dbutils/dbutils/sqlite.h" #include "cx/mempool.h" +#define SQL_REPOSITORY_GET_ALL "select * from repositories;" + #define SQL_NOTEBOOK_STRUCTURE "with recursive cols as (\n" \ " select 1 as depth, '' as path, * from resources where resource_id = ?\n" \ " union all\n" \ @@ -362,11 +364,8 @@ void note_store_reload() { } // NoteStore root object - NoteStore *store = cxMalloc(a, sizeof(NoteStore)); + NoteStore *store = cxZalloc(a, sizeof(NoteStore)); store->mp = mp; - store->root = NULL; - store->trash = NULL; - store->repositories = cxLinkedListCreate(a, NULL, CX_STORE_POINTERS); // key: resource_id value: Notebook* CxMap *collection_map = cxHashMapCreate(NULL, CX_STORE_POINTERS, cxListSize(collections) + 16); @@ -400,6 +399,18 @@ void note_store_reload() { cxMapFree(collection_map); + // get repositories + DBUQuery *q2 = connection->createQuery(connection, NULL); + dbuQuerySetSQL(q2, SQL_REPOSITORY_GET_ALL); + DBUObjectBuilder *builder2 = dbuObjectBuilder(repository_class, q2, mp->allocator); + CxList *repositories = dbuObjectBuilderGetList(builder2); + if(!repositories) { + // TODO: error + } else { + store->repositories = repositories; + } + dbuObjectBuilderDestroy(builder2); + if(current_store) { cxMempoolFree(current_store->mp); } -- 2.47.3