2009-04-11 14:02:47 -04:00
|
|
|
! 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
|
|
|
|
|
|
2009-04-11 14:02:47 -04:00
|
|
|
GENERIC: db-open ( db -- db-connection )
|
2009-04-11 21:21:04 -04:00
|
|
|
|
|
|
|
|
GENERIC: db-close ( handle -- )
|
|
|
|
|
|
2009-04-11 14:02:47 -04:00
|
|
|
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 ;
|
2009-04-11 14:02:47 -04:00
|
|
|
|
|
|
|
|
: with-db ( db quot -- )
|
2009-04-11 21:21:04 -04:00
|
|
|
[ db-open db-connection over ] dip
|
2009-04-11 14:02:47 -04:00
|
|
|
'[ _ [ drop @ ] with-disposal ] with-variable ; inline
|