db.tuples[{-docs,-tests}]: add reject-tuples

freebsd-work
Alexander Iljin 2018-12-24 23:54:36 +01:00 committed by Doug Coleman
parent bb1e6943e6
commit b8daf396e2
3 changed files with 25 additions and 2 deletions

View File

@ -139,7 +139,18 @@ HELP: delete-tuples
{ $description "Uses the " { $snippet "tuple" } " as an exemplar object and deletes any objects that have the same slots set. If a slot is not " { $link f } ", then it is used to generate an SQL statement that deletes tuples." }
{ $warning "This word will delete your data." } ;
{ insert-tuple update-tuple update-tuples delete-tuples } related-words
HELP: reject-tuples
{ $values
{ "query/tuple" tuple }
{ "quot" { $quotation ( tuple -- ? ) } } }
{ $description "An SQL query is constructed from the slots of the exemplar tuple that are not " { $link f } ". The " { $snippet "quot" } " is applied to each tuple from the database that matches the query, and if it returns a true value, the row is deleted from the database."
$nl
"The word is equivalent to the following code:"
{ $code "query/tuple select-tuples quot filter [ delete-tuples ] each" }
"The difference is that " { $snippet "reject-tuples" } " handles query results one by one, thus avoiding the overhead of allocating the intermediate array of tuples, which " { $link select-tuples } " would do. This is important when processing large amounts of data in limited memory." }
{ $warning "This word will delete your data." } ;
{ insert-tuple update-tuple update-tuples delete-tuples reject-tuples } related-words
HELP: each-tuple
{ $values
@ -200,7 +211,10 @@ ARTICLE: "db-tuples-words" "High-level tuple/database words"
update-tuples
}
"Deleting tuples:"
{ $subsections delete-tuples }
{ $subsections
delete-tuples
reject-tuples
}
"Querying tuples:"
{ $subsections
each-tuple

View File

@ -690,6 +690,12 @@ select-me "select_me"
] update-tuples
select-me new [ data>> ] collector [ each-tuple ] dip
natural-sort
] unit-test
[ { "test2" } ] [
select-me new [ data>> "test1" = ] reject-tuples
select-me new [ data>> ] collector [ each-tuple ] dip
natural-sort
] unit-test ;
[ test-mapping ] test-sqlite

View File

@ -163,3 +163,6 @@ ERROR: no-defined-persistent object ;
: update-tuples ( query/tuple quot: ( tuple -- tuple'/f ) -- )
'[ @ [ update-tuple ] when* ] each-tuple ; inline
: reject-tuples ( query/tuple quot: ( tuple -- ? ) -- )
'[ dup @ [ delete-tuples ] [ drop ] if ] each-tuple ; inline