🐿️ squirrel - type safe SQL in Gleam

squirrel_demo.mp4

What’s Squirrel?

If you need to talk with a database in Gleam you’ll have to write something like this:

import pog
import gleam/dynamic/decode

pub type FindSquirrelRow {
FindSquirrelRow(name: String, owned_acorns: Int)
}

/// Find a squirrel and its owned acorns given its name.
///
pub fn find_squirrel(db: pog.Connection, name: String) {
let squirrel_row_decoder = {
use name <- decode.field(0, decode.string)
use owned_acorns <- decode.field(1, decode.int)
decode.success(FindSquirrelRow(name:, owned_acorns:))
}

"
select
name,
owned_acorns
from
squirrel
where
name = $1
"
|> pog.query
|> pog.parameter(pog.text(name))
|> pog.returning(squirrel_row_decoder)
|> pog.execute(db)
}

This is probably fine if you have a few …

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help