add update, delete to fql
parent
7ab58fa3b3
commit
447a55418c
|
@ -33,6 +33,26 @@ IN: db2.fql.tests
|
||||||
expand-fql sql>>
|
expand-fql sql>>
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
[ "delete from computer order by omg limit 3" ]
|
||||||
|
[
|
||||||
|
delete new
|
||||||
|
"computer" >>tables
|
||||||
|
"omg" >>order-by
|
||||||
|
3 >>limit
|
||||||
|
expand-fql sql>>
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
[ "update computer set name = oscar order by omg limit 3" ]
|
||||||
|
[
|
||||||
|
update new
|
||||||
|
"computer" >>tables
|
||||||
|
"name" >>keys
|
||||||
|
"oscar" >>values
|
||||||
|
"omg" >>order-by
|
||||||
|
3 >>limit
|
||||||
|
expand-fql sql>>
|
||||||
|
] unit-test
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
[ test-fql ] test-dbs
|
[ test-fql ] test-dbs
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors arrays combinators constructors db2
|
USING: accessors arrays combinators constructors db2
|
||||||
db2.private db2.sqlite.lib db2.statements db2.utils destructors
|
db2.private db2.sqlite.lib db2.statements db2.utils destructors
|
||||||
kernel make math.parser sequences strings ;
|
kernel make math.parser sequences strings assocs ;
|
||||||
IN: db2.fql
|
IN: db2.fql
|
||||||
|
|
||||||
TUPLE: fql-statement sql in out ;
|
TUPLE: fql-statement sql in out ;
|
||||||
|
@ -20,6 +20,20 @@ CONSTRUCTOR: insert ( into names values -- obj ) ;
|
||||||
M: insert normalize-fql ( insert -- insert )
|
M: insert normalize-fql ( insert -- insert )
|
||||||
[ [ ?1array ] ?when ] change-names ;
|
[ [ ?1array ] ?when ] change-names ;
|
||||||
|
|
||||||
|
TUPLE: update tables keys values where order-by limit ;
|
||||||
|
CONSTRUCTOR: update ( tables keys values where -- obj ) ;
|
||||||
|
M: update normalize-fql ( insert -- insert )
|
||||||
|
[ [ ?1array ] ?when ] change-tables
|
||||||
|
[ [ ?1array ] ?when ] change-keys
|
||||||
|
[ [ ?1array ] ?when ] change-values
|
||||||
|
[ [ ?1array ] ?when ] change-order-by ;
|
||||||
|
|
||||||
|
TUPLE: delete tables where order-by limit ;
|
||||||
|
CONSTRUCTOR: delete ( tables keys values where -- obj ) ;
|
||||||
|
M: delete normalize-fql ( insert -- insert )
|
||||||
|
[ [ ?1array ] ?when ] change-tables
|
||||||
|
[ [ ?1array ] ?when ] change-order-by ;
|
||||||
|
|
||||||
TUPLE: select names from where group-by order-by offset limit ;
|
TUPLE: select names from where group-by order-by offset limit ;
|
||||||
CONSTRUCTOR: select ( names from -- obj ) ;
|
CONSTRUCTOR: select ( names from -- obj ) ;
|
||||||
M: select normalize-fql ( select -- select )
|
M: select normalize-fql ( select -- select )
|
||||||
|
@ -43,6 +57,33 @@ M: insert expand-fql*
|
||||||
} cleave
|
} cleave
|
||||||
] "" make >>sql ;
|
] "" make >>sql ;
|
||||||
|
|
||||||
|
M: update expand-fql*
|
||||||
|
[ fql-statement new ] dip
|
||||||
|
[
|
||||||
|
{
|
||||||
|
[ "update " % tables>> ", " join % ]
|
||||||
|
[
|
||||||
|
" set " % [ keys>> ] [ values>> ] bi
|
||||||
|
zip [ ", " % ] [ first2 [ % ] dip " = " % % ] interleave
|
||||||
|
]
|
||||||
|
! [ " " % from>> ", " join % ]
|
||||||
|
[ where>> [ " where " % [ expand-fql % ] when* ] when* ]
|
||||||
|
[ order-by>> [ " order by " % ", " join % ] when* ]
|
||||||
|
[ limit>> [ " limit " % # ] when* ]
|
||||||
|
} cleave
|
||||||
|
] "" make >>sql ;
|
||||||
|
|
||||||
|
M: delete expand-fql*
|
||||||
|
[ fql-statement new ] dip
|
||||||
|
[
|
||||||
|
{
|
||||||
|
[ "delete from " % tables>> ", " join % ]
|
||||||
|
[ where>> [ " where " % [ expand-fql % ] when* ] when* ]
|
||||||
|
[ order-by>> [ " order by " % ", " join % ] when* ]
|
||||||
|
[ limit>> [ " limit " % # ] when* ]
|
||||||
|
} cleave
|
||||||
|
] "" make >>sql ;
|
||||||
|
|
||||||
M: select expand-fql*
|
M: select expand-fql*
|
||||||
[ fql-statement new ] dip
|
[ fql-statement new ] dip
|
||||||
[
|
[
|
||||||
|
@ -57,7 +98,6 @@ M: select expand-fql*
|
||||||
} cleave
|
} cleave
|
||||||
] "" make >>sql ;
|
] "" make >>sql ;
|
||||||
|
|
||||||
|
|
||||||
M: fql-statement sql-command ( sql -- )
|
M: fql-statement sql-command ( sql -- )
|
||||||
sql>> sql-command ;
|
sql>> sql-command ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue