/**************************************************************************** ** ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the documentation of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:FDL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and Digia. For licensing terms and ** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Free Documentation License Usage ** Alternatively, this file may be used under the terms of the GNU Free ** Documentation License version 1.3 as published by the Free Software ** Foundation and appearing in the file included in the packaging of ** this file. Please review the following information to ensure ** the GNU Free Documentation License version 1.3 requirements ** will be met: http://www.gnu.org/copyleft/fdl.html. ** $QT_END_LICENSE$ ** ****************************************************************************/ /*! \page map-views.html \title Map and Join Views \target join \section1 Performing a Map \target Map A map is defined by creating a \l Map object in the database with a "map" property. A Map operates on one or more source types, producing values of a single target type. The target type must extend \l View. \table \row \li _type \li Map \row \li targetType \li The output type of this mapping \row \li targetKeyName \li Name of the key for the emitted objects. Optional. \sa deterministic-map-uuids \row \li map \li A dictionary whose keys are source type names and whose values are the functions to run on those source type. \endtable \section2 Deterministic Map Uuids \target{deterministic-map-uuids} By default, View objects created by Map are assigned a deterministic Uuid (see \l {Special JSON Properties}). If the "map" or "join" functions assign _uuid to the object they return, then that value is used as the uuid for the object. Otherwise, the view engine constructs an identifier string as follows: \code sourceUuids.sort(); if (targeKeyName.isEmpty()) { var identifier = targetType + ":" + sourceUuids.join(":"); object._uuid = jsondb.createUuidFromString(identifier); } else { var keyValue = object[targetKeyName]; var identifier = targetType + ":" + sourceUuids.join(":") + ":" + keyValue; object._uuid = jsondb.createUuidFromString(identifier); } \endcode \section2 Map Proxy When the map functions run, they have access to a jsondb proxy object with one method: \table \row \li \l {jsondb.emit}{jsondb.emit}(viewObject) \endtable \section3 jsondb.emit Emits a view object. \l jsondb.emit may be called zero or more times in a map function. Each object emitted from the map function is created as a view object, with property _type bound to the target type. See \l {Creating a Map View}. \section1 Performing a Join \target Join A join is defined by creating a \l Map object in the database with a "join" property. \table \row \li _type \li Map \row \li targetType \li The output type of this Join \row \li join \li A dictionary whose keys are source type names and whose values are the functions to run on those source type. \endtable \section2 JSON DB Join Proxy When the \l Join functions run, they have access to a jsondb proxy object with two methods: \table \row \li \l {jsondb.lookup} {jsondb.lookup}({index: indexName, value: v, objectType: objectType}, context) \row \target {jsondb.emit} \li \l {jsondb.emit}{jsondb.emit}(viewObject) \endtable \section3 jsondb.lookup \target {jsondb.lookup} Takes two arguments, a lookup object and a context object. The lookup object consists of: \table \row \li index \li The name of the index to use. \row \li value \li The value to match in the index. \row \li objectType \li The type of the objects to lookup. Must be one of the source types listed in the \l Join definition. \endtable For each object found, the join function for objectType is called with two arguments: the matching object and the context object. See \l {Creating a Join View}. */