Merge branch 'master' of git://factorcode.org/git/factor
commit
7eca88cdb5
|
@ -39,31 +39,13 @@ TUPLE: statement handle sql in-params out-params bind-params bound? type ;
|
||||||
TUPLE: simple-statement < statement ;
|
TUPLE: simple-statement < statement ;
|
||||||
TUPLE: prepared-statement < statement ;
|
TUPLE: prepared-statement < statement ;
|
||||||
|
|
||||||
SINGLETON: throwable
|
|
||||||
SINGLETON: nonthrowable
|
|
||||||
|
|
||||||
: make-throwable ( obj -- obj' )
|
|
||||||
dup sequence? [
|
|
||||||
[ make-throwable ] map
|
|
||||||
] [
|
|
||||||
throwable >>type
|
|
||||||
] if ;
|
|
||||||
|
|
||||||
: make-nonthrowable ( obj -- obj' )
|
|
||||||
dup sequence? [
|
|
||||||
[ make-nonthrowable ] map
|
|
||||||
] [
|
|
||||||
nonthrowable >>type
|
|
||||||
] if ;
|
|
||||||
|
|
||||||
TUPLE: result-set sql in-params out-params handle n max ;
|
TUPLE: result-set sql in-params out-params handle n max ;
|
||||||
|
|
||||||
: construct-statement ( sql in out class -- statement )
|
: construct-statement ( sql in out class -- statement )
|
||||||
new
|
new
|
||||||
swap >>out-params
|
swap >>out-params
|
||||||
swap >>in-params
|
swap >>in-params
|
||||||
swap >>sql
|
swap >>sql ;
|
||||||
throwable >>type ;
|
|
||||||
|
|
||||||
HOOK: <simple-statement> db ( str in out -- statement )
|
HOOK: <simple-statement> db ( str in out -- statement )
|
||||||
HOOK: <prepared-statement> db ( str in out -- statement )
|
HOOK: <prepared-statement> db ( str in out -- statement )
|
||||||
|
@ -81,12 +63,9 @@ GENERIC: more-rows? ( result-set -- ? )
|
||||||
|
|
||||||
GENERIC: execute-statement* ( statement type -- )
|
GENERIC: execute-statement* ( statement type -- )
|
||||||
|
|
||||||
M: throwable execute-statement* ( statement type -- )
|
M: object execute-statement* ( statement type -- )
|
||||||
drop query-results dispose ;
|
drop query-results dispose ;
|
||||||
|
|
||||||
M: nonthrowable execute-statement* ( statement type -- )
|
|
||||||
drop [ query-results dispose ] [ 2drop ] recover ;
|
|
||||||
|
|
||||||
: execute-statement ( statement -- )
|
: execute-statement ( statement -- )
|
||||||
dup sequence? [
|
dup sequence? [
|
||||||
[ execute-statement ] each
|
[ execute-statement ] each
|
||||||
|
|
|
@ -8,9 +8,8 @@ IN: db.queries
|
||||||
GENERIC: where ( specs obj -- )
|
GENERIC: where ( specs obj -- )
|
||||||
|
|
||||||
: maybe-make-retryable ( statement -- statement )
|
: maybe-make-retryable ( statement -- statement )
|
||||||
dup in-params>> [ generator-bind? ] contains? [
|
dup in-params>> [ generator-bind? ] contains?
|
||||||
make-retryable
|
[ make-retryable ] when ;
|
||||||
] when ;
|
|
||||||
|
|
||||||
: query-make ( class quot -- )
|
: query-make ( class quot -- )
|
||||||
>r sql-props r>
|
>r sql-props r>
|
||||||
|
|
|
@ -199,10 +199,9 @@ TUPLE: annotation n paste-id summary author mode contents ;
|
||||||
: test-sqlite ( quot -- )
|
: test-sqlite ( quot -- )
|
||||||
>r "tuples-test.db" temp-file sqlite-db r> with-db ;
|
>r "tuples-test.db" temp-file sqlite-db r> with-db ;
|
||||||
|
|
||||||
! : test-postgresql ( quot -- )
|
: test-postgresql ( quot -- )
|
||||||
! >r { "localhost" "postgres" "foob" "factor-test" } postgresql-db r> with-db ;
|
>r { "localhost" "postgres" "foob" "factor-test" } postgresql-db r> with-db ;
|
||||||
|
|
||||||
: test-postgresql drop ;
|
|
||||||
: test-repeated-insert
|
: test-repeated-insert
|
||||||
[ ] [ person ensure-table ] unit-test
|
[ ] [ person ensure-table ] unit-test
|
||||||
[ ] [ person1 get insert-tuple ] unit-test
|
[ ] [ person1 get insert-tuple ] unit-test
|
||||||
|
|
|
@ -112,8 +112,8 @@ M: retryable execute-statement* ( statement type -- )
|
||||||
|
|
||||||
: recreate-table ( class -- )
|
: recreate-table ( class -- )
|
||||||
[
|
[
|
||||||
drop-sql-statement make-nonthrowable
|
[ drop-sql-statement [ execute-statement ] with-disposals
|
||||||
[ execute-statement ] with-disposals
|
] curry ignore-errors
|
||||||
] [ create-table ] bi ;
|
] [ create-table ] bi ;
|
||||||
|
|
||||||
: ensure-table ( class -- )
|
: ensure-table ( class -- )
|
||||||
|
|
Loading…
Reference in New Issue