Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
Issues/440 (#445)
Browse files Browse the repository at this point in the history
* (#440) Added GetTablesAsync() to list from IOfflineStore.

* (#440) Fix for ConcreteOfflineStore impl. in tests.
  • Loading branch information
adrianhall authored Aug 5, 2022
1 parent 1c898a3 commit 0665f28
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,17 @@ public override async Task<Page<JObject>> GetPageAsync(QueryDescription query, C
}
}

/// <summary>
/// Gets the list of offline tables that have been defined.
/// </summary>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A task that returns the list of tables that have been defined.</returns>
public override async Task<IList<string>> GetTablesAsync(CancellationToken cancellationToken = default)
{
await EnsureInitializedAsync(cancellationToken).ConfigureAwait(false);
return tableMap.Keys.Where(t => !t.StartsWith("__")).ToList();
}

/// <summary>
/// Initialize the store. This is over-ridden by the store implementation to provide a point
/// where the tables can be created or updated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ public abstract class AbstractOfflineStore : IOfflineStore
/// <returns>A task that returns a page of items when complete.</returns>
public abstract Task<Page<JObject>> GetPageAsync(QueryDescription query, CancellationToken cancellationToken = default);

/// <summary>
/// Gets the list of offline tables that have been defined.
/// </summary>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A task that returns the list of tables that have been defined.</returns>
public abstract Task<IList<string>> GetTablesAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Initializes the store for use.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ public interface IOfflineStore : IDisposable
/// <returns>A task that returns a page of items when complete.</returns>
Task<Page<JObject>> GetPageAsync(QueryDescription query, CancellationToken cancellationToken = default);

/// <summary>
/// Gets the list of offline tables that have been defined.
/// </summary>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A task that returns the list of tables that have been defined.</returns>
Task<IList<string>> GetTablesAsync(CancellationToken cancellationToken = default);

/// <summary>
/// Initializes the store for use.
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions sdk/dotnet/test/Datasync.Common.Test/Mocks/MockOfflineStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ public Task<Page<JObject>> GetPageAsync(QueryDescription query, CancellationToke
}
}

/// <summary>
/// Gets the list of offline tables that have been defined.
/// </summary>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param>
/// <returns>A task that returns the list of tables that have been defined.</returns>
public Task<IList<string>> GetTablesAsync(CancellationToken cancellationToken = default)
{
var list = TableMap.Keys.Where(t => !t.StartsWith("__")).ToList();
return Task.FromResult((IList<string>)list);
}

/// <summary>
/// Initializes the store for use.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,20 @@ public async Task DeltaTokenStore_StoresWithMSAccuracy()
var storedToken = await deltaTokenStore.GetDeltaTokenAsync("testtable", "testquery");
Assert.Equal(storedToken.Millisecond, deltaToken.Millisecond);
}

[Fact]
public async Task GetTablesAsync_ReturnsListOfTables()
{
// Set up the default store and client.
var store = new OfflineSQLiteStore(ConnectionString);
store.DefineTable(TestTable, IdEntityDefinition);
var client = new DatasyncClient("https://localhost/", new DatasyncClientOptions { OfflineStore = store });
var context = new SyncContext(client, store);
await context.InitializeAsync();

var tables = await context.OfflineStore.GetTablesAsync();
Assert.Equal(1, tables.Count); // If it's 4, then the system tables are being returned as well.
Assert.Equal(TestTable, tables[0]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public override Task<Page<JObject>> GetPageAsync(QueryDescription query, Cancell
throw new NotImplementedException();
}

public override Task<IList<string>> GetTablesAsync(CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}

public override Task UpsertAsync(string tableName, IEnumerable<JObject> items, bool ignoreMissingColumns, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
Expand Down

0 comments on commit 0665f28

Please sign in to comment.