Skip to content

Commit

Permalink
getting the ids
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrot-lc committed Oct 21, 2024
1 parent 7f445dc commit 1b9e8a9
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/sqlite_merger.gleam
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit 1b9e8a9

Please sign in to comment.