2 * SQL database interfaces for Standard ML
3 * Copyright (C
) 2003 Adam Chlipala
5 * This library is free software
; you can redistribute it
and/or
6 * modify it under the terms
of the GNU Lesser General Public
7 * License
as published by the Free Software Foundation
; either
8 * version
2.1 of the License
, or (at your option
) any later version
.
10 * This library is distributed
in the hope that it will be useful
,
11 * but WITHOUT ANY WARRANTY
; without even the implied warranty
of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
. See the GNU
13 * Lesser General Public License for more details
.
15 * You should have received a copy
of the GNU Lesser General Public
16 * License along
with this library
; if not
, write to the Free Software
17 * Foundation
, Inc
., 59 Temple Place
, Suite
330, Boston
, MA
02111-1307 USA
20 (* Functor for creating a client from a minimal driver
*)
22 functor SqlClient(Driver
: SQL_DRIVER
) :> SQL_CLIENT
23 where type conn
= Driver
.conn
=
27 fun oneOrNoRows conn query
=
28 fold
conn (fn (row
, NONE
) => SOME row
29 |
(_
, SOME _
) => raise Sql
"Expected one or zero rows; got multiple") NONE query
31 fun oneRow conn query
=
32 (case oneOrNoRows conn query
of
33 NONE
=> raise Sql
"Expected one row; got none"
36 fun app conn f q
= fold
conn (fn (row
, ()) => f row
) () q
37 fun map conn f q
= List.rev (fold
conn (fn (row
, out
) => (f row
)::out
) [] q
)
39 fun query conn q
= List.rev (fold conn
op:: [] q
)