]> gitweb.factorcode.org Git - factor.git/commitdiff
db configurations factored out through db.info
authorSam Anklesaria <sam@Tintin.local>
Tue, 28 Jul 2009 20:34:49 +0000 (15:34 -0500)
committerSam Anklesaria <sam@Tintin.local>
Tue, 28 Jul 2009 20:34:49 +0000 (15:34 -0500)
extra/db/info/info.factor [new file with mode: 0644]
extra/persistency/persistency.factor
extra/recipes/recipes.factor
extra/ui/frp/gadgets/gadgets.factor

diff --git a/extra/db/info/info.factor b/extra/db/info/info.factor
new file mode 100644 (file)
index 0000000..66409f2
--- /dev/null
@@ -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 ;
\ No newline at end of file
index 8100bce353d3d7940dcab3aa2e88b7eeae097cb6..1604c66b402420235a336de86b76b7acd998b0c0 100644 (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 ;
\ No newline at end of file
index 4ad9397504ecc9dc3c71315d0b154a56d50f5f8e..528663d370e2813e1ff5d7ed7fbe6935b03c5f44 100644 (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) ;
index f39ca3accde6e1a6b8f82921130b37cda1181cc0..59dfd987a8a59042639680c68e8988725c0420e0 100644 (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
\ No newline at end of file
+M: gadget >>= output-model [ swap call( x -- y ) ] curry ; 
\ No newline at end of file