1 ! Copyright (C) 2008 Slava Pestov, Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: concurrency.combinators db.pools db.sqlite db.tuples
4 db.types kernel math random threads tools.test db sequences
5 io prettyprint db.postgresql accessors io.files.temp
6 namespaces fry system math.parser ;
9 : postgresql-test-db ( -- postgresql-db )
13 "thepasswordistrust" >>password
14 "factor-test" >>database ;
16 : sqlite-test-db ( -- sqlite-db )
17 "tuples-test.db" temp-file <sqlite-db> ;
20 ! These words leak resources, but are useful for interactivel testing
21 : set-sqlite-db ( -- )
22 sqlite-db db-open db-connection set ;
24 : set-postgresql-db ( -- )
25 postgresql-db db-open db-connection set ;
28 : test-sqlite ( quot -- )
30 [ ] [ sqlite-test-db _ with-db ] unit-test
33 : test-postgresql ( quot -- )
35 os windows? cpu x86.64? and [
36 [ ] [ postgresql-test-db _ with-db ] unit-test
41 TUPLE: test-1 id a b c ;
44 { "id" "ID" INTEGER +db-assigned-id+ }
45 { "a" "A" { VARCHAR 256 } +not-null+ }
46 { "b" "B" { VARCHAR 256 } +not-null+ }
47 { "c" "C" { VARCHAR 256 } +not-null+ }
50 TUPLE: test-2 id x y z ;
53 { "id" "ID" INTEGER +db-assigned-id+ }
54 { "x" "X" { VARCHAR 256 } +not-null+ }
55 { "y" "Y" { VARCHAR 256 } +not-null+ }
56 { "z" "Z" { VARCHAR 256 } +not-null+ }
59 : test-1-tuple ( -- tuple )
60 f 100 random 100 random 100 random [ number>string ] tri@
63 : db-tester ( test-db -- )
74 test-1-tuple insert-tuple yield
80 : db-tester2 ( test-db -- )
90 test-1-tuple insert-tuple yield