Skip to content

Commit acf3cda

Browse files
committed
Add helper for nullable decoders
1 parent 166ee26 commit acf3cda

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

gleam.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name = "pturso"
2-
version = "1.0.0"
2+
version = "1.1.0"
33
description = "Turso for Gleam. Similar to the sqlight library, but uses a Port instead of a NIF (so it works fine even for statically linked BEAM builds)."
44
licences = ["MIT"]
55
repository = { type = "github", user = "Resonious", repo = "pturso" }

src/pturso.gleam

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import gleam/option
12
import gleam/list
23
import gleam/result.{try}
34
import gleam/dynamic/decode
@@ -34,6 +35,11 @@ pub type Error {
3435
DecodeError(errors: List(decode.DecodeError))
3536
}
3637

38+
pub fn nullable(decoder: decode.Decoder(Param)) -> decode.Decoder(Param) {
39+
decode.optional(decoder)
40+
|> decode.map(option.unwrap(_, Null))
41+
}
42+
3743
@external(erlang, "pturso_ffi", "now_ms")
3844
fn now_ms() -> Int
3945

0 commit comments

Comments
 (0)