summaryrefslogtreecommitdiff
path: root/dsa/FireBase/Query/QueryFactoryExtensions.cs
blob: 71dae5cb3711445b9a890527e7c0af6c375367d1 (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
using System;

namespace Firebase.Database.Query
{
    /// <summary>
    ///     Query extensions providing linq like syntax for firebase server methods.
    /// </summary>
    public static class QueryFactoryExtensions
    {
        /// <summary>
        ///     Adds an auth parameter to the query.
        /// </summary>
        /// <param name="node"> The child. </param>
        /// <param name="tokenFactory"> The auth token. </param>
        /// <returns> The <see cref="AuthQuery" />. </returns>
        internal static AuthQuery WithAuth(this FirebaseQuery node, Func<string> tokenFactory)
        {
            return new AuthQuery(node, tokenFactory, node.Client);
        }

        /// <summary>
        ///     References a sub child of the existing node.
        /// </summary>
        /// <param name="node"> The child. </param>
        /// <param name="pathFactory"> The path of sub child. </param>
        /// <returns> The <see cref="ChildQuery" />. </returns>
        public static ChildQuery Child(this ChildQuery node, Func<string> pathFactory)
        {
            return new ChildQuery(node, pathFactory, node.Client);
        }

        /// <summary>
        ///     Order data by given <see cref="propertyNameFactory" />. Note that this is used mainly for following filtering
        ///     queries and due to firebase implementation
        ///     the data may actually not be ordered.
        /// </summary>
        /// <param name="child"> The child. </param>
        /// <param name="propertyNameFactory"> The property name. </param>
        /// <returns> The <see cref="OrderQuery" />. </returns>
        public static OrderQuery OrderBy(this ChildQuery child, Func<string> propertyNameFactory)
        {
            return new OrderQuery(child, propertyNameFactory, child.Client);
        }

        /// <summary>
        ///     Order data by $key. Note that this is used mainly for following filtering queries and due to firebase
        ///     implementation
        ///     the data may actually not be ordered.
        /// </summary>
        /// <param name="child"> The child. </param>
        /// <returns> The <see cref="OrderQuery" />. </returns>
        public static OrderQuery OrderByKey(this ChildQuery child)
        {
            return child.OrderBy("$key");
        }

        /// <summary>
        ///     Order data by $value. Note that this is used mainly for following filtering queries and due to firebase
        ///     implementation
        ///     the data may actually not be ordered.
        /// </summary>
        /// <param name="child"> The child. </param>
        /// <returns> The <see cref="OrderQuery" />. </returns>
        public static OrderQuery OrderByValue(this ChildQuery child)
        {
            return child.OrderBy("$value");
        }

        /// <summary>
        ///     Order data by $priority. Note that this is used mainly for following filtering queries and due to firebase
        ///     implementation
        ///     the data may actually not be ordered.
        /// </summary>
        /// <param name="child"> The child. </param>
        /// <returns> The <see cref="OrderQuery" />. </returns>
        public static OrderQuery OrderByPriority(this ChildQuery child)
        {
            return child.OrderBy("$priority");
        }

        /// <summary>
        ///     Instructs firebase to send data greater or equal to the <see cref="valueFactory" />. This must be preceded by an
        ///     OrderBy query.
        /// </summary>
        /// <param name="child"> Current node. </param>
        /// <param name="valueFactory"> Value to start at. </param>
        /// <returns> The <see cref="FilterQuery" />. </returns>
        public static FilterQuery StartAt(this ParameterQuery child, Func<string> valueFactory)
        {
            return new FilterQuery(child, () => "startAt", valueFactory, child.Client);
        }

        /// <summary>
        ///     Instructs firebase to send data lower or equal to the <see cref="valueFactory" />. This must be preceded by an
        ///     OrderBy query.
        /// </summary>
        /// <param name="child"> Current node. </param>
        /// <param name="valueFactory"> Value to start at. </param>
        /// <returns> The <see cref="FilterQuery" />. </returns>
        public static FilterQuery EndAt(this ParameterQuery child, Func<string> valueFactory)
        {
            return new FilterQuery(child, () => "endAt", valueFactory, child.Client);
        }

        /// <summary>
        ///     Instructs firebase to send data equal to the <see cref="valueFactory" />. This must be preceded by an OrderBy
        ///     query.
        /// </summary>
        /// <param name="child"> Current node. </param>
        /// <param name="valueFactory"> Value to start at. </param>
        /// <returns> The <see cref="FilterQuery" />. </returns>
        public static FilterQuery EqualTo(this ParameterQuery child, Func<string> valueFactory)
        {
            return new FilterQuery(child, () => "equalTo", valueFactory, child.Client);
        }

        /// <summary>
        ///     Instructs firebase to send data greater or equal to the <see cref="valueFactory" />. This must be preceded by an
        ///     OrderBy query.
        /// </summary>
        /// <param name="child"> Current node. </param>
        /// <param name="valueFactory"> Value to start at. </param>
        /// <returns> The <see cref="FilterQuery" />. </returns>
        public static FilterQuery StartAt(this ParameterQuery child, Func<double> valueFactory)
        {
            return new FilterQuery(child, () => "startAt", valueFactory, child.Client);
        }

        /// <summary>
        ///     Instructs firebase to send data lower or equal to the <see cref="valueFactory" />. This must be preceded by an
        ///     OrderBy query.
        /// </summary>
        /// <param name="child"> Current node. </param>
        /// <param name="valueFactory"> Value to start at. </param>
        /// <returns> The <see cref="FilterQuery" />. </returns>
        public static FilterQuery EndAt(this ParameterQuery child, Func<double> valueFactory)
        {
            return new FilterQuery(child, () => "endAt", valueFactory, child.Client);
        }

        /// <summary>
        ///     Instructs firebase to send data equal to the <see cref="valueFactory" />. This must be preceded by an OrderBy
        ///     query.
        /// </summary>
        /// <param name="child"> Current node. </param>
        /// <param name="valueFactory"> Value to start at. </param>
        /// <returns> The <see cref="FilterQuery" />. </returns>
        public static FilterQuery EqualTo(this ParameterQuery child, Func<double> valueFactory)
        {
            return new FilterQuery(child, () => "equalTo", valueFactory, child.Client);
        }

        /// <summary>
        ///     Instructs firebase to send data equal to the <see cref="valueFactory" />. This must be preceded by an OrderBy
        ///     query.
        /// </summary>
        /// <param name="child"> Current node. </param>
        /// <param name="valueFactory"> Value to start at. </param>
        /// <returns> The <see cref="FilterQuery" />. </returns>
        public static FilterQuery EqualTo(this ParameterQuery child, Func<bool> valueFactory)
        {
            return new FilterQuery(child, () => "equalTo", valueFactory, child.Client);
        }

        /// <summary>
        ///     Limits the result to first <see cref="countFactory" /> items.
        /// </summary>
        /// <param name="child"> Current node. </param>
        /// <param name="countFactory"> Number of elements. </param>
        /// <returns> The <see cref="FilterQuery" />. </returns>
        public static FilterQuery LimitToFirst(this ParameterQuery child, Func<int> countFactory)
        {
            return new FilterQuery(child, () => "limitToFirst", () => countFactory(), child.Client);
        }

        /// <summary>
        ///     Limits the result to last <see cref="countFactory" /> items.
        /// </summary>
        /// <param name="child"> Current node. </param>
        /// <param name="countFactory"> Number of elements. </param>
        /// <returns> The <see cref="FilterQuery" />. </returns>
        public static FilterQuery LimitToLast(this ParameterQuery child, Func<int> countFactory)
        {
            return new FilterQuery(child, () => "limitToLast", () => countFactory(), child.Client);
        }
    }
}