CouchDB
Jeff Massung
massung at gmail.com
Fri May 13 11:51:31 EDT 2011
Todd,
CouchDB (or Mongo, Riak, and other NoSQL alternatives) are excellent
databases in the right situation. I haven't used on with LC, but have used
CouchDB plenty. Their main benefits lie in A) no schema and B) replication.
If you have no need of either, then it might be more work to get working
than it's worth.
While most NoSQL solutions use a REST API to insert, select, update, etc.
the real trick is the JSON input and output through the HTTP protocol. So,
what you'd need to do is write a JSON library in LC for encoding and
decoding values. Once that's in place, everything else should be trivial.
## example encoding function... likely needs tweaked (doesn't handle
null/nil)
function encodeJSON pVal
if pVal is true then
return "true"
elseif pVal is false then
return "false"
elseif isNumber(pVal) then
return pVal
elseif isArray(pVal) then
local tObject = "{"
repeat for each line tKey in the keys of pVal
put quote & tKey & quote & ":" & encodeJSON pVal[tKey] & comma after
tObject
end repeat
return tObject & "}"
end if
return quote & pVal & quote
end encodeJSON
I don't have time to try and whip together an example decode, but it would
basically involve parsing JSON and creating either an array (from a JSON
object) or just returning the value (since everything in LC is a string).
After that it's just posting, getting, etc.
Jeff M.
More information about the use-livecode
mailing list