Skip to content

gleam: implement DB layer with gleam_pgo #9

@HeyItWorked

Description

@HeyItWorked

Task

Create gleam-bookshelf/src/db.gleam with all 5 CRUD database functions.

Functions to implement

  • insert_book(conn, title, author, status) -> Result(Book, AppError)
  • get_all_books(conn) -> Result(List(Book), AppError)
  • get_book_by_id(conn, id) -> Result(Book, AppError)
  • update_book(conn, id, title, author, status) -> Result(Book, AppError)
  • delete_book(conn, id) -> Result(Nil, AppError)

Key differences from Go/TS

  • No global mutable stateconn (pgo.Connection) is passed as an argument, not stored in a module-level variable
  • Row decoder — must build a dynamic.decode4(...) decoder to map SQL columns to Book fields
  • use keyword — replaces Go's if err != nil pattern for chaining fallible operations
  • SQL is identical — same $1, $2 parameterized queries, same RETURNING clauses

Acceptance criteria

  • All 5 functions implemented with proper Result return types
  • Row decoder correctly maps (id, title, author, status) columns
  • delete_book returns Error(NotFound) when 0 rows affected
  • gleam build passes

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestgleamGleam implementation

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions