persistency allows sql types for slots
parent
8051218ee0
commit
63f3c5dedd
|
@ -4,7 +4,7 @@ USING: accessors kernel math namespaces make sequences random
|
||||||
strings math.parser math.intervals combinators math.bitwise
|
strings math.parser math.intervals combinators math.bitwise
|
||||||
nmake db db.tuples db.types classes words shuffle arrays
|
nmake db db.tuples db.types classes words shuffle arrays
|
||||||
destructors continuations db.tuples.private prettyprint
|
destructors continuations db.tuples.private prettyprint
|
||||||
db.private byte-arrays ;
|
db.private byte-arrays strings.parser parser ;
|
||||||
IN: db.queries
|
IN: db.queries
|
||||||
|
|
||||||
GENERIC: where ( specs obj -- )
|
GENERIC: where ( specs obj -- )
|
||||||
|
@ -130,6 +130,10 @@ M: integer where ( spec obj -- ) object-where ;
|
||||||
|
|
||||||
M: string where ( spec obj -- ) object-where ;
|
M: string where ( spec obj -- ) object-where ;
|
||||||
|
|
||||||
|
TUPLE: pattern value ; C: <pattern> pattern
|
||||||
|
SYNTAX: %" parse-string <pattern> parsed ;
|
||||||
|
M: pattern where value>> over column-name>> 0% " LIKE " 0% bind# ;
|
||||||
|
|
||||||
: filter-slots ( tuple specs -- specs' )
|
: filter-slots ( tuple specs -- specs' )
|
||||||
[
|
[
|
||||||
slot-name>> swap get-slot-named
|
slot-name>> swap get-slot-named
|
||||||
|
|
|
@ -6,10 +6,13 @@ IN: persistency
|
||||||
|
|
||||||
TUPLE: persistent id ;
|
TUPLE: persistent id ;
|
||||||
|
|
||||||
: add-types ( table -- table' ) [ dup array? [ first ] when dup >upper FACTOR-BLOB 3array ] map
|
: add-types ( table -- table' ) [ dup array? [ [ first dup >upper ] [ second ] bi 3array ]
|
||||||
{ "id" "ID" +db-assigned-id+ } prefix ;
|
[ dup >upper FACTOR-BLOB 3array ] if
|
||||||
|
] map { "id" "ID" +db-assigned-id+ } prefix ;
|
||||||
|
|
||||||
SYNTAX: STORED-TUPLE: parse-tuple-definition [ drop persistent ] dip [ define-tuple-class ]
|
: remove-types ( table -- table' ) [ dup array? [ first ] when ] map ;
|
||||||
|
|
||||||
|
SYNTAX: STORED-TUPLE: parse-tuple-definition [ drop persistent ] dip [ remove-types define-tuple-class ]
|
||||||
[ nip [ dup unparse >upper ] [ add-types ] bi* define-persistent ] 3bi ;
|
[ nip [ dup unparse >upper ] [ add-types ] bi* define-persistent ] 3bi ;
|
||||||
|
|
||||||
: define-db ( database class -- ) swap [ [ ensure-table ] with-db ] [ "database" set-word-prop ] 2bi ;
|
: define-db ( database class -- ) swap [ [ ensure-table ] with-db ] [ "database" set-word-prop ] 2bi ;
|
||||||
|
|
|
@ -1,18 +1,23 @@
|
||||||
USING: accessors arrays db.tuples db.sqlite persistency
|
USING: accessors arrays db.tuples db.sqlite persistency db.queries
|
||||||
io.files.temp kernel monads sequences ui ui.frp.gadgets
|
io.files.temp kernel monads sequences ui ui.frp.gadgets
|
||||||
ui.frp.layout ui.frp.signals ui.gadgets.scrollers ui.gadgets.labels
|
ui.frp.layout ui.frp.signals ui.gadgets.scrollers ui.gadgets.labels
|
||||||
colors.constants ui.pens.solid combinators math locals strings
|
colors.constants ui.pens.solid combinators math locals strings fries
|
||||||
ui.tools.inspector ;
|
ui.images db.types ;
|
||||||
FROM: sets => prune ;
|
FROM: sets => prune ;
|
||||||
IN: recipes
|
IN: recipes
|
||||||
STORED-TUPLE: recipe title votes txt genre ;
|
STORED-TUPLE: recipe { title { VARCHAR 100 } } { votes INTEGER } { txt TEXT } { genre { VARCHAR 100 } } ;
|
||||||
: <recipe> ( title genre text -- recipe ) recipe new swap >>txt swap >>genre swap >>title ;
|
: <recipe> ( title genre text -- recipe ) recipe new swap >>txt swap >>genre swap >>title 0 >>votes ;
|
||||||
"recipes.db" temp-file <sqlite-db> recipe define-db
|
"recipes.db" temp-file <sqlite-db> recipe define-db
|
||||||
: top-recipes ( -- recipes ) <query> T{ recipe } >>tuple "votes" >>order get-tuples ;
|
: top-recipes ( offset search -- recipes ) <query> T{ recipe } rot >>title >>tuple
|
||||||
: top-genres ( -- genres ) top-recipes [ genre>> ] map prune 5 (head-slice) ;
|
"votes" >>order 30 >>limit swap >>offset get-tuples ;
|
||||||
|
: top-genres ( -- genres ) f f top-recipes [ genre>> ] map prune 4 (head-slice) ;
|
||||||
|
: <image-button> ( str -- button ) i" vocab:recipes/icons/_.tiff" <image-name> <frp-button> ;
|
||||||
|
|
||||||
: interface ( -- book ) [
|
: interface ( -- book ) [
|
||||||
[
|
[
|
||||||
[ $ TOOLBAR $ <spacer> $ GENRES $ ] <hbox> { 5 0 } >>gap COLOR: gray <solid> >>interior ,
|
[ $ TOOLBAR $ <spacer> $ SEARCH $ ] <hbox> COLOR: AliceBlue <solid> >>interior ,
|
||||||
|
[ "Genres:" <label> , <spacer> $ GENRES $ ] <hbox>
|
||||||
|
{ 5 0 } >>gap COLOR: gray <solid> >>interior ,
|
||||||
$ RECIPES $
|
$ RECIPES $
|
||||||
] <vbox> ,
|
] <vbox> ,
|
||||||
[
|
[
|
||||||
|
@ -21,19 +26,27 @@ STORED-TUPLE: recipe title votes txt genre ;
|
||||||
$ BUTTON $
|
$ BUTTON $
|
||||||
] <vbox> ,
|
] <vbox> ,
|
||||||
] <frp-book*> { 350 245 } >>pref-dim ;
|
] <frp-book*> { 350 245 } >>pref-dim ;
|
||||||
|
|
||||||
:: recipe-browser ( -- ) [
|
:: recipe-browser ( -- ) [
|
||||||
interface
|
interface
|
||||||
<frp-table*> :> tbl
|
<frp-table*> :> tbl
|
||||||
"okay" <frp-border-button> BUTTON -> :> ok
|
"okay" <frp-border-button> BUTTON -> :> ok
|
||||||
"Submit Recipe" <frp-button> [ store-tuple ] >>value TOOLBAR -> :> submit
|
"submit" <image-button> [ store-tuple ] >>value TOOLBAR -> :> submit
|
||||||
|
"love" <image-button> TOOLBAR -> [ 1 ] <$
|
||||||
|
"hate" <image-button> -> [ -1 ] <$ 2array <merge> :> votes
|
||||||
|
"back" <image-button> -> [ -30 ] <$
|
||||||
|
"more" <image-button> -> [ 30 ] <$ 2array <merge> :> viewed
|
||||||
|
<frp-field*> SEARCH ->% 1 :> search
|
||||||
submit ok [ [ drop ] ] <$ 2array <merge> [ drop ] >>value :> quot
|
submit ok [ [ drop ] ] <$ 2array <merge> [ drop ] >>value :> quot
|
||||||
ok t <basic> "all" <frp-button> GENRES -> 3array <merge> [ top-recipes ] <$ :> updates
|
viewed 0 [ + ] <fold> search ok t <basic> "all" <frp-button> GENRES -> 3array <merge>
|
||||||
|
[ drop [ f ] [ "%" dup surround <pattern> ] if-empty top-recipes ] 3fmap-| :> updates
|
||||||
updates [ top-genres UI[ <frp-button> GENRES ->? ] map <merge> ] bind*
|
updates [ top-genres UI[ <frp-button> GENRES ->? ] map <merge> ] bind*
|
||||||
[ text>> T{ recipe } swap >>genre get-tuples ] fmap
|
[ text>> T{ recipe } swap >>genre get-tuples ] fmap
|
||||||
tbl swap updates 2array <merge> >>model
|
tbl swap updates 2array <merge> >>model
|
||||||
[ [ title>> ] [ genre>> ] bi 2array ] >>quot
|
[ [ title>> ] [ genre>> ] bi 2array ] >>quot
|
||||||
{ "Title" "Genre" } >>column-titles dup <scroller> RECIPES ,% 1
|
{ "Title" "Genre" } >>column-titles dup <scroller> RECIPES ,% 1 actions>> :> val
|
||||||
actions>> submit [ "" dup dup <recipe> ] <$ 2array <merge>
|
val votes [ [ + ] curry change-votes store-tuple ] 2$>-| ,
|
||||||
|
val submit [ "" dup dup <recipe> ] <$ 2array <merge>
|
||||||
{ [ [ title>> ] fmap <frp-field> TITLE ->% .5 ]
|
{ [ [ title>> ] fmap <frp-field> TITLE ->% .5 ]
|
||||||
[ [ genre>> ] fmap <frp-field> GENRE ->% .5 ]
|
[ [ genre>> ] fmap <frp-field> GENRE ->% .5 ]
|
||||||
[ [ txt>> ] fmap <frp-editor> BODY ->% 1 ]
|
[ [ txt>> ] fmap <frp-editor> BODY ->% 1 ]
|
||||||
|
@ -45,5 +58,3 @@ STORED-TUPLE: recipe title votes txt genre ;
|
||||||
] with-interface "recipes" open-window ;
|
] with-interface "recipes" open-window ;
|
||||||
|
|
||||||
MAIN: recipe-browser
|
MAIN: recipe-browser
|
||||||
|
|
||||||
! should clear out old values on submission
|
|
Loading…
Reference in New Issue