package sihl

  1. Overview
  2. Docs
The modular functional web framework

Install

Dune Dependency

Authors

Maintainers

Sources

sihl-queue-0.1.5.tbz
sha256=bfa7bde9af02bb83d5ca39d54797b05b43317f033d93d24ca86ca42ff8ef83a1
sha512=6bb8727f65116e8042aa1fb77b3c14851ce5238f7b412adadf0f8e5b52d5310e8f06056c96bf76a82ffd7096753f49b2b0482f41e18ee1ca94310b874fe81bf9

doc/src/sihl.database/id.ml.html

Source file id.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
type t = Uuidm.t

let pp = Uuidm.pp
let equal = Uuidm.equal
let random () = Uuidm.v `V4

let of_string id_string =
  match id_string |> Uuidm.of_string with
  | Some id -> Ok id
  | None ->
    Error
      (Printf.sprintf
         "Invalid id %s provided, can not convert string to uuidv4"
         id_string)
;;

let of_bytes id_bytes =
  let msg =
    Printf.sprintf "Invalid id %s provided, can not convert bytes to uuidv4" id_bytes
  in
  id_bytes |> Uuidm.of_bytes |> Option.to_result ~none:msg
;;

let to_string id = Uuidm.to_string id
let to_bytes id = Uuidm.to_bytes id
let is_valid_str id_string = id_string |> of_string |> Result.is_ok

let t_string =
  let ( let* ) = Result.bind in
  let encode uuid =
    let* uuid = of_string uuid in
    Ok (to_bytes uuid)
  in
  let decode uuid =
    let* uuid = of_bytes uuid in
    Ok (to_string uuid)
  in
  Caqti_type.(custom ~encode ~decode string)
;;

let t =
  let ( let* ) = Result.bind in
  let encode uuid = Ok (to_bytes uuid) in
  let decode uuid =
    let* uuid = of_bytes uuid in
    Ok uuid
  in
  Caqti_type.(custom ~encode ~decode octets)
;;

module Uuidm = Uuidm
OCaml

Innovation. Community. Security.