Compare commits

..

No commits in common. "802c2f99af0bd42e3dd4b8a357ddd4c76fe7e0d6" and "0a6d1dc1717a750d94555f534df96b9adbe4542e" have entirely different histories.

View file

@ -24,6 +24,10 @@ pub fn handle_request(req: Request) -> Response {
} }
} }
type Row {
Row(String)
}
fn handle_previous(hash) { fn handle_previous(hash) {
let db_path = "members.db" let db_path = "members.db"
use conn <- sqlight.with_connection(db_path) use conn <- sqlight.with_connection(db_path)
@ -32,10 +36,10 @@ fn handle_previous(hash) {
"select previous from ring where hash = ?", "select previous from ring where hash = ?",
on: conn, on: conn,
with: [sqlight.text(hash)], with: [sqlight.text(hash)],
expecting: dynamic.element(0, dynamic.string), expecting: dynamic.decode1(Row, dynamic.element(0, dynamic.string)),
) )
case previous { case previous {
Ok([previous_link]) -> wisp.redirect(previous_link) Ok([Row(previous_link)]) -> wisp.redirect(previous_link)
_ -> wisp.not_found() _ -> wisp.not_found()
} }
} }
@ -48,10 +52,10 @@ fn handle_next(hash) {
"select next from ring where hash = ?", "select next from ring where hash = ?",
on: conn, on: conn,
with: [sqlight.text(hash)], with: [sqlight.text(hash)],
expecting: dynamic.element(0, dynamic.string), expecting: dynamic.decode1(Row, dynamic.element(0, dynamic.string)),
) )
case next { case next {
Ok([next_link]) -> wisp.redirect(next_link) Ok([Row(next_link)]) -> wisp.redirect(next_link)
_ -> wisp.not_found() _ -> wisp.not_found()
} }
} }
@ -64,10 +68,10 @@ fn handle_random() {
"select next from ring order by random() limit 1", "select next from ring order by random() limit 1",
on: conn, on: conn,
with: [], with: [],
expecting: dynamic.element(0, dynamic.string), expecting: dynamic.decode1(Row, dynamic.element(0, dynamic.string)),
) )
case random { case random {
Ok([random_link]) -> wisp.redirect(random_link) Ok([Row(random_link)]) -> wisp.redirect(random_link)
_ -> wisp.not_found() _ -> wisp.not_found()
} }
} }
@ -83,12 +87,12 @@ fn home_page(req: Request) -> Response {
"select member from ring order by member asc", "select member from ring order by member asc",
on: conn, on: conn,
with: [], with: [],
expecting: dynamic.element(0, dynamic.string), expecting: dynamic.decode1(Row, dynamic.element(0, dynamic.string)),
) )
let members = let members =
result.unwrap(members, []) result.unwrap(members, [])
|> list.map(fn(row) { |> list.map(fn(row) {
let member = row let Row(member) = row
html.li([], [html.a([attribute.href(member)], [html.text(member)])]) html.li([], [html.a([attribute.href(member)], [html.text(member)])])
}) })
let html = let html =