Skip to content

Commit 58daca9

Browse files
committed
Added DB operations to IPowerSyncDatabase interface.
1 parent 7f795ab commit 58daca9

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

PowerSync/PowerSync.Common/Client/PowerSyncDatabase.cs

Lines changed: 23 additions & 5 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

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.

0 commit comments

Comments
 (0)