From da21dd57634aebffe0f5833b598e1128fafc0def Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sat, 27 Apr 2024 12:31:12 +0530 Subject: npassd/collection: init --- src/npassd/db.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'src/npassd/db.c') diff --git a/src/npassd/db.c b/src/npassd/db.c index 5afa45e..f55bede 100644 --- a/src/npassd/db.c +++ b/src/npassd/db.c @@ -7,17 +7,23 @@ #define DB_NAME "secret_service.sqlite" -const char sql_stmt_init[] = "CREATE TABLE IF NOT EXISTS store (" - " storeid INTEGER PRIMARY KEY," - " name TEXT NOT NULL UNIQUE" - ");" - "CREATE TABLE IF NOT EXISTS lookup (" - " key TEXT NOT NULL," - " value TEXT NOT NULL," - " storeid INTEGER," - " UNIQUE(storeid, key)," - " FOREIGN KEY(storeid) REFERENCES store(storeid)" - ");"; +const char sql_stmt_init[] = + "CREATE TABLE IF NOT EXISTS collections (" + " id INTEGER PRIMARY KEY," + " root TEXT NOT NULL UNIQUE," + " label TEXT UNIQUE," + " alias TEXT UNIQUE," + " created INTEGER," + " modified INTEGER" + ");" + "CREATE TABLE IF NOT EXISTS collection_attrs (" + " id INTEGER PRIMARY KEY," + " key TEXT NOT NULL," + " value TEXT NOT NULL," + " collectionid INTEGER," + " UNIQUE(key, collectionid)" + " FOREIGN KEY(collectionid) REFERENCES collections(id)" + ");"; int db_init(const char *store_path, struct sqlite3 **db) { @@ -41,6 +47,7 @@ int db_init(const char *store_path, struct sqlite3 **db) ret = sqlite3_exec(*db, sql_stmt_init, NULL, NULL, NULL); if (ret != SQLITE_OK) { + sqlite3_close(*db); print_err("Failed to create tables: %s", sqlite3_errmsg(*db)); return -EPERM; } -- cgit v1.2.3