Main | Tutorials | ViewCFCOverviewView.cfc implements the CouchDB View API. It extends Document.cfc and overwrites the Load() function. What is a View?A Couch DB View is a static result set that has been dynamically built by a custom "map" function. A map function parses all of the documents in your database and "emits" a single key/value result for each document that should be added to the View it is building. Once a view has been built, it remains static until a document is added, updated, or removed. Since the database is not queried for every View request, the database response speed is very fast. MethodsView.cfc has all of the same properties and methods as Document.cfc, except for the following: Load()View.cfc requires an ID and View name. The ID provided should not include "_design/", since that is implied when working with views. The View name should not include "_view/", since that is also implied when working with views. Example: view_obj = createObject('component','view').init('my_database');
view_results = view_obj.load('posts','byAuthor');
The above code returns view results located at: /my_database/_design/posts/_view/byAuthor You may also pass the following optional parameters available in the CouchDB View API:
Temporary()Returns a temporary view result. Requires a JSON-encoded map function. Cleanup()Removes all unused view results from the database. Compact()Compacts individual design view results. |