2008-02-11 14:39:43 -05:00
|
|
|
USING: io.files kernel tools.test db db.sqlite db.tuples
|
|
|
|
db.types continuations namespaces ;
|
2008-02-11 00:11:16 -05:00
|
|
|
IN: temporary
|
|
|
|
|
|
|
|
TUPLE: person the-id the-name the-number ;
|
|
|
|
: <person> ( name age -- person )
|
|
|
|
{ set-person-the-name set-person-the-number } person construct ;
|
|
|
|
|
|
|
|
person "PERSON"
|
|
|
|
{
|
|
|
|
{ "the-id" "ROWID" INTEGER +native-id+ }
|
|
|
|
{ "the-name" "NAME" { VARCHAR 256 } +not-null+ }
|
|
|
|
{ "the-number" "AGE" INTEGER { +default+ 0 } }
|
|
|
|
} define-persistent
|
|
|
|
|
2008-02-11 14:39:43 -05:00
|
|
|
SYMBOL: the-person
|
|
|
|
|
2008-02-11 00:11:16 -05:00
|
|
|
: test-tuples ( -- )
|
2008-02-11 14:39:43 -05:00
|
|
|
[ person drop-table ] [ ] recover
|
|
|
|
person create-table
|
|
|
|
f "billy" 100 person construct-boa
|
|
|
|
the-person set
|
|
|
|
|
|
|
|
[ ] [ the-person get insert-tuple ] unit-test
|
2008-02-11 00:11:16 -05:00
|
|
|
|
2008-02-11 14:39:43 -05:00
|
|
|
[ 1 ] [ the-person get person-the-id ] unit-test
|
2008-02-11 00:11:16 -05:00
|
|
|
|
2008-02-11 14:39:43 -05:00
|
|
|
200 the-person get set-person-the-number
|
2008-02-11 00:11:16 -05:00
|
|
|
|
2008-02-11 14:39:43 -05:00
|
|
|
[ ] [ the-person get update-tuple ] unit-test
|
2008-02-11 00:11:16 -05:00
|
|
|
|
2008-02-11 14:39:43 -05:00
|
|
|
[ ] [ the-person get delete-tuple ] unit-test ;
|
2008-02-11 00:11:16 -05:00
|
|
|
|
|
|
|
: test-sqlite ( -- )
|
|
|
|
"tuples-test.db" resource-path <sqlite-db> [
|
|
|
|
test-tuples
|
|
|
|
] with-db ;
|
|
|
|
|
|
|
|
test-sqlite
|
|
|
|
|
|
|
|
! : test-postgres ( -- )
|
|
|
|
! resource-path <postgresql-db> [
|
|
|
|
! test-tuples
|
|
|
|
! ] with-db ;
|
2008-02-12 16:47:01 -05:00
|
|
|
|
|
|
|
! test-postgres
|