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