Livecode Wiki
Advertisement

Livecode works well with CouchDB without any plugin. Remember that you can verify all on the admin panel at http://127.0.0.1:5984/_utils/

Let's see some examples:

Test connection

Try:

put URL "http://127.0.0.1:5984/"

You get:

{"couchdb":"Welcome","uuid":"c049bbaa8f32635820f367ec7e77e4b6","version":"1.5.0","vendor":{"version":"14.04","name":"Ubuntu"}}

Show all databases

Try:

put URL "http://127.0.0.1:5984/_all_dbs" 

You get:

["_replicator","_users"]

Database creation

Try:

PUT empty into URL http://127.0.0.1:5984/mynewdatabase"

Document creation

Try:

put "Mary" into temp[FirstName]
put "Gold" into temp[Surname]
put "noise" into temp[Likes][1]
put "animals" into temp[Likes][2]
put "chocolate" into temp[Likes][3]
put jsonExport(temp) into temp
PUT temp into url "http://127.0.0.1:5984/mynewdatabase/mynewdocument1"

Listing all documents

Try _all_docs parameter:

PUT  url "http://127.0.0.1:5984/mynewdatabase/_all_docs" 

You get:

{"total_rows":1,"offset":0,"rows":[
{"id":"mynewdocument1","key":"mynewdocument1","value":{"rev":"1-b044c45141a2acf86c2e812081b2ed56"}}
]}

Get a document

Try:

PUT  url "http://127.0.0.1:5984/mynewdatabase/mynewdocument1"

You get:

{"_id":"mynewdocument1","_rev":"1-b044c45141a2acf86c2e812081b2ed56","FirstName":"Mary","Surname":"Gold","Likes":{"3":"chocolate","1":"noise","2":"animals"}}

Delete a document

Try:

delete URL "http://127.0.0.1:5984/mynewdatabase/mynewdocument1"

User and password

If you need to authenticate with user and password just put them in your request:

put URL "http://user:password@127.0.0.1:5984/mydatabase"
Advertisement