Skip to content

Commit ab62cc1

Browse files
committed
Merge branch 'main' into feat/nuget-release
2 parents 8342b51 + 2ae759e commit ab62cc1

File tree

7 files changed

+24
-41
lines changed

7 files changed

+24
-41
lines changed

PowerSync/PowerSync.Common/Client/PowerSyncDatabase.cs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ public class BasePowerSyncDatabaseOptions()
2828

2929
}
3030

31-
public abstract class DatabaseSource { }
31+
public interface IDatabaseSource { }
3232

33-
public class DBAdapterSource(IDBAdapter Adapter) : DatabaseSource
33+
public class DBAdapterSource(IDBAdapter Adapter) : IDatabaseSource
3434
{
3535
public IDBAdapter Adapter { get; init; } = Adapter;
3636
}
3737

38-
public class OpenFactorySource(ISQLOpenFactory Factory) : DatabaseSource
38+
public class OpenFactorySource(ISQLOpenFactory Factory) : IDatabaseSource
3939
{
4040
public ISQLOpenFactory Factory { get; init; } = Factory;
4141
}
@@ -45,8 +45,7 @@ public class PowerSyncDatabaseOptions() : BasePowerSyncDatabaseOptions()
4545
/// <summary>
4646
/// Source for a SQLite database connection.
4747
/// </summary>
48-
public DatabaseSource Database { get; set; } = null!;
49-
48+
public IDatabaseSource Database { get; set; } = null!;
5049
}
5150

5251
public class PowerSyncDBEvent : StreamingSyncImplementationEvent
@@ -63,6 +62,25 @@ public interface IPowerSyncDatabase : IEventStream<PowerSyncDBEvent>
6362
public Task<CrudBatch?> GetCrudBatch(int limit);
6463

6564
public Task<CrudTransaction?> GetNextCrudTransaction();
65+
66+
Task<NonQueryResult> Execute(string query, object[]? parameters = null);
67+
68+
Task<T[]> GetAll<T>(string sql, params object[]? parameters);
69+
70+
Task<T?> GetOptional<T>(string sql, params object[]? parameters);
71+
72+
Task<T> Get<T>(string sql, params object[]? parameters);
73+
74+
Task<T> ReadLock<T>(Func<ILockContext, Task<T>> fn, DBLockOptions? options = null);
75+
76+
Task<T> ReadTransaction<T>(Func<ITransaction, Task<T>> fn, DBLockOptions? options = null);
77+
78+
Task WriteLock(Func<ILockContext, Task> fn, DBLockOptions? options = null);
79+
Task<T> WriteLock<T>(Func<ILockContext, Task<T>> fn, DBLockOptions? options = null);
80+
81+
Task WriteTransaction(Func<ITransaction, Task> fn, DBLockOptions? options = null);
82+
Task<T> WriteTransaction<T>(Func<ITransaction, Task<T>> fn, DBLockOptions? options = null);
83+
6684
}
6785

6886
public class PowerSyncDatabase : EventStream<PowerSyncDBEvent>, IPowerSyncDatabase
@@ -102,9 +120,6 @@ public PowerSyncDatabase(PowerSyncDatabaseOptions options)
102120
}
103121
else if (options.Database is SQLOpenOptions openOptions)
104122
{
105-
// TODO default to MDSQLite factory for now
106-
// Can be broken out, rename this class to Abstract
107-
// `this.openDBAdapter(options)`
108123
Database = new MDSQLiteAdapter(new MDSQLiteAdapterOptions
109124
{
110125
Name = openOptions.DbFilename,
@@ -346,7 +361,6 @@ public async Task DisconnectAndClear()
346361
await Disconnect();
347362
await WaitForReady();
348363

349-
// TODO CL bool clearLocal = options?.ClearLocal ?? false;
350364
bool clearLocal = true;
351365

352366
await Database.WriteTransaction(async tx =>
@@ -364,12 +378,6 @@ await Database.WriteTransaction(async tx =>
364378
base.Close();
365379
await WaitForReady();
366380

367-
// TODO CL
368-
// if (options.Disconnect)
369-
// {
370-
// await Disconnect();
371-
// }
372-
373381
syncStreamImplementation?.Close();
374382
BucketStorageAdapter?.Close();
375383

PowerSync/PowerSync.Common/Client/SQLOpenFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace PowerSync.Common.Client;
22

33
using PowerSync.Common.DB;
44

5-
public class SQLOpenOptions : DatabaseSource
5+
public class SQLOpenOptions : IDatabaseSource
66
{
77
/// <summary>
88
/// Filename for the database.

PowerSync/PowerSync.Common/Client/Sync/Stream/Remote.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public Remote(IPowerSyncBackendConnector connector)
5050

5151
credentials = await connector.FetchCredentials();
5252

53-
// TODO CL trailing forward slash check
5453
return credentials;
5554
}
5655

@@ -155,7 +154,6 @@ private async Task<HttpRequestMessage> BuildRequest(HttpMethod method, string pa
155154

156155
if (string.IsNullOrEmpty(credentials.Token))
157156
{
158-
// TODO CL error status code 401
159157
var error = new HttpRequestException("Not signed in");
160158
throw error;
161159
}

PowerSync/PowerSync.Common/Client/Sync/Stream/StreamingSyncImplementation.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ public StreamingSyncImplementation(StreamingSyncImplementationOptions options)
131131

132132
CancellationTokenSource = null;
133133

134-
// TODO CL throttling
135134
TriggerCrudUpload = () =>
136135
{
137136
if (!SyncStatus.Connected || SyncStatus.DataFlowStatus.Uploading)

PowerSync/PowerSync.Common/DB/Schema/Table.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ namespace PowerSync.Common.DB.Schema;
22

33
using Newtonsoft.Json;
44

5-
// TODO CL Need to port this to C#
6-
// export const InvalidSQLCharacters = /["'%,.#\s[\]]/;
7-
85
public class TableOptions(
96
Dictionary<string, List<string>>? indexes = null,
107
bool? localOnly = null,

PowerSync/PowerSync.Common/MDSQLite/MDSQLiteConnection.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ public async Task<QueryResult> ExecuteQuery(string query, object[]? parameters =
142142
var row = new Dictionary<string, object>();
143143
for (int i = 0; i < reader.FieldCount; i++)
144144
{
145-
// TODO: What should we do with null values?
146145
row[reader.GetName(i)] = reader.IsDBNull(i) ? null : reader.GetValue(i);
147146
}
148147
rows.Add(row);
@@ -164,8 +163,6 @@ public async Task<T[]> GetAll<T>(string sql, object[]? parameters = null)
164163

165164
var items = new List<T>();
166165

167-
// TODO: Improve mapping errors for when the result fields don't match the target type.
168-
// TODO: This conversion may be a performance bottleneck, it's the easiest mechamisn for getting result typing.
169166
foreach (var row in result.Rows.Array)
170167
{
171168
if (row != null)
@@ -197,8 +194,6 @@ public async Task<T[]> GetAll<T>(string sql, object[]? parameters = null)
197194
return default;
198195
}
199196

200-
// TODO: Improve mapping errors for when the result fields don't match the target type.
201-
// TODO: This conversion may be a performance bottleneck, it's the easiest mechamisn for getting result typing.
202197
string json = JsonConvert.SerializeObject(firstRow);
203198
return JsonConvert.DeserializeObject<T>(json);
204199
}

commands

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)