diff --git a/PowerSync/PowerSync.Common/CHANGELOG.md b/PowerSync/PowerSync.Common/CHANGELOG.md index aa1f857..5e01c47 100644 --- a/PowerSync/PowerSync.Common/CHANGELOG.md +++ b/PowerSync/PowerSync.Common/CHANGELOG.md @@ -1,5 +1,40 @@ # PowerSync.Common Changelog +## 0.0.9-alpha.1 + +- _Breaking:_ Further updated schema definition syntax. + - Renamed `Schema` and `Table` to `CompiledSchema` and `CompiledTable` and renamed `SchemaFactory` and `TableFactory` to `Schema` and `Table`. + - Made `CompiledSchema` and `CompiledTable` internal classes. + - These are the last breaking changes to schema definition before entering beta. + +```csharp +public static Table Assets = new Table +{ + Name = "assets", + Columns = + { + ["make"] = ColumnType.Text, + ["model"] = ColumnType.Text, + // ... + }, + Indexes = + { + ["makemodel"] = ["make", "model"], + }, +}; + +public static Table Customers = new Table +{ + Name = "customers", + Columns = + { + ["name"] = ColumnType.Text, + }, +}; + +public static Schema PowerSyncSchema = new Schema(Assets, Customers); +``` + ## 0.0.8-alpha.1 - Updated the syntax for defining the app schema to use a factory pattern. diff --git a/PowerSync/PowerSync.Common/Client/PowerSyncDatabase.cs b/PowerSync/PowerSync.Common/Client/PowerSyncDatabase.cs index 4e5c138..ef78479 100644 --- a/PowerSync/PowerSync.Common/Client/PowerSyncDatabase.cs +++ b/PowerSync/PowerSync.Common/Client/PowerSyncDatabase.cs @@ -101,7 +101,7 @@ public interface IPowerSyncDatabase : IEventStream public class PowerSyncDatabase : EventStream, IPowerSyncDatabase { public IDBAdapter Database { get; protected set; } - private Schema schema; + private CompiledSchema schema; private static readonly int DEFAULT_WATCH_THROTTLE_MS = 30; private static readonly Regex POWERSYNC_TABLE_MATCH = new Regex(@"(^ps_data__|^ps_data_local__)", RegexOptions.Compiled); @@ -168,7 +168,7 @@ public PowerSyncDatabase(PowerSyncDatabaseOptions options) Closed = false; Ready = false; - schema = options.Schema; + schema = options.Schema.Compile(); SdkVersion = ""; remoteFactory = options.RemoteFactory ?? (connector => new Remote(connector)); @@ -223,7 +223,7 @@ public PowerSyncDatabase(PowerSyncDatabaseOptions options) } }, logger: Logger); - IsReadyTask = Initialize(); + IsReadyTask = Initialize(options); } protected IBucketStorageAdapter generateBucketStorageAdapter() @@ -307,11 +307,11 @@ public async Task WaitForStatus(Func predicate, CancellationTo await tcs.Task; } - protected async Task Initialize() + protected async Task Initialize(PowerSyncDatabaseOptions options) { await BucketStorageAdapter.Init(); await LoadVersion(); - await UpdateSchema(schema); + await UpdateSchema(options.Schema); await ResolveOfflineSyncStatus(); await Database.Execute("PRAGMA RECURSIVE_TRIGGERS=TRUE"); Ready = true; @@ -369,6 +369,7 @@ protected async Task ResolveOfflineSyncStatus() /// public async Task UpdateSchema(Schema schema) { + CompiledSchema compiledSchema = schema.Compile(); if (syncStreamImplementation != null) { throw new Exception("Cannot update schema while connected"); @@ -376,15 +377,15 @@ public async Task UpdateSchema(Schema schema) try { - schema.Validate(); + compiledSchema.Validate(); } catch (Exception ex) { Logger.LogWarning("Schema validation failed. Unexpected behavior could occur: {Exception}", ex); } - this.schema = schema; - await Database.Execute("SELECT powersync_replace_schema(?)", [schema.ToJSON()]); + this.schema = compiledSchema; + await Database.Execute("SELECT powersync_replace_schema(?)", [compiledSchema.ToJSON()]); await Database.RefreshSchema(); Emit(new PowerSyncDBEvent { SchemaChanged = schema }); } diff --git a/PowerSync/PowerSync.Common/DB/Schema/CompiledSchema.cs b/PowerSync/PowerSync.Common/DB/Schema/CompiledSchema.cs new file mode 100644 index 0000000..8055e21 --- /dev/null +++ b/PowerSync/PowerSync.Common/DB/Schema/CompiledSchema.cs @@ -0,0 +1,41 @@ +namespace PowerSync.Common.DB.Schema; + +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +class CompiledSchema(Dictionary tables) +{ + private readonly Dictionary Tables = tables; + + public void Validate() + { + foreach (var kvp in Tables) + { + var tableName = kvp.Key; + var table = kvp.Value; + + if (CompiledTable.InvalidSQLCharacters.IsMatch(tableName)) + { + throw new Exception($"Invalid characters in table name: {tableName}"); + } + + table.Validate(); + } + } + + public string ToJSON() + { + var jsonObject = new + { + tables = Tables.Select(kv => + { + var json = JObject.Parse(kv.Value.ToJSON(kv.Key)); + var orderedJson = new JObject { ["name"] = kv.Key }; + orderedJson.Merge(json, new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Concat }); + return orderedJson; + }).ToList() + }; + + return JsonConvert.SerializeObject(jsonObject); + } +} diff --git a/PowerSync/PowerSync.Common/DB/Schema/CompiledTable.cs b/PowerSync/PowerSync.Common/DB/Schema/CompiledTable.cs new file mode 100644 index 0000000..8a1e5d3 --- /dev/null +++ b/PowerSync/PowerSync.Common/DB/Schema/CompiledTable.cs @@ -0,0 +1,136 @@ +namespace PowerSync.Common.DB.Schema; + +using System.Collections.Generic; +using System.Text.RegularExpressions; + +using Newtonsoft.Json; + +class CompiledTable +{ + public static readonly Regex InvalidSQLCharacters = new Regex(@"[""'%,.#\s\[\]]", RegexOptions.Compiled); + + public string Name { get; init; } = null!; + protected TableOptions Options { get; init; } = null!; + public IReadOnlyDictionary Columns { get; init; } + public IReadOnlyDictionary> Indexes { get; init; } + + private readonly ColumnJSON[] ColumnsJSON; + private readonly IndexJSON[] IndexesJSON; + + public CompiledTable(string name, Dictionary columns, TableOptions options) + { + ColumnsJSON = + columns + .Select(kvp => new ColumnJSON(new ColumnJSONOptions(kvp.Key, kvp.Value))) + .ToArray(); + + IndexesJSON = + (Options?.Indexes ?? []) + .Select(kvp => + new IndexJSON(new IndexJSONOptions( + kvp.Key, + kvp.Value.Select(name => + new IndexedColumnJSON(new IndexedColumnJSONOptions( + name.Replace("-", ""), !name.StartsWith("-"))) + ).ToArray() + )) + ) + .ToArray(); + + Name = name; + Columns = columns; + Options = options; + Indexes = Options?.Indexes ?? []; + } + + public void Validate() + { + if (string.IsNullOrWhiteSpace(Name)) + { + throw new Exception($"Table name is required."); + } + + if (!string.IsNullOrWhiteSpace(Options.ViewName) && InvalidSQLCharacters.IsMatch(Options.ViewName!)) + { + throw new Exception($"Invalid characters in view name: {Options.ViewName}"); + } + + if (Columns.Count > Table.MAX_AMOUNT_OF_COLUMNS) + { + throw new Exception( + $"Table has too many columns. The maximum number of columns is {Table.MAX_AMOUNT_OF_COLUMNS}."); + } + + if (Options.TrackMetadata && Options.LocalOnly) + { + throw new Exception("Can't include metadata for local-only tables."); + } + + if (Options.TrackPreviousValues != null && Options.LocalOnly) + { + throw new Exception("Can't include old values for local-only tables."); + } + + var columnNames = new HashSet { "id" }; + + foreach (var columnName in Columns.Keys) + { + if (columnName == "id") + { + throw new Exception("An id column is automatically added, custom id columns are not supported"); + } + + if (InvalidSQLCharacters.IsMatch(columnName)) + { + throw new Exception($"Invalid characters in column name: {columnName}"); + } + + columnNames.Add(columnName); + } + + foreach (var kvp in Indexes) + { + var indexName = kvp.Key; + var indexColumns = kvp.Value; + + if (InvalidSQLCharacters.IsMatch(indexName)) + { + throw new Exception($"Invalid characters in index name: {indexName}"); + } + + foreach (var indexColumn in indexColumns) + { + if (!columnNames.Contains(indexColumn)) + { + throw new Exception($"Column {indexColumn} not found for index {indexName}"); + } + } + } + } + + public string ToJSON(string Name = "") + { + var trackPrevious = Options.TrackPreviousValues; + + var jsonObject = new + { + view_name = Options.ViewName ?? Name, + local_only = Options.LocalOnly, + insert_only = Options.InsertOnly, + columns = ColumnsJSON.Select(c => c.ToJSONObject()).ToList(), + indexes = IndexesJSON.Select(i => i.ToJSONObject(this)).ToList(), + + include_metadata = Options.TrackMetadata, + ignore_empty_update = Options.IgnoreEmptyUpdates, + include_old = (object)(trackPrevious switch + { + null => false, + { Columns: null } => true, + { Columns: var cols } => cols + }), + include_old_only_when_changed = trackPrevious?.OnlyWhenChanged ?? false + }; + + return JsonConvert.SerializeObject(jsonObject); + } +} diff --git a/PowerSync/PowerSync.Common/DB/Schema/IndexJSON.cs b/PowerSync/PowerSync.Common/DB/Schema/IndexJSON.cs index 573b7e1..e316017 100644 --- a/PowerSync/PowerSync.Common/DB/Schema/IndexJSON.cs +++ b/PowerSync/PowerSync.Common/DB/Schema/IndexJSON.cs @@ -12,7 +12,7 @@ class IndexJSON(IndexJSONOptions options) public IndexedColumnJSON[] Columns => options.Columns ?? []; - public object ToJSONObject(Table table) + public object ToJSONObject(CompiledTable table) { return new { diff --git a/PowerSync/PowerSync.Common/DB/Schema/IndexedColumnJSON.cs b/PowerSync/PowerSync.Common/DB/Schema/IndexedColumnJSON.cs index 198685d..6e499a1 100644 --- a/PowerSync/PowerSync.Common/DB/Schema/IndexedColumnJSON.cs +++ b/PowerSync/PowerSync.Common/DB/Schema/IndexedColumnJSON.cs @@ -14,7 +14,7 @@ class IndexedColumnJSON(IndexedColumnJSONOptions options) protected bool Ascending { get; set; } = options.Ascending; - public string ToJSON(Table table) + public string ToJSON(CompiledTable table) { var colType = table.Columns.TryGetValue(Name, out var value) ? value : default; diff --git a/PowerSync/PowerSync.Common/DB/Schema/Schema.cs b/PowerSync/PowerSync.Common/DB/Schema/Schema.cs index 3b60b4e..8b932b3 100644 --- a/PowerSync/PowerSync.Common/DB/Schema/Schema.cs +++ b/PowerSync/PowerSync.Common/DB/Schema/Schema.cs @@ -1,41 +1,22 @@ namespace PowerSync.Common.DB.Schema; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -public class Schema(Dictionary tables) +public class Schema { - private readonly Dictionary Tables = tables; + private readonly List _tables; - public void Validate() + public Schema(params Table[] tables) { - foreach (var kvp in Tables) - { - var tableName = kvp.Key; - var table = kvp.Value; - - if (Table.InvalidSQLCharacters.IsMatch(tableName)) - { - throw new Exception($"Invalid characters in table name: {tableName}"); - } - - table.Validate(); - } + _tables = tables.ToList(); } - public string ToJSON() + internal CompiledSchema Compile() { - var jsonObject = new + Dictionary tableMap = new(); + foreach (Table table in _tables) { - tables = Tables.Select(kv => - { - var json = JObject.Parse(kv.Value.ToJSON(kv.Key)); - var orderedJson = new JObject { ["name"] = kv.Key }; - orderedJson.Merge(json, new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Concat }); - return orderedJson; - }).ToList() - }; - - return JsonConvert.SerializeObject(jsonObject); + var compiled = table.Compile(); + tableMap[compiled.Name] = compiled; + } + return new CompiledSchema(tableMap); } } diff --git a/PowerSync/PowerSync.Common/DB/Schema/SchemaFactory.cs b/PowerSync/PowerSync.Common/DB/Schema/SchemaFactory.cs deleted file mode 100644 index 85b4f08..0000000 --- a/PowerSync/PowerSync.Common/DB/Schema/SchemaFactory.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace PowerSync.Common.DB.Schema; - -public class SchemaFactory -{ - private readonly List
_tables; - - public SchemaFactory(params Table[] tables) - { - _tables = tables.ToList(); - } - - public SchemaFactory(params TableFactory[] tableFactories) - { - _tables = tableFactories.Select((f) => f.Create()).ToList(); - } - - public Schema Create() - { - Dictionary tableMap = new(); - foreach (Table table in _tables) - { - tableMap[table.Name] = table; - } - return new Schema(tableMap); - } -} diff --git a/PowerSync/PowerSync.Common/DB/Schema/Table.cs b/PowerSync/PowerSync.Common/DB/Schema/Table.cs index e120c08..bc4b01b 100644 --- a/PowerSync/PowerSync.Common/DB/Schema/Table.cs +++ b/PowerSync/PowerSync.Common/DB/Schema/Table.cs @@ -1,8 +1,5 @@ namespace PowerSync.Common.DB.Schema; -using System.Collections.Generic; -using System.Text.RegularExpressions; - using Newtonsoft.Json; public class TableOptions( @@ -21,7 +18,7 @@ public class TableOptions( public bool InsertOnly { get; set; } = insertOnly ?? false; - public string? ViewName { get; } = viewName; + public string? ViewName { get; set; } = viewName; /// /// Whether to add a hidden `_metadata` column that will be enabled for updates to attach custom @@ -65,131 +62,69 @@ public class Table { public const int MAX_AMOUNT_OF_COLUMNS = 1999; - public static readonly Regex InvalidSQLCharacters = new Regex(@"[""'%,.#\s\[\]]", RegexOptions.Compiled); + public Dictionary Columns { get; set; } = new(); - public string Name { get; init; } = null!; - protected TableOptions Options { get; init; } = null!; - public IReadOnlyDictionary Columns { get; init; } - public IReadOnlyDictionary> Indexes { get; init; } + public TableOptions Options { get; set; } - private readonly ColumnJSON[] ColumnsJSON; - private readonly IndexJSON[] IndexesJSON; + public string Name { get; set; } = null!; - public Table(string name, Dictionary columns, TableOptions? options = null) + public Dictionary> Indexes + { + get { return Options.Indexes; } + set { Options.Indexes = value; } + } + public bool LocalOnly + { + get { return Options.LocalOnly; } + set { Options.LocalOnly = value; } + } + public bool InsertOnly + { + get { return Options.InsertOnly; } + set { Options.InsertOnly = value; } + } + string? ViewName + { + get { return Options.ViewName; } + set { Options.ViewName = value; } + } + bool TrackMetadata + { + get { return Options.TrackMetadata; } + set { Options.TrackMetadata = value; } + } + TrackPreviousOptions? TrackPreviousValues { - ColumnsJSON = - columns - .Select(kvp => new ColumnJSON(new ColumnJSONOptions(kvp.Key, kvp.Value))) - .ToArray(); - - IndexesJSON = - (Options?.Indexes ?? []) - .Select(kvp => - new IndexJSON(new IndexJSONOptions( - kvp.Key, - kvp.Value.Select(name => - new IndexedColumnJSON(new IndexedColumnJSONOptions( - name.Replace("-", ""), !name.StartsWith("-"))) - ).ToArray() - )) - ) - .ToArray(); + get { return Options.TrackPreviousValues; } + set { Options.TrackPreviousValues = value; } + } + bool IgnoreEmptyUpdates + { + get { return Options.IgnoreEmptyUpdates; } + set { Options.IgnoreEmptyUpdates = value; } + } - Options = options ?? new TableOptions(); + public Table() + { + Options = new TableOptions(); + } + // Mirrors the legacy syntax, as well as the syntax found in the other SDKs. + public Table(string name, Dictionary columns, TableOptions? options = null) + { Name = name; Columns = columns; - Indexes = Options?.Indexes ?? []; + Options = options ?? new TableOptions(); } - public void Validate() + internal CompiledTable Compile() { if (string.IsNullOrWhiteSpace(Name)) { - throw new Exception($"Table name is required."); - } - - if (!string.IsNullOrWhiteSpace(Options.ViewName) && InvalidSQLCharacters.IsMatch(Options.ViewName!)) - { - throw new Exception($"Invalid characters in view name: {Options.ViewName}"); + throw new InvalidOperationException("Table name is required."); } - if (Columns.Count > MAX_AMOUNT_OF_COLUMNS) - { - throw new Exception( - $"Table has too many columns. The maximum number of columns is {MAX_AMOUNT_OF_COLUMNS}."); - } - - if (Options.TrackMetadata && Options.LocalOnly) - { - throw new Exception("Can't include metadata for local-only tables."); - } - - if (Options.TrackPreviousValues != null && Options.LocalOnly) - { - throw new Exception("Can't include old values for local-only tables."); - } - - var columnNames = new HashSet { "id" }; - - foreach (var columnName in Columns.Keys) - { - if (columnName == "id") - { - throw new Exception("An id column is automatically added, custom id columns are not supported"); - } - - if (InvalidSQLCharacters.IsMatch(columnName)) - { - throw new Exception($"Invalid characters in column name: {columnName}"); - } - - columnNames.Add(columnName); - } - - foreach (var kvp in Indexes) - { - var indexName = kvp.Key; - var indexColumns = kvp.Value; - - if (InvalidSQLCharacters.IsMatch(indexName)) - { - throw new Exception($"Invalid characters in index name: {indexName}"); - } - - foreach (var indexColumn in indexColumns) - { - if (!columnNames.Contains(indexColumn)) - { - throw new Exception($"Column {indexColumn} not found for index {indexName}"); - } - } - } - } - - public string ToJSON(string Name = "") - { - var trackPrevious = Options.TrackPreviousValues; - - var jsonObject = new - { - view_name = Options.ViewName ?? Name, - local_only = Options.LocalOnly, - insert_only = Options.InsertOnly, - columns = ColumnsJSON.Select(c => c.ToJSONObject()).ToList(), - indexes = IndexesJSON.Select(i => i.ToJSONObject(this)).ToList(), - - include_metadata = Options.TrackMetadata, - ignore_empty_update = Options.IgnoreEmptyUpdates, - include_old = (object)(trackPrevious switch - { - null => false, - { Columns: null } => true, - { Columns: var cols } => cols - }), - include_old_only_when_changed = trackPrevious?.OnlyWhenChanged ?? false - }; - - return JsonConvert.SerializeObject(jsonObject); + return new CompiledTable(Name, Columns, Options); } } + diff --git a/PowerSync/PowerSync.Common/DB/Schema/TableFactory.cs b/PowerSync/PowerSync.Common/DB/Schema/TableFactory.cs deleted file mode 100644 index 18de684..0000000 --- a/PowerSync/PowerSync.Common/DB/Schema/TableFactory.cs +++ /dev/null @@ -1,56 +0,0 @@ -namespace PowerSync.Common.DB.Schema; - -using System.Collections; - -public class TableFactory() -{ - public ColumnMap Columns { get; set; } = new(); - public IndexMap Indexes { get; set; } = new(); - - public string Name { get; set; } = null!; - public bool LocalOnly { get; set; } = false; - public bool InsertOnly { get; set; } = false; - string? ViewName { get; set; } - bool? TrackMetadata { get; set; } - TrackPreviousOptions? TrackPreviousValues { get; set; } - bool? IgnoreEmptyUpdates { get; set; } - - public Table Create() - { - if (string.IsNullOrWhiteSpace(Name)) - { - throw new Exception("Table name is required."); - } - TableOptions options = new( - indexes: Indexes.Indexes, - localOnly: LocalOnly, - insertOnly: InsertOnly, - viewName: ViewName, - trackMetadata: TrackMetadata, - trackPreviousValues: TrackPreviousValues, - ignoreEmptyUpdates: IgnoreEmptyUpdates - ); - return new Table(Name, Columns.Columns, options); - } -} - -public class ColumnMap : IEnumerable -{ - public Dictionary Columns { get; } = new(); - - public void Add(string key, ColumnType value) => Columns.Add(key, value); - - public ColumnType this[string name] { set { Columns[name] = value; } } - public IEnumerator GetEnumerator() => Columns.GetEnumerator(); -} - -public class IndexMap : IEnumerable -{ - public Dictionary> Indexes { get; } = new(); - - public void Add(string key, List value) => Indexes.Add(key, value); - - public List this[string name] { set { Indexes[name] = value; } } - public IEnumerator GetEnumerator() => Indexes.GetEnumerator(); -} - diff --git a/PowerSync/PowerSync.Maui/CHANGELOG.md b/PowerSync/PowerSync.Maui/CHANGELOG.md index eb52f4d..f903a1d 100644 --- a/PowerSync/PowerSync.Maui/CHANGELOG.md +++ b/PowerSync/PowerSync.Maui/CHANGELOG.md @@ -1,20 +1,30 @@ # PowerSync.Maui Changelog +## 0.0.7-alpha.1 + +- Upstream PowerSync.Common version bump (See Powersync.Common changelog 0.0.9-alpha.1 for more information) + - _Breaking:_ Updates to how the application schema is defined. + ## 0.0.6-alpha.1 + - Upstream PowerSync.Common version bump (See Powersync.Common changelog 0.0.8-alpha.1 for more information) ## 0.0.5-alpha.1 + - Upstream PowerSync.Common version bump (See Powersync.Common changelog 0.0.7-alpha.1 for more information) ## 0.0.4-alpha.1 + - Upstream PowerSync.Common version bump (See Powersync.Common changelog 0.0.6-alpha.1 for more information) - Added ability to specify `AppMetadata` sync/stream requests (see Common changelog). ## 0.0.3-alpha.1 + - Upstream PowerSync.Common version bump (See PowerSync.Common change 0.0.5-alpha.1 for more information) - Using the latest (0.4.9) version of the core extension, it introduces support for the Rust Sync implementation and also makes it the default - users can still opt out and use the legacy C# sync implementation as option when calling `connect()`. ## 0.0.2-alpha.1 + - Fixed issues related to extension loading when installing package outside of the monorepo. ## 0.0.1-alpha.1 @@ -22,5 +32,6 @@ - Introduce package. Support for iOS/Android use cases. ### Platform Runtime Support Added -* MAUI iOS -* MAUI Android + +- MAUI iOS +- MAUI Android diff --git a/Tests/PowerSync/PowerSync.Common.IntegrationTests/PowerSync.Common.IntegrationTests.csproj b/Tests/PowerSync/PowerSync.Common.IntegrationTests/PowerSync.Common.IntegrationTests.csproj index 21189c9..f387380 100644 --- a/Tests/PowerSync/PowerSync.Common.IntegrationTests/PowerSync.Common.IntegrationTests.csproj +++ b/Tests/PowerSync/PowerSync.Common.IntegrationTests/PowerSync.Common.IntegrationTests.csproj @@ -1,17 +1,23 @@  - net8.0 + netstandard2.0;net8.0 + 12 enable enable + false + true - + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + diff --git a/Tests/PowerSync/PowerSync.Common.IntegrationTests/TestSchema.cs b/Tests/PowerSync/PowerSync.Common.IntegrationTests/TestSchema.cs index 122a25d..92a5ede 100644 --- a/Tests/PowerSync/PowerSync.Common.IntegrationTests/TestSchema.cs +++ b/Tests/PowerSync/PowerSync.Common.IntegrationTests/TestSchema.cs @@ -4,7 +4,7 @@ namespace PowerSync.Common.IntegrationTests; public class TestSchema { - public static TableFactory Todos = new TableFactory() + public static Table Todos = new Table { Name = "todos", Columns = @@ -24,7 +24,7 @@ public class TestSchema }; - public static TableFactory Lists = new TableFactory() + public static Table Lists = new Table { Name = "lists", Columns = @@ -35,5 +35,5 @@ public class TestSchema } }; - public static Schema PowerSyncSchema = new SchemaFactory(Todos, Lists).Create(); + public static Schema PowerSyncSchema = new Schema(Todos, Lists); } diff --git a/Tests/PowerSync/PowerSync.Common.Tests/Client/Sync/CRUDTests.cs b/Tests/PowerSync/PowerSync.Common.Tests/Client/Sync/CRUDTests.cs index 53fe1fd..6f877e9 100644 --- a/Tests/PowerSync/PowerSync.Common.Tests/Client/Sync/CRUDTests.cs +++ b/Tests/PowerSync/PowerSync.Common.Tests/Client/Sync/CRUDTests.cs @@ -297,10 +297,7 @@ public async Task InsertOnlyTablesTest() InsertOnly = true }); - Schema insertOnlySchema = new Schema(new Dictionary - { - { "logs", logs }, - }); + Schema insertOnlySchema = new Schema(logs); var uniqueDbName = $"test-{Guid.NewGuid()}.db"; diff --git a/Tests/PowerSync/PowerSync.Common.Tests/TestSchema.cs b/Tests/PowerSync/PowerSync.Common.Tests/TestSchema.cs index ea583f5..55b9a97 100644 --- a/Tests/PowerSync/PowerSync.Common.Tests/TestSchema.cs +++ b/Tests/PowerSync/PowerSync.Common.Tests/TestSchema.cs @@ -4,7 +4,7 @@ namespace PowerSync.Common.Tests; public class TestSchemaTodoList { - public static TableFactory Todos = new TableFactory() + public static Table Todos = new Table { Name = "todos", Columns = @@ -23,7 +23,7 @@ public class TestSchemaTodoList } }; - public static TableFactory Lists = new TableFactory() + public static Table Lists = new Table { Name = "lists", Columns = @@ -34,12 +34,12 @@ public class TestSchemaTodoList } }; - public static readonly Schema AppSchema = new SchemaFactory(Todos, Lists).Create(); + public static readonly Schema AppSchema = new Schema(Todos, Lists); } public class TestSchema { - public static readonly ColumnMap AssetsColumns = new ColumnMap + public static readonly Dictionary AssetsColumns = new() { ["created_at"] = ColumnType.Text, ["make"] = ColumnType.Text, @@ -51,7 +51,7 @@ public class TestSchema ["description"] = ColumnType.Text, }; - public static readonly Table Assets = new TableFactory() + public static readonly Table Assets = new Table { Name = "assets", Columns = AssetsColumns, @@ -59,9 +59,9 @@ public class TestSchema { ["makemodel"] = ["make", "model"] } - }.Create(); + }; - public static readonly Table Customers = new TableFactory() + public static readonly Table Customers = new Table { Name = "customers", Columns = @@ -69,14 +69,14 @@ public class TestSchema ["name"] = ColumnType.Text, ["email"] = ColumnType.Text, } - }.Create(); + }; - public static readonly Schema AppSchema = new SchemaFactory(Assets, Customers).Create(); + public static readonly Schema AppSchema = new Schema(Assets, Customers); public static Schema GetSchemaWithCustomAssetOptions(TableOptions? assetOptions = null) { - var customAssets = new Table("assets", AssetsColumns.Columns, assetOptions); + var customAssets = new Table("assets", AssetsColumns, assetOptions); - return new SchemaFactory(customAssets, Customers).Create(); + return new Schema(customAssets, Customers); } } diff --git a/demos/CommandLine/AppSchema.cs b/demos/CommandLine/AppSchema.cs index f531973..3631667 100644 --- a/demos/CommandLine/AppSchema.cs +++ b/demos/CommandLine/AppSchema.cs @@ -4,7 +4,7 @@ namespace CommandLine; class AppSchema { - public static TableFactory Todos = new TableFactory() + public static Table Todos = new Table { Name = "todos", Columns = @@ -24,7 +24,7 @@ class AppSchema } }; - public static TableFactory Lists = new TableFactory() + public static Table Lists = new Table { Name = "lists", Columns = { @@ -34,5 +34,5 @@ class AppSchema } }; - public static Schema PowerSyncSchema = new SchemaFactory(Todos, Lists).Create(); + public static Schema PowerSyncSchema = new Schema(Todos, Lists); } diff --git a/demos/MAUITodo/Data/AppSchema.cs b/demos/MAUITodo/Data/AppSchema.cs index 6562578..e261fd0 100644 --- a/demos/MAUITodo/Data/AppSchema.cs +++ b/demos/MAUITodo/Data/AppSchema.cs @@ -2,7 +2,7 @@ class AppSchema { - public static TableFactory Todos = new TableFactory() + public static Table Todos = new Table { Name = "todos", Columns = @@ -21,7 +21,7 @@ class AppSchema } }; - public static TableFactory Lists = new TableFactory() + public static Table Lists = new Table { Name = "lists", Columns = @@ -32,5 +32,5 @@ class AppSchema } }; - public static Schema PowerSyncSchema = new SchemaFactory(Todos, Lists).Create(); + public static Schema PowerSyncSchema = new Schema(Todos, Lists); } diff --git a/demos/WPF/Models/AppSchema.cs b/demos/WPF/Models/AppSchema.cs index 3ec15c5..a4fa75f 100644 --- a/demos/WPF/Models/AppSchema.cs +++ b/demos/WPF/Models/AppSchema.cs @@ -4,7 +4,7 @@ namespace PowersyncDotnetTodoList.Models; class AppSchema { - public static TableFactory Todos = new TableFactory() + public static Table Todos = new Table { Name = "todos", Columns = @@ -24,7 +24,7 @@ class AppSchema } }; - public static TableFactory Lists = new TableFactory() + public static Table Lists = new Table { Name = "lists", Columns = { @@ -34,5 +34,5 @@ class AppSchema } }; - public static Schema PowerSyncSchema = new SchemaFactory(Todos, Lists).Create(); + public static Schema PowerSyncSchema = new Schema(Todos, Lists); }