Skip to content

Commit

Permalink
Some refactoring work on the model API, and initial (non functioning)…
Browse files Browse the repository at this point in the history
… replication API implementation
  • Loading branch information
borrrden committed Mar 30, 2017
1 parent b107912 commit 479ff1b
Show file tree
Hide file tree
Showing 19 changed files with 204 additions and 569 deletions.
37 changes: 22 additions & 15 deletions src/Couchbase.Lite.Tests.Shared/ModelTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using System.Linq;

using Couchbase.Lite;
using Couchbase.Lite.Query;
using FluentAssertions;
using Newtonsoft.Json;
using Xunit;
Expand All @@ -40,7 +41,7 @@ public class TestModel : IDocumentModel

public TestModelReference Child { get; set; } = new TestModelReference();

public IDocumentMetadata Metadata
public IDocument Document
{
get; set;
}
Expand All @@ -66,22 +67,28 @@ public ModelTest(ITestOutputHelper output) : base(output)
//[Fact]
//public void TestModel()
//{
// var model = Db.GetDocument<TestModel>();
// var item = model.Item;
// item.IntValue = 42;
// item.StringValue = "Jim";
// item.Child.IntValues = new[] { 1, 2, 3, 4 };
// model.Save().Should().BeTrue("because otherwise the save failed");
// Db.DoSync(() =>
// {
// var model = Db.CreateDocument().AsModel<TestModel>();
// model.IntValue = 42;
// model.StringValue = "Jim";
// model.Child.IntValues = new[] {1, 2, 3, 4};
// model.Save();

// var model2 = Db.GetDocument<TestModel>();
// item = model2.Item;
// item.IntValue = 43;
// item.StringValue = "Jim";
// item.Child.IntValues = new[] { 1, 2, 3, 4, 5 };
// model2.Save();
// var model2 = Db.CreateDocument().AsModel<TestModel>();
// model2.IntValue = 43;
// model2.StringValue = "Jim";
// model2.Child.IntValues = new[] {1, 2, 3, 4, 5};
// model2.Save();

// var all = from x in QueryableFactory.MakeQueryable<TestModel>(Db) where x.Child.IntValues.Sum() > 10 select x;
// all.ToArray();
// var all = from x in DataSourceFactory.LinqDataSource<TestModel>(Db, true)
// where x.Child.IntValues.Sum() > 10
// select x;

// var test = all.ToArray();
// test.Count().Should().Be(1);
// test[0].IntValue.Should().Be(43);
// });
//}
}
}
2 changes: 1 addition & 1 deletion src/Couchbase.Lite.Tests.Shared/QueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class NamesModel : IDocumentModel
[JsonProperty(PropertyName = "memberSince")]
public string MemberSince { get; set; }

public IDocumentMetadata Metadata { get; set; }
public IDocument Document { get; set; }

public NamesModel()
{
Expand Down
2 changes: 0 additions & 2 deletions src/Couchbase.Lite/API/IDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ public interface IDatabase : IThreadSafe, IDisposable
[AccessibilityMode(AccessMode.FromQueueOnly)]
IDocument GetDocument(string id);

//IModeledDocument<T> GetDocument<T>(string id) where T : class, new();

/// <summary>
/// Runs the given batch of operations as an atomic unit
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Couchbase.Lite/API/IDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Couchbase.Lite
/// <summary>
/// An interface describing a Couchbase Lite document
/// </summary>
public interface IDocument : IPropertyContainer, IDisposable
public interface IDocument : IPropertyContainer, IDisposable/*, IModellable*/
{
#region Properties

Expand Down
53 changes: 0 additions & 53 deletions src/Couchbase.Lite/API/IDocumentMetadata.cs

This file was deleted.

8 changes: 4 additions & 4 deletions src/Couchbase.Lite/API/IDocumentModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ namespace Couchbase.Lite
/// Using this interface, an arbitrary non-Couchbase class can become
/// the model for retrieving data
/// </summary>
public interface IDocumentModel
internal interface IDocumentModel
{
#region Properties

/// <summary>
/// Gets or sets the metadata for the document (note:
/// this should only be set by the library)
/// Gets or sets the document that is used to populate this instance
/// of a concrete class
/// </summary>
IDocumentMetadata Metadata { get; set; }
IDocument Document { get; set; }

#endregion
}
Expand Down
59 changes: 0 additions & 59 deletions src/Couchbase.Lite/API/IModeledDocument.cs

This file was deleted.

17 changes: 17 additions & 0 deletions src/Couchbase.Lite/API/Query/DataSourceFactory.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Couchbase.Lite.DB;
using Couchbase.Lite.Querying;

namespace Couchbase.Lite.Query
{
Expand All @@ -19,5 +21,20 @@ public static IDatabaseSource Database(IDatabase database)

return new DatabaseSource(db);
}

internal static IQueryable<TElement> LinqDataSource<TElement>(IDatabase database, bool prefetch)
where TElement : class, IDocumentModel, new()
{
if (database == null) {
throw new ArgumentNullException(nameof(database));
}

var db = database as Database;
if (db == null) {
throw new NotSupportedException("Custom IDatabase not supported");
}

return new DatabaseQueryable<TElement>(db, prefetch);
}
}
}
58 changes: 0 additions & 58 deletions src/Couchbase.Lite/API/QueryableFactory.cs

This file was deleted.

1 change: 1 addition & 0 deletions src/Couchbase.Lite/Couchbase.Lite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="Remotion.Linq" Version="2.1.1" />
<PackageReference Include="System.Linq.Expressions" Version="4.3.0" />
<PackageReference Include="System.Net.WebSockets.Client" Version="4.3.0" />
<PackageReference Include="System.Security.Cryptography.Algorithms" Version="4.3.0" />
</ItemGroup>

Expand Down
Loading

0 comments on commit 479ff1b

Please sign in to comment.