Skip to content

Commit

Permalink
Clean up some ambiguously named classes and let GroupBy directly take…
Browse files Browse the repository at this point in the history
… expressions
  • Loading branch information
borrrden committed Jul 7, 2017
1 parent e31dab0 commit 9d5a5cb
Show file tree
Hide file tree
Showing 15 changed files with 201 additions and 279 deletions.
16 changes: 3 additions & 13 deletions src/Couchbase.Lite.Tests.Shared/QueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,15 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

using Couchbase.Lite;
using Couchbase.Lite.Query;
using FluentAssertions;
using LiteCore.Interop;
using Newtonsoft.Json;
using Couchbase.Lite.Internal.Query;
using DataSource = Couchbase.Lite.Query.DataSource;
using Function = Couchbase.Lite.Query.Function;
using GroupBy = Couchbase.Lite.Query.GroupBy;
using Ordering = Couchbase.Lite.Query.Ordering;
#if !WINDOWS_UWP
using Xunit;
using Xunit.Abstractions;
Expand Down Expand Up @@ -574,7 +564,7 @@ public void TestJoin()
var number2Prop = Expression.Property("number2");
using (var q = Query.Select(SelectResult.Expression(number2Prop.From("main")))
.From(DataSource.Database(Db).As("main"))
.Join(Joins.Join(DataSource.Database(Db).As("secondary"))
.Joins(Join.DefaultJoin(DataSource.Database(Db).As("secondary"))
.On(Expression.Property("number1").From("main")
.EqualTo(Expression.Property("theone").From("secondary"))))) {
using (var results = q.Run()) {
Expand Down Expand Up @@ -628,7 +618,7 @@ public void TestGroupBy()
using (var q = Query.Select(SelectResult.Expression(STATE), SelectResult.Expression(COUNT), SelectResult.Expression(MAXZIP))
.From(DataSource.Database(Db))
.Where(gender.EqualTo("female"))
.GroupBy(GroupBy.Expression(STATE))
.GroupBy(STATE)
.OrderBy(Ordering.Expression(STATE))) {
var numRows = VerifyQuery(q, (n, row) =>
{
Expand All @@ -651,7 +641,7 @@ public void TestGroupBy()
using (var q = Query.Select(SelectResult.Expression(STATE), SelectResult.Expression(COUNT), SelectResult.Expression(MAXZIP))
.From(DataSource.Database(Db))
.Where(gender.EqualTo("female"))
.GroupBy(GroupBy.Expression(STATE))
.GroupBy(STATE)
.Having(COUNT.GreaterThan(1))
.OrderBy(Ordering.Expression(STATE))) {
var numRows = VerifyQuery(q, (n, row) =>
Expand Down
44 changes: 0 additions & 44 deletions src/Couchbase.Lite/API/Query/GroupBy.cs

This file was deleted.

18 changes: 9 additions & 9 deletions src/Couchbase.Lite/API/Query/IGroupByRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//

namespace Couchbase.Lite.Query
{

namespace Couchbase.Lite.Query
{
/// <summary>
/// An interface representing a portion of a query which can take GROUP BY
/// as its next step
/// </summary>
public interface IGroupByRouter
{
public interface IGroupByRouter
{
#region Public Methods

/// <summary>
/// Groups the current query by the given GROUP BY clauses
/// </summary>
/// <param name="groupBy">The clauses to group by</param>
/// <param name="expressions">The clauses to group by</param>
/// <returns>The query grouped by the given clauses for further processing</returns>
IGroupBy GroupBy(params IGroupBy[] groupBy);
IGroupBy GroupBy(params IExpression[] expressions);

#endregion
}
}
}
}
2 changes: 1 addition & 1 deletion src/Couchbase.Lite/API/Query/IJoinRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public interface IJoinRouter
/// </summary>
/// <param name="joins">The join clauses to add</param>
/// <returns>The query with the join statement, for further processing</returns>
IJoin Join(params IJoin[] joins);
IJoin Joins(params IJoin[] joins);

#endregion
}
Expand Down
4 changes: 2 additions & 2 deletions src/Couchbase.Lite/API/Query/IOrderByRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public interface IOrderByRouter
/// <summary>
/// Routes this IExpression to the next ORDER BY portion of the query
/// </summary>
/// <param name="ordering">An array of order by operations to consider in the
/// <param name="orderings">An array of order by operations to consider in the
/// ORDER BY portion of the query</param>
/// <returns>The next ORDER BY portion of the query</returns>
IOrdering OrderBy(params IOrdering[] ordering);
IOrdering OrderBy(params IOrdering[] orderings);

#endregion
}
Expand Down
10 changes: 5 additions & 5 deletions src/Couchbase.Lite/API/Query/Joins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Couchbase.Lite.Query
/// <summary>
/// A class for creating <see cref="IJoin"/> instances
/// </summary>
public static class Joins
public static class Join
{
#region Public Methods

Expand All @@ -36,7 +36,7 @@ public static class Joins
/// <returns>An <see cref="IJoinOn"/> instance for processing</returns>
public static IJoinOn CrossJoin(IDataSource dataSource)
{
return new Join("CROSS", dataSource);
return new QueryJoin("CROSS", dataSource);
}

/// <summary>
Expand All @@ -46,15 +46,15 @@ public static IJoinOn CrossJoin(IDataSource dataSource)
/// <returns>An <see cref="IJoinOn"/> instance for processing</returns>
public static IJoinOn InnerJoin(IDataSource dataSource)
{
return new Join(null, dataSource);
return new QueryJoin(null, dataSource);
}

/// <summary>
/// Synonym for <see cref="InnerJoin(IDataSource)"/>
/// </summary>
/// <param name="dataSource">The data source to JOIN with</param>
/// <returns>An <see cref="IJoinOn"/> instance for processing</returns>
public static IJoinOn Join(IDataSource dataSource)
public static IJoinOn DefaultJoin(IDataSource dataSource)
{
return InnerJoin(dataSource);
}
Expand All @@ -76,7 +76,7 @@ public static IJoinOn LeftJoin(IDataSource dataSource)
/// <returns>An <see cref="IJoinOn"/> instance for processing</returns>
public static IJoinOn LeftOuterJoin(IDataSource dataSource)
{
return new Join("LEFT OUTER", dataSource);
return new QueryJoin("LEFT OUTER", dataSource);
}

#endregion
Expand Down
96 changes: 48 additions & 48 deletions src/Couchbase.Lite/Query/DataSource.cs
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
//
// DataSource.cs
//
// Author:
// Jim Borden <[email protected]>
//
// Copyright (c) 2017 Couchbase, Inc All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
using Couchbase.Lite.Query;

namespace Couchbase.Lite.Internal.Query
{
internal abstract class DataSource : IDataSource
{
#region Properties

internal object Source { get; }

#endregion

#region Constructors

protected DataSource(object source)
{
Source = source;
}

#endregion

#region Public Methods

public abstract object ToJSON();

#endregion
}
}
//
// DataSource.cs
//
// Author:
// Jim Borden <[email protected]>
//
// Copyright (c) 2017 Couchbase, Inc All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
using Couchbase.Lite.Query;

namespace Couchbase.Lite.Internal.Query
{
internal abstract class QueryDataSource : IDataSource
{
#region Properties

internal object Source { get; }

#endregion

#region Constructors

protected QueryDataSource(object source)
{
Source = source;
}

#endregion

#region Public Methods

public abstract object ToJSON();

#endregion
}
}
Loading

0 comments on commit 9d5a5cb

Please sign in to comment.