1 ! You will need to run 'createdb factor-test' to create the database.
2 ! Set username and password in the 'connect' word.
5 USING: kernel postgresql alien errors io prettyprint sequences namespaces ;
8 : test-connection ( host port pgopts pgtty db user pass -- bool )
9 [ [ ] with-postgres ] catch "Error connecting!" "Connected!" ? print ;
13 "localhost" "" "" "" "test" "postgres" "" [
14 "drop table animal" do-command
16 "create table animal (id serial not null primary key, species varchar(256), name varchar(256), age integer)" do-command
17 "insert into animal (species, name, age) values ('lion', 'Mufasa', 5)"
20 "select * from animal where name = 'Mufasa'" [ ] do-query
21 "select * from animal where name = 'Mufasa'"
23 result>seq length 1 = [ "...there can only be one Mufasa..." throw ] unless
26 "insert into animal (species, name, age) values ('lion', 'Simba', 1)"
29 "select * from animal"
32 result>seq print-table
36 ! [ "select asdf from animal"
37 ! [ ] do-query ] catch [ "caught: " write print ] when*
38 ! "select asdf from animal" [ ] do-query
39 ! "aofijweafew" do-command