summaryrefslogtreecommitdiffstats
path: root/doc/src/map-views.qdoc
blob: c971edeae2f221b4688a372bd294030f4276cba0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/****************************************************************************
**
** 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}.

*/