From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 2B0667EEBF for ; Sun, 5 Jul 2015 17:37:19 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of mfp@acm.org) identity=pra; client-ip=86.109.99.145; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ferferse@telefonica.net"; x-sender="mfp@acm.org"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of ferferse@telefonica.net designates 86.109.99.145 as permitted sender) identity=mailfrom; client-ip=86.109.99.145; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ferferse@telefonica.net"; x-sender="ferferse@telefonica.net"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@smtp.movistar.es) identity=helo; client-ip=86.109.99.145; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ferferse@telefonica.net"; x-sender="postmaster@smtp.movistar.es"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0B/AgA/TplVlJFjbVZcg2ZgqxMBBpQkhXeBaAEBAQEBARIBAQEBBwsLCR8wQQWDXgEFMgFWCw4KCSUPBQ0bIQESiBoDFgnBIg2GCASGHYUugk0egWiDUYEUAQSUFYRihSGBZIE7hnOJDINAg12EI22CSwEBAQ X-IPAS-Result: A0B/AgA/TplVlJFjbVZcg2ZgqxMBBpQkhXeBaAEBAQEBARIBAQEBBwsLCR8wQQWDXgEFMgFWCw4KCSUPBQ0bIQESiBoDFgnBIg2GCASGHYUugk0egWiDUYEUAQSUFYRihSGBZIE7hnOJDINAg12EI22CSwEBAQ X-IronPort-AV: E=Sophos;i="5.15,410,1432591200"; d="scan'208";a="139023638" Received: from smtp21.acens.net (HELO smtp.movistar.es) ([86.109.99.145]) by mail3-smtp-sop.national.inria.fr with ESMTP; 05 Jul 2015 17:37:18 +0200 X-CTCH-RefID: str=0001.0A0B0206.55994F2B.0037,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0 X-CTCH-Spam: Unknown Received: from AIKA (83.60.40.137) by smtp.movistar.es (8.6.122.03) (authenticated as ferferse$telefonica.net) id 558BFF10007E7A46; Sun, 5 Jul 2015 15:37:15 +0000 Received: from mfp by AIKA with local (Exim 4.80) (envelope-from ) id 1ZBlyk-0006Sc-Hs; Sun, 05 Jul 2015 17:37:14 +0200 Date: Sun, 5 Jul 2015 17:37:14 +0200 From: Mauricio =?iso-8859-1?Q?Fern=E1ndez?= To: Erkki Seppala , caml-list@inria.fr Message-ID: <20150705153714.GA7839@AIKA> Mail-Followup-To: Erkki Seppala , caml-list@inria.fr References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [Caml-list] looking for "real world" sqlite3 examples On Sun, Jul 05, 2015 at 04:45:14PM +0300, Erkki Seppala wrote: > Martin DeMello writes: > > > 2. type conversions - in the absence of an orm, do i have to write my > > own by hand per resultset. or is there some intermediate-level library > > that i haven't found that would automate some of it? > > > > 3. is there a maintained library for generating sql queries in a typed manner? > > You should look into SqlExpr: > > https://github.com/mfp/ocaml-sqlexpr/ > > I used it recently for a very small project, and it seemed to work > great, even if it doesn't ensure compile-time type safety like PGOCaml. There's a mechanism to unit test the queries automatically (ensuring that they're coherent with the DB's schema) which can be integrated in the regular build process, able to catch many (most) problems (syntax errors, missing/misnamed/ambiguous columns/tables, etc.), see https://github.com/mfp/ocaml-sqlexpr#syntax-extension It works by collecting all the statements that constitute the schema (marked as "sqlinit") along with the remaining regular queries ("sql" / "sqlc"), and then generating functions that initialize an empty DB and prepare all the statements against it (similarly to what PGOCaml does at compile-time). This can also serve as "early run-time checking", arguably stronger than PGOCaml in a way (because you can verify that the queries are valid against the DB's current schema, not against the one you had when compiling). If you're using OUnit and all your DB-related code lies in module MyDB, you can do something like this to unit test the SQL queries: open OUnit let test_sql f () = let b = Buffer.create 13 in let fmt = Format.formatter_of_buffer b in let contents b = Format.fprintf fmt "@?"; Buffer.contents b in if not (f fmt) then assert_failure (contents b) let tests = [ "SQL tests" >:: test_sql MyDB.auto_check_db; ... ] ... run_test_tt_main ("All" >::: tests) -- Mauricio Fernández