use new lookup for sqlite
parent
f5485c1a3d
commit
be8ac1d7b6
|
@ -126,7 +126,7 @@ M: sqlite-db create-sql-statement ( class -- statement )
|
|||
"(" 0% [ ", " 0% ] [
|
||||
dup column-name>> 0%
|
||||
" " 0%
|
||||
dup type>> t lookup-type 0%
|
||||
dup type>> lookup-create-type 0%
|
||||
modifiers 0%
|
||||
] interleave ");" 0%
|
||||
] sqlite-make dup sql>> . ;
|
||||
|
@ -247,42 +247,34 @@ M: sqlite-db <select-by-slots-statement> ( tuple class -- statement )
|
|||
M: sqlite-db random-id-quot ( -- quot )
|
||||
[ 64 [ 2^ random ] keep 1 - set-bit ] ;
|
||||
|
||||
M: sqlite-db modifier-table ( -- hashtable )
|
||||
M: sqlite-db persistent-table ( -- assoc )
|
||||
H{
|
||||
{ +native-id+ "primary key" }
|
||||
{ +assigned-id+ "primary key" }
|
||||
{ +random-id+ "primary key" }
|
||||
{ +autoincrement+ "autoincrement" }
|
||||
{ +unique+ "unique" }
|
||||
{ +default+ "default" }
|
||||
{ +null+ "null" }
|
||||
{ +not-null+ "not null" }
|
||||
{ system-random-generator "" }
|
||||
{ secure-random-generator "" }
|
||||
{ random-generator "" }
|
||||
{ +native-id+ { "integer primary key" "integer primary key" f } }
|
||||
{ +assigned-id+ { f f "primary key" } }
|
||||
{ +random-id+ { "integer primary key" "integer primary key" f } }
|
||||
{ INTEGER { "integer" "integer" "primary key" } }
|
||||
{ BIG-INTEGER { "bigint" "bigint" } }
|
||||
{ SIGNED-BIG-INTEGER { "bigint" "bigint" } }
|
||||
{ UNSIGNED-BIG-INTEGER { "bigint" "bigint" } }
|
||||
{ TEXT { "text" "text" } }
|
||||
{ VARCHAR { "text" "text" } }
|
||||
{ DATE { "date" "date" } }
|
||||
{ TIME { "time" "time" } }
|
||||
{ DATETIME { "datetime" "datetime" } }
|
||||
{ TIMESTAMP { "timestamp" "timestamp" } }
|
||||
{ DOUBLE { "real" "real" } }
|
||||
{ BLOB { "blob" "blob" } }
|
||||
{ FACTOR-BLOB { "blob" "blob" } }
|
||||
{ +autoincrement+ { f f "autoincrement" } }
|
||||
{ +unique+ { f f "unique" } }
|
||||
{ +default+ { f f "default" } }
|
||||
{ +null+ { f f "null" } }
|
||||
{ +not-null+ { f f "not null" } }
|
||||
{ system-random-generator { f f f } }
|
||||
{ secure-random-generator { f f f } }
|
||||
{ random-generator { f f f } }
|
||||
} ;
|
||||
|
||||
M: sqlite-db type-table ( -- assoc )
|
||||
H{
|
||||
{ +native-id+ "integer primary key" }
|
||||
{ +random-id+ "integer primary key" }
|
||||
{ INTEGER "integer" }
|
||||
{ BIG-INTEGER "bigint" }
|
||||
{ SIGNED-BIG-INTEGER "bigint" }
|
||||
{ UNSIGNED-BIG-INTEGER "bigint" }
|
||||
{ TEXT "text" }
|
||||
{ VARCHAR "text" }
|
||||
{ DATE "date" }
|
||||
{ TIME "time" }
|
||||
{ DATETIME "datetime" }
|
||||
{ TIMESTAMP "timestamp" }
|
||||
{ DOUBLE "real" }
|
||||
{ BLOB "blob" }
|
||||
{ FACTOR-BLOB "blob" }
|
||||
} ;
|
||||
|
||||
M: sqlite-db create-type-table ( symbol -- str ) type-table ;
|
||||
|
||||
M: sqlite-db compound ( str seq -- str' )
|
||||
over {
|
||||
{ "default" [ first number>string join-space ] }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: io.files kernel tools.test db db.tuples classes
|
||||
db.types continuations namespaces math math.ranges
|
||||
prettyprint tools.walker db.sqlite calendar sequences
|
||||
prettyprint tools.walker calendar sequences db.sqlite
|
||||
math.intervals db.postgresql accessors random math.bitfields.lib ;
|
||||
IN: db.tuples.tests
|
||||
|
||||
|
@ -106,13 +106,6 @@ SYMBOL: person4
|
|||
|
||||
[ ] [ person drop-table ] unit-test ;
|
||||
|
||||
: make-native-person-table ( -- )
|
||||
[ person drop-table ] [ drop ] recover
|
||||
person create-table
|
||||
T{ person f f "billy" 200 3.14 } insert-tuple
|
||||
T{ person f f "johnny" 10 3.14 } insert-tuple
|
||||
;
|
||||
|
||||
: native-person-schema ( -- )
|
||||
person "PERSON"
|
||||
{
|
||||
|
@ -192,7 +185,6 @@ TUPLE: annotation n paste-id summary author mode contents ;
|
|||
|
||||
: test-repeated-insert
|
||||
[ ] [ person ensure-table ] unit-test
|
||||
|
||||
[ ] [ person1 get insert-tuple ] unit-test
|
||||
[ person1 get insert-tuple ] must-fail ;
|
||||
|
||||
|
@ -302,11 +294,12 @@ TUPLE: bignum-test id m n o ;
|
|||
} define-persistent
|
||||
[ bignum-test drop-table ] ignore-errors
|
||||
[ ] [ bignum-test ensure-table ] unit-test
|
||||
[ ] [ 63 2^ dup dup <bignum-test> insert-tuple ] unit-test
|
||||
[ ] [ 63 2^ 1- dup dup <bignum-test> insert-tuple ] unit-test ;
|
||||
|
||||
[ T{ bignum-test f 1
|
||||
-9223372036854775808 9223372036854775808 -9223372036854775808 } ]
|
||||
[ T{ bignum-test f 1 } select-tuple ] unit-test ;
|
||||
! sqlite only
|
||||
! [ T{ bignum-test f 1
|
||||
! -9223372036854775808 9223372036854775808 -9223372036854775808 } ]
|
||||
! [ T{ bignum-test f 1 } select-tuple ] unit-test ;
|
||||
|
||||
TUPLE: secret n message ;
|
||||
C: <secret> secret
|
||||
|
@ -346,17 +339,17 @@ C: <secret> secret
|
|||
[ native-person-schema test-tuples ] test-postgresql
|
||||
[ assigned-person-schema test-tuples ] test-postgresql
|
||||
[ assigned-person-schema test-repeated-insert ] test-postgresql
|
||||
[ test-bignum ] test-sqlite
|
||||
[ test-bignum ] test-postgresql
|
||||
[ test-serialize ] test-postgresql
|
||||
! [ test-intervals ] test-postgresql
|
||||
! [ test-random-id ] test-postgresql
|
||||
|
||||
TUPLE: does-not-persist ;
|
||||
|
||||
[
|
||||
[ does-not-persist create-sql-statement ]
|
||||
[ class \ not-persistent = ] must-fail-with
|
||||
] test-sqlite
|
||||
! [
|
||||
! [ does-not-persist create-sql-statement ]
|
||||
! [ class \ not-persistent = ] must-fail-with
|
||||
! ] test-sqlite
|
||||
|
||||
[
|
||||
[ does-not-persist create-sql-statement ]
|
||||
|
|
Loading…
Reference in New Issue