factor/extra/db2/connections/connections.factor

24 lines
635 B
Factor
Raw Normal View History

! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors destructors fry kernel namespaces ;
IN: db2.connections
TUPLE: db-connection handle ;
2009-04-11 21:21:04 -04:00
: new-db-connection ( handle class -- db-connection )
new
swap >>handle ; inline
GENERIC: db-open ( db -- db-connection )
2009-04-11 21:21:04 -04:00
GENERIC: db-close ( handle -- )
HOOK: parse-db-error db-connection ( error -- error' )
M: db-connection dispose ( db-connection -- )
2009-04-11 21:21:04 -04:00
[ db-close ] [ f >>handle drop ] bi ;
: with-db ( db quot -- )
2009-04-11 21:21:04 -04:00
[ db-open db-connection over ] dip
'[ _ [ drop @ ] with-disposal ] with-variable ; inline