1 ! You will need to run 'createdb factor-test' to create the database.
2 ! Set username and password in the 'connect' word.
4 USING: kernel db.postgresql alien continuations io classes
5 prettyprint sequences namespaces tools.test db
6 db.tuples db.types unicode.case ;
7 IN: db.postgresql.tests
9 : test-db ( -- postgresql-db )
10 { "localhost" "postgres" "foob" "factor-test" } postgresql-db ;
12 [ ] [ test-db [ ] with-db ] unit-test
16 [ "drop table person;" sql-command ] ignore-errors
17 "create table person (name varchar(30), country varchar(30));"
20 "insert into person values('John', 'America');" sql-command
21 "insert into person values('Jane', 'New Zealand');" sql-command
28 { "Jane" "New Zealand" }
32 "select * from person" sql-query
39 { "Jane" "New Zealand" }
41 ] [ test-db [ "select * from person" sql-query ] with-db ] unit-test
46 "insert into person(name, country) values('Jimmy', 'Canada')"
54 { "Jane" "New Zealand" }
57 ] [ test-db [ "select * from person" sql-query ] with-db ] unit-test
62 "insert into person(name, country) values('Jose', 'Mexico')" sql-command
63 "insert into person(name, country) values('Jose', 'Mexico')" sql-command
71 "select * from person" sql-query length
79 "insert into person(name, country) values('Jose', 'Mexico')"
81 "insert into person(name, country) values('Jose', 'Mexico')"
89 "select * from person" sql-query length
94 : with-dummy-db ( quot -- )
95 >r T{ postgresql-db } db r> with-variable ;