 
 HOOK: <select-by-slots-statement> db ( tuple -- tuple )
 
-: setup-select ( tuple -- tuple statement )
+: setup-select ( tuple -- statement )
     dup dup class <select-by-slots-statement>
-    [ bind-tuple ] 2keep ;
+    [ bind-tuple ] keep ;
 
 : select-tuple ( tuple -- tuple )
-    setup-select query-tuple ;
+    setup-select query-tuples first ;
 
-: select-tuples ( tuple -- tuple )
-    setup-select query-tuples ;
+: select-tuples ( tuple -- tuple ) setup-select query-tuples ;
 
 ! uniqueResult


: insert-native ( tuple -- )
    dup class <insert-native-statement>
    [ bind-tuple ] 2keep query-tuple drop ;

: insert-assigned ( tuple -- )
    dup <insert-assigned-statement>


HOOK: row-column-typed db ( result-set n type -- sql )

: resulting-tuple ( row out-params -- tuple )
    dup first sql-spec-class construct-empty [
        [
            >r [ sql-spec-type sql-type>factor-type ] keep
            sql-spec-slot-name r> set-slot-named
        ] curry 2each
    ] keep ;

: query-tuples ( statement -- seq )
    [ statement-out-params ] keep query-results [
        ! out-parms result-set
        [
            sql-row swap resulting-tuple
        ] with query-map
    ] with-disposal ;
 
: query-modify-tuple ( tuple statement -- )
    [ query-results [ sql-row ] with-disposal ] keep
    statement-out-params rot [
        >r [ sql-spec-type sql-type>factor-type ] keep
        sql-spec-slot-name r> set-slot-named
    ] curry 2each ;

: sql-props ( class -- columns table )
    dup db-columns swap db-table ;
