From 4398458248233f4bbeb1236f8ab91d11d0136a74 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 12 Mar 2008 23:57:56 -0500 Subject: [PATCH] add ensure-table --- extra/db/tuples/tuples-tests.factor | 10 ++++++---- extra/db/tuples/tuples.factor | 6 +++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/extra/db/tuples/tuples-tests.factor b/extra/db/tuples/tuples-tests.factor index 584282e1c8..4c47066d35 100755 --- a/extra/db/tuples/tuples-tests.factor +++ b/extra/db/tuples/tuples-tests.factor @@ -30,9 +30,11 @@ SYMBOL: person3 SYMBOL: person4 : test-tuples ( -- ) - [ person drop-table ] [ drop ] recover + [ ] [ person ensure-table ] unit-test + [ ] [ person drop-table ] unit-test [ ] [ person create-table ] unit-test [ person create-table ] must-fail + [ ] [ person ensure-table ] unit-test [ ] [ person1 get insert-tuple ] unit-test @@ -191,8 +193,8 @@ TUPLE: annotation n paste-id summary author mode contents ; [ native-person-schema test-tuples ] test-sqlite [ assigned-person-schema test-tuples ] test-sqlite -[ native-person-schema test-tuples ] test-postgresql -[ assigned-person-schema test-tuples ] test-postgresql +! [ native-person-schema test-tuples ] test-postgresql +! [ assigned-person-schema test-tuples ] test-postgresql TUPLE: serialize-me id data ; @@ -211,7 +213,7 @@ TUPLE: serialize-me id data ; ] [ T{ serialize-me f 1 } select-tuples ] unit-test ; [ test-serialize ] test-sqlite -[ test-serialize ] test-postgresql +! [ test-serialize ] test-postgresql TUPLE: exam id name score ; diff --git a/extra/db/tuples/tuples.factor b/extra/db/tuples/tuples.factor index 32055ccedc..82147a2efa 100755 --- a/extra/db/tuples/tuples.factor +++ b/extra/db/tuples/tuples.factor @@ -3,7 +3,8 @@ USING: arrays assocs classes db kernel namespaces tuples words sequences slots math math.parser io prettyprint db.types continuations -mirrors sequences.lib tools.walker combinators.lib ; +mirrors sequences.lib tools.walker combinators.lib +combinators.cleave ; IN: db.tuples : define-persistent ( class table columns -- ) @@ -73,6 +74,9 @@ HOOK: insert-tuple* db ( tuple statement -- ) : drop-table ( class -- ) drop-sql-statement [ execute-statement ] with-disposals ; +: ensure-table ( class -- ) + [ dup drop-table ] ignore-errors create-table ; + : insert-native ( tuple -- ) dup class db get db-insert-statements [ ] cache