···3232 |sql}]
3333end
34343535-let execute_raw db_path sql =
3636- let db = Sqlite3.db_open db_path in
3737- try
3838- let rc = Sqlite3.exec db sql in
3939- let _ = try Sqlite3.db_close db with _ -> true in
4040- match rc with
3535+let execute_raw conn sql =
3636+ let module C = (val conn : Caqti_lwt.CONNECTION) in
3737+ match C.driver_connection with
3838+ | Some (Caqti_driver_sqlite3.Driver_connection db) -> (
3939+ match Sqlite3.exec db sql with
4140 | Sqlite3.Rc.OK ->
4241 Lwt.return_ok ()
4342 | _ ->
4443 let err_msg = Sqlite3.errmsg db in
4545- Lwt.return_error (Failure ("sql error: " ^ err_msg))
4646- with e ->
4747- let _ = try Sqlite3.db_close db with _ -> true in
4848- Lwt.return_error e
4444+ Lwt.return_error
4545+ (Caqti_error.request_failed
4646+ ~uri:(Uri.of_string "sqlite3://")
4747+ ~query:sql (Caqti_error.Msg err_msg) ) )
4848+ | _ ->
4949+ Lwt.return_error
5050+ (Caqti_error.request_failed
5151+ ~uri:(Uri.of_string "sqlite3://")
5252+ ~query:sql (Caqti_error.Msg "driver_connection not available") )
49535054let parse_migration_filename filename =
5155 try
···5862 with _ -> None
59636064let run_migration db (id, name, sql) =
6161- (* I think it's better to do a transaction per migration, no harm in applying the ones that don't error *)
6265 Util.use_pool db (fun conn ->
6366 Util.transact conn (fun () ->
6464- let module C = (val conn : Caqti_lwt.CONNECTION) in
6565- let query =
6666- Caqti_request.Infix.( ->. ) Caqti_type.unit Caqti_type.unit sql
6767- in
6868- let result = C.exec query () in
6969- Lwt_result.map
7070- (fun _ ->
7171- let applied_at = Util.now_ms () in
7272- Queries.record_migration ~id ~name ~applied_at conn )
7373- result ) )
6767+ let open Lwt_result.Infix in
6868+ execute_raw conn sql
6969+ >>= fun () ->
7070+ let applied_at = Util.now_ms () in
7171+ Queries.record_migration ~id ~name ~applied_at conn ) )
74727573type migration_type = Data_store | User_store
7674
+2-2
pegasus/lib/repository.ml
···450450 in
451451 Lwt.return {commit= new_commit; results}
452452453453-let load ?write ?(ensure_active = false) ?ds did : t Lwt.t =
453453+let load ?write ?create ?(ensure_active = false) ?ds did : t Lwt.t =
454454 let%lwt data_store_conn =
455455 match ds with
456456 | Some ds ->
···459459 Data_store.connect ?write ()
460460 in
461461 let%lwt user_db =
462462- try%lwt User_store.connect did
462462+ try%lwt User_store.connect ?create ~write:true did
463463 with _ ->
464464 Errors.invalid_request ~name:"RepoNotFound"
465465 "your princess is in another castle"