kiranandcode / petrol

Petrol's an OCaml SQL API made to go FAST.
https://gopiandcode.github.io/petrol/petrol/index.html
Other
109 stars 6 forks source link

sqlite3: `expected BOOLEAN got BOOLEAN` #8

Closed fholmqvist closed 1 year ago

fholmqvist commented 1 year ago

Inserting a boolean value into an sqlite3 database throws an exception. Removing the boolean field fixes the problem.

Error message

Fatal error: exception Failure("wrapped value list did not conform to specification - expected BOOLEAN got BOOLEAN")

Example program

open Petrol
open Petrol.Sqlite3

let db = StaticSchema.init ()

let todo, Expr.[title; desc; finished] =
  StaticSchema.declare_table db ~name:"todo"
    Schema.
      [ field "title" ~ty:Type.text
      ; field "desc" ~ty:Type.text
      ; field "finished" ~ty:Type.bool ]

let insert_todo ~title:t ~desc:d ~finished:fn db =
  Query.insert ~table:todo
    ~values:Expr.[title := s t; desc := s d; finished := bl fn]
  |> Request.make_zero |> Petrol.exec db

let test_insert =
  let open Lwt_result.Syntax in
  let* conn = Caqti_lwt.connect (Uri.of_string "sqlite3://::memory:") in
  let* _ = Petrol.StaticSchema.initialise db conn in
  insert_todo ~title:"use petrol" ~desc:"it seems amazing" ~finished:true conn

let () =
  match Lwt_main.run test_insert with
  | Ok _ ->
      print_endline "ok"
  | Error err ->
      print_endline (Caqti_error.show err)

Dune

(executable
 (name todo)
 (libraries petrol caqti-driver-sqlite3))

Setup

kiranandcode commented 1 year ago

Awesome, thanks for the bug report!

Small bug on my end where I didn't update the equality function on types between versions.

Will push a fix later today!