Skip to content

Instantly share code, notes, and snippets.

@danse
Last active August 29, 2015 14:09
Show Gist options
  • Save danse/269462575fa78c64c3cd to your computer and use it in GitHub Desktop.
Save danse/269462575fa78c64c3cd to your computer and use it in GitHub Desktop.
Naming convention for Couch views

Deprecated

This is now maintained here https://github.com/eHealthAfrica/tools-reference/blob/master/view-naming-convention.md


Naming convention for views, starting from the basic case of no reduce functions. Views are couples of arbitrary functions, and as such it is impossible to express their whole variety with a name, so i am just trying to cover the most common cases.

No reduce

In the case of no reduce function, usually views are just meant to sort documents by a set of properties. An idea in this case is to name them like this:

[<slug>_][if_<property>_is_<value>_]by_(<property>_)+

When a property is nested, just replace the dot . with an underscore _. Convert cases to lowercase. Convert underscore separated to no separation.

The slug can contain additional information like the function of the view or the country where it is used (for apps used in several countries).

Examples

by_name // the key is doc.name
by_patient_name // the key is doc.patient.name
by_patient_name_patient_referenceno // the key is doc.patient.referenceNo
by_patient_name_patient_referenceno // the key is doc.patient.reference_no
sl_to_print_by_contact_provincecode // the key is doc.contact.province_code
if_case_status_is_open_by_location // case.status === 'open', the key is location
supervisors_by_location // summarising the view logic with the slug "supervisors"

With a reduce function

In this case, i would use the same convention, with a prefix expressing the reduce. The reduce part could be structured as follows:

<slug>_[on_<property>_]<map part>

Examples

stats_on_patient_age_by_case_status

The case above refers to builtin reduce functions, which should cover the wide majority of uses

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment