From 1b9e8a9ad4ef025af7cf7eed4c6b73cbbb324569 Mon Sep 17 00:00:00 2001 From: Pierrot LC Date: Mon, 21 Oct 2024 22:43:52 +0200 Subject: [PATCH] getting the ids --- src/sqlite_merger.gleam | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/sqlite_merger.gleam b/src/sqlite_merger.gleam index 553bad7..d7e7d24 100644 --- a/src/sqlite_merger.gleam +++ b/src/sqlite_merger.gleam @@ -1,26 +1,29 @@ import gleam/dynamic -import gleam/int import gleam/io import gleam/list -import gleam/string +import gleam/set.{type Set} import sqlight -pub fn main() { - io.println("Hello from sqlite_merger!") - - use conn <- sqlight.with_connection("file:bookmarks.db") - let query = "SELECT id, url FROM bookmarks;" - let decoder = dynamic.tuple2(dynamic.int, dynamic.string) - let message = case +fn list_items(db: String) -> Set(Int) { + use conn <- sqlight.with_connection("file:" <> db) + let query = "SELECT id, id FROM bookmarks;" + let decoder = dynamic.element(0, dynamic.int) + let assert Ok(ids) = sqlight.query(query, on: conn, with: [], expecting: decoder) - { - Error(e) -> e.message - Ok(res) -> - res - |> list.map(fn(x) { x.0 }) - |> list.map(fn(x) { int.to_string(x) }) - |> list.map(fn(x) { x <> " " }) - |> string.concat - } - io.println(message) + + ids + |> list.map(fn(x) { x }) + |> set.from_list +} + +fn diff_items(db1: String, db2: String) -> Set(Int) { + let items1 = list_items(db1) + let items2 = list_items(db2) + + set.difference(items1, items2) +} + +pub fn main() { + let ids = list_items("bookmarks.db") + io.println("Hey") }