 
 M: string where ( spec obj -- ) object-where ;
 
+: filter-slots ( tuple specs -- specs' )
+    [
+        slot-name>> swap get-slot-named
+        dup double-infinite-interval? [ drop f ] when
+    ] with filter ;
+
 : where-clause ( tuple specs -- )
-    " where " 0% [
-        " and " 0%
+    dupd filter-slots
+    dup empty? [
+        2drop
     ] [
-        2dup slot-name>> swap get-slot-named where
-    ] interleave drop ;
+        " where " 0% [
+            " and " 0%
+        ] [
+            2dup slot-name>> swap get-slot-named where
+        ] interleave drop
+    ] if ;
 
 M: db <delete-tuple-statement> ( tuple table -- sql )
     [
         "delete from " 0% 0%
-        dupd
-        [ slot-name>> swap get-slot-named ] with filter
-        dup empty? [ 2drop ] [ where-clause ] if ";" 0%
+        where-clause
     ] query-make ;
 
 M: db <select-by-slots-statement> ( tuple class -- statement )

        [ dup column-name>> 0% 2, ] interleave

        " from " 0% 0%
        dupd
        [ slot-name>> swap get-slot-named ] with filter
        dup empty? [ 2drop ] [ where-clause ] if ";" 0%
    ] query-make ;

math.bitfields.lib namespaces.lib db db.tuples db.types
math.intervals ;
IN: db.queries

GENERIC: where ( specs obj -- )

