Diff: [root] @ 962c4d2f220 | faq | css

tccli

File created: 33188 code/tccli [Diff]

diff --git a/code/tccli b/code/tccli
new file mode 100644
index 0000000..8693cd2
-- /dev/null
++ b/code/tccli
@@ -0,0 +1,44 @@
"tccli"http://hackage.haskell.org/package/tccli

bc.. import qualified Data.ByteString.Lazy as BSL
import qualified Data.ByteString.Lazy.UTF8 as BUL
import Database.TokyoCabinet.HDB
import System.Environment (getArgs)

printUsage = do
putStrLn "Simple TokyoCabinet hash storage interface."
putStrLn "Usage: tchcli <db file> <action> <args>"
putStrLn "Examples: tchcli mydb.tch get mykey # gets value of mykey and prints it to STDOUT"
putStrLn " tchcli mydb.tch put mykey # stores data from STDIN as mykey in database"
putStrLn " tchcli mydb.tch putcat mykey # appends data from STDIN to mykey in database"

performTricks dbname action arg = do
case action of
"get" -> do
db <- new
open db dbname [OCREAT, OREADER]
result <- get db (BUL.fromString arg)
maybe (putStr "") (BSL.putStr) result
"put" -> do
db <- new
open db dbname [OCREAT, OWRITER]
put db (BUL.fromString arg) =<< BSL.getContents
return ()
"putcat" -> do
db <- new
open db dbname [OCREAT, OWRITER]
putcat db (BUL.fromString arg) =<< BSL.getContents
return ()
"num" -> do
db <- new
open db dbname [OCREAT, OREADER]
print =<< rnum db
otherwise -> printUsage

main = do
args <- getArgs
if (length args < 3) then
printUsage
else do
let [dbname, action, arg] = args
performTricks dbname action arg
\ No newline at end of file

By Voker57 on 2010-06-06 14:49:11 +0400 Powered by bitcheese wiki engine