Sorry, correction in Step 1. Second to the last line should read:
light = Lightning(information=dict(attributes=dict(timestamp =
datetime.now(), longitude = 30.4, latitude = 18.9, description='cloud to
ground')))

On Mon, May 8, 2017 at 10:07 AM, Noel Quintos <[email protected]> wrote:

> I had a hard time installing couchapp (my machine is not connected to the
> internet) but finally got that working, and I would say it is worth the
> effort. My problem is solved and here is what I did, just in case somebody
> out there have the same problem at hand.
>
> 1.  I used python couchdb module to save into couchDb like this:
>
> from couchdb.mapping import Mapping, DictField, Document, TextField,
> FloatField, DateTimeField
> class Lightning(Document):
>     information = DictField(Mapping.build(
>          attributes = DictField(Mapping.build(
>                timestamp = DateTimeField();
>                longitude = FloatField(),
>                latitude    = FloatField(),
>                description = TextField()
>          ))
>      ))
> light = Lightning(timestamp = datetime.now(), longitude = 30.4, latitude =
> 18.9, description='cloud to ground')
> light.store(db)
>
> 2. Using couchapp, I did:
>   couchapp init vaisala
> Take note that 'vaisala' is my design document name.
> There might be something wrong with my couchapp installation because it
> did not create the various sub-directories and so, I manually created the
> "lists" directory
>
> 3. I then did:
> couchapp generate list lightlist
> It then created lightlist.js inside the "lists" directory, which I then
> added this code:
>
> function(head, req) {
>    var row = getRow();
>    var mylist = new Array();
>    while(row) {
>        mylist.push(row.value.information);
>        row=getRow();
>    }
> send(JSON.stringify(mylist, null, 2);
> }
>
> Prior to that, I have an existing view called "nv" which is contained on
> another design document called "doc". Notice that in my list function, I am
> simply building a regular javascript array, and the elements are already in
> the right object structure. Recall that my target JSON output is an array
> (hence, I am building an array in my list function) of dictionary of
> dictionaries. "row.value.information" is actually dictionary of
> dictionaries that I see in my "nv" view. At the end of my list function, I
> am simply converting the javascript object to JSON format. The "2" in the
> argument will provide indentation to the JSON output, making it more
> readable, and make it look like more my desired output.
>
> 4.  I uploaded the list function via "couchapp push lightning".
> "lightning" here is the name of my couchDB database. Using Fauxton, I am
> able to see in the "lightning" database, an entry with id of
> "_design/vaisala", and under that, "lists", I can see "lightlist"
> containing the function that I just created.
>
> 5. I then type:
> curl -X GET http://172.16.54.8:5984/lightning/_design/vaisala/_
> list/lightlist/doc/nv
> And that showed that data in the format that I want it.
>
> Thanks to everyone who helped me figure it out especially to Aurélien, who
> had been very patient with me!
>
> On Thu, May 4, 2017 at 11:23 PM, Aurélien Bénel <[email protected]>
> wrote:
>
>> Hi Noel,
>>
>> > "error":"compilation_error","reason":"Expression does not eval to a
>> function.
>>
>>
>> We could analyse the JSON manually, but as your application will get
>> bigger,
>> it will become more and more complex.
>> As I wrote earlier, I recommend you to use a tool like couchapp (
>> http://github.com/couchapp/couchapp).
>>
>> The idea is to convert a folder with subfolders and files into a design
>> document.
>> In your case it would be something like:
>>
>> - doc /         (weird name for a design document…)
>>   - views
>>     - map
>>       - nv.js
>>   - lists
>>     - lightning.js
>>
>> Documentation is there:
>>     https://couchapp.readthedocs.io/en/latest/couchapp/gettingst
>> arted.html
>>
>> Note that, with couchapp, you are not obliged to generate a complete «
>> app », but maybe it’s easier to begin with.
>>
>>
>> Regards,
>>
>> Aurélien
>
>
>
>
> --
> Noel P. Quintos
>



-- 
Noel P. Quintos

Reply via email to