Skip to content

Latest commit

 

History

History
49 lines (38 loc) · 1.47 KB

README.md

File metadata and controls

49 lines (38 loc) · 1.47 KB

Hammock

Relax even further and have Hammock manage your CouchDB design documents while you manage JavaScript files in source control.

Usage

Create the following directory structure:

root
`-- design_doc_name
    |-- views
    |   |-- view_name
    |   |   |-- map.js
    |   |   `-- reduce.js
    |   `-- another_view
    |       `-- map.js
    `-- [shows|lists|filters|updates|validate]
        |-- function_name1.js
        `-- function_name2.js

And call Sync:

	if db, err := hammock.Database(db_host, db_name, db_username, db_password); err == nil {

		if changes, err := hammock.Sync(db, "root"); err == nil {

			if len(changes) > 0 {

				fmt.Println(strings.Join(changes, "\n"))
			}
		} else {

			log.Fatalln(err)
		}
	} else {

		log.Fatalln(err)
	}

Sync reads the directory structure and compares it with the design document in the CouchDB database (if such a design document does not exist it is created). Any differences are corrected treating the data read from disk as the correct version. Sync does not merge differences, it will always treat the state read from disk as the correct one.

The only difference Sync does not try to correct (yet) is deleting design documents that exist in the database but not on the disk.

TODO

  • Add tests.
  • Support CoffeeScript files.
  • Add an option for freezing documents, so that Sync will not attempt to override the CouchDB content.
  • Consider deleting documents from CouchDB when they do not exist on disk.