Skip to content

Commit 78aeaa9

Browse files
Merge branch 'upstream-main'
# Conflicts: # src/DataStax.AstraDB.DataApi/Collections/Collection.cs # src/DataStax.AstraDB.DataApi/Core/Query/ProjectionBuilder.cs # src/DataStax.AstraDB.DataApi/DataAPIClient.cs
2 parents 6596132 + eccde5d commit 78aeaa9

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright DataStax, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
namespace DataStax.AstraDB.DataApi.Core;
18+
19+
public class CountDocumentsCommandOptions : CommandOptions
20+
{
21+
public int MaxDocumentsToCount { get; set; } = int.MaxValue;
22+
}

src/DataStax.AstraDB.DataApi/Core/Query/ProjectionBuilder.cs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,80 @@ public ExclusiveProjectionBuilder<T> IncludeSpecial<TField>(Expression<Func<T, T
388388
return this;
389389
}
390390

391+
/// <summary>
392+
/// Specify a field to include in the projection.
393+
/// </summary>
394+
/// <param name="fieldName">The name of the field to include.</param>
395+
/// <returns>The projection builder.</returns>
396+
public ExclusiveProjectionBuilder<T> Slice(string fieldName, int start, int length = 0)
397+
{
398+
var projection = new Projection() { FieldName = fieldName, Include = true, SliceStart = start };
399+
if (length > 0)
400+
{
401+
projection.SliceLength = length;
402+
}
403+
_projections.Add(projection);
404+
return this;
405+
}
406+
407+
/// <summary>
408+
/// Specify a field to include in the projection.
409+
/// </summary>
410+
/// <typeparam name="TField">The type of the field to include.</typeparam>
411+
/// <param name="fieldExpression">The field to include in the projection.</param>
412+
/// <returns>The projection builder.</returns>
413+
public ExclusiveProjectionBuilder<T> Slice<TField>(Expression<Func<T, TField>> fieldExpression, int start, int length = 0)
414+
{
415+
var fieldName = fieldExpression.GetMemberNameTree();
416+
var projection = new Projection() { FieldName = fieldName, Include = true, SliceStart = start };
417+
if (length > 0)
418+
{
419+
projection.SliceLength = length;
420+
}
421+
_projections.Add(projection);
422+
return this;
423+
}
424+
425+
/// <summary>
426+
/// Specify a special field to include in the projection.
427+
/// </summary>
428+
/// <param name="fieldName">The name of the field to include.</param>
429+
/// <returns>The projection builder.</returns>
430+
public ExclusiveProjectionBuilder<T> IncludeSpecial(string fieldName)
431+
{
432+
_projections.Add(new Projection() { FieldName = fieldName, Include = true });
433+
return this;
434+
}
435+
436+
/// <summary>
437+
/// Specify a special field to include in the projection.
438+
/// </summary>
439+
/// <param name="fieldName">The name of the field to include.</param>
440+
/// <returns>The projection builder.</returns>
441+
public ExclusiveProjectionBuilder<T> IncludeSpecial<TField>(Expression<Func<T, TField>> fieldExpression)
442+
{
443+
var isSpecial = false;
444+
if (ExpressionValidator.DoesPropertyHaveAttribute<T, TField, DocumentMappingAttribute>(fieldExpression))
445+
{
446+
isSpecial = true;
447+
}
448+
if (ExpressionValidator.DoesPropertyHaveAttribute<T, TField, DocumentIdAttribute>(fieldExpression))
449+
{
450+
isSpecial = true;
451+
}
452+
var fieldName = fieldExpression.GetMemberNameTree();
453+
if (fieldName == "_id")
454+
{
455+
isSpecial = true;
456+
}
457+
if (!isSpecial)
458+
{
459+
throw new ArgumentException($"Property '{fieldName}' must either have the '{typeof(DocumentMappingAttribute).Name}' attribute or be the '{typeof(DocumentIdAttribute).Name}' attribute.", nameof(fieldExpression));
460+
}
461+
_projections.Add(new Projection() { FieldName = fieldName, Include = true });
462+
return this;
463+
}
464+
391465
public override IProjectionBuilder Clone()
392466
{
393467
var clone = new ExclusiveProjectionBuilder<T>();

0 commit comments

Comments
 (0)