db configurations factored out through db.info

db4
Sam Anklesaria 2009-07-28 15:34:49 -05:00
parent 7a5309f075
commit 0c104ca126
4 changed files with 19 additions and 6 deletions

15
extra/db/info/info.factor Normal file
View File

@ -0,0 +1,15 @@
USING: accessors sequences generalizations io.encodings.utf8 db.postgresql parser combinators vocabs.parser db.sqlite
io.files ;
IN: db.info
! having sensative (and likely to change) information directly in source code seems a bad idea
: get-info ( -- lines ) current-vocab name>> "vocab:" "/dbinfo.txt" surround utf8 file-lines ;
SYNTAX: get-psql-info <postgresql-db> get-info 5 firstn
{
[ >>host ]
[ >>port ]
[ >>username ]
[ [ f ] [ ] if-empty >>password ]
[ >>database ]
} spread parsed ;
SYNTAX: get-sqlite-info get-info first <sqlite-db> parsed ;

View File

@ -22,4 +22,4 @@ SYNTAX: STORED-TUPLE: parse-tuple-definition [ drop persistent ] dip [ remove-ty
: get-tuple ( query -- tuple ) [ select-tuple ] w/db ;
: store-tuple ( tuple -- ) [ insert-tuple ] w/db ;
: modify-tuple ( tuple -- ) [ update-tuple ] w/db ;
: remove-tuples ( tuple -- ) [ delete-tuples ] w/db ;
: remove-tuples ( tuple -- ) [ delete-tuples ] w/db ;

View File

@ -1,5 +1,5 @@
USING: accessors arrays colors.constants combinators db.queries
db.sqlite db.tuples db.types io.files.temp kernel locals math
db.info db.tuples db.types kernel locals math
monads persistency sequences sequences.extras ui ui.frp.gadgets
ui.frp.layout ui.frp.signals ui.gadgets.labels
ui.gadgets.scrollers ui.pens.solid ;
@ -8,7 +8,7 @@ IN: recipes
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 0 >>votes ;
"recipes.db" temp-file <sqlite-db> recipe define-db
get-psql-info recipe define-db
: top-recipes ( offset search -- recipes ) <query> T{ recipe } rot >>title >>tuple
"votes" >>order 30 >>limit swap >>offset get-tuples ;
: top-genres ( -- genres ) f f top-recipes [ genre>> ] map prune 4 (head-slice) ;

View File

@ -76,6 +76,4 @@ INSTANCE: gadget-monad monad
INSTANCE: gadget monad
M: gadget monad-of drop gadget-monad ;
M: gadget-monad return drop <gadget> swap >>model ;
M: gadget >>= output-model [ swap call( x -- y ) ] curry ;
! Make sure prop removal really destroys normal db code
M: gadget >>= output-model [ swap call( x -- y ) ] curry ;