Skip to content

Conversation

stevensJourney
Copy link
Collaborator

@stevensJourney stevensJourney commented Apr 18, 2025

Overview

This adds Schema generators for the Kotlin, Swift and DotNet SDKs

Related https://github.com/journeyapps-platform/ide/pull/1105

Kotlin

import com.powersync.db.schema.Column
import com.powersync.db.schema.Schema
import com.powersync.db.schema.Table

val schema = Schema(
  Table(
    name = "assets1",
    columns = listOf(
        Column.text("name"),
        Column.integer("count"),
        Column.text("owner_id")
    )
  ),
  Table(
    name = "assets2",
    columns = listOf(
        Column.text("name"),
        Column.integer("count"),
        Column.text("other_id"),
        Column.text("foo")
    )
  )
)

Swift

import PowerSync

let schema = Schema(
  Table(
    name: "assets1",
    columns: [
        .text("name"), // text
        .integer("count"), // int4
        .text("owner_id") // uuid
    ]
  ),
  Table(
    name: "assets2",
    columns: [
        .text("name"), // text
        .integer("count"), // int4
        .text("other_id"), // uuid
        .text("foo")
    ]
  )
)

.Net

using PowerSync.Common.DB.Schema;

class AppSchema
{
  public static Table Assets1 = new Table(new Dictionary<string, ColumnType>
  {
      { "name", ColumnType.TEXT },
      { "count", ColumnType.INTEGER },
      { "owner_id", ColumnType.TEXT }
  });

  public static Table Assets2 = new Table(new Dictionary<string, ColumnType>
  {
      { "name", ColumnType.TEXT },
      { "count", ColumnType.INTEGER },
      { "other_id", ColumnType.TEXT },
      { "foo", ColumnType.TEXT }
  });

  public static Schema PowerSyncSchema = new Schema(new Dictionary<string, Table>
  {
    {"assets1", Assets1},
    {"assets2", Assets2}
  });
}

Copy link

changeset-bot bot commented Apr 18, 2025

🦋 Changeset detected

Latest commit: f01c062

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@stevensJourney stevensJourney requested a review from Copilot April 22, 2025 07:18
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds new schema generators for the Kotlin, Swift, and .Net SDKs, along with updates to file exports and associated tests.

  • Added tests for schema generation in Kotlin, Swift, and .Net.
  • Introduced new generator classes: KotlinSchemaGenerator, SwiftSchemaGenerator, DotNetSchemaGenerator.
  • Updated the export infrastructure to include the new generators.

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/sync-rules/test/src/generate_schema.test.ts Added tests validating schema generation for Kotlin, Swift, and .Net using new generators.
packages/sync-rules/src/schema-generators/schema-generators.ts Updated exports to include new generator modules.
packages/sync-rules/src/schema-generators/generators.ts Added imports and registrations for Kotlin, Swift, and DotNet generators.
packages/sync-rules/src/schema-generators/TsSchemaGenerator.ts Adjusted import paths to match updated project structure.
packages/sync-rules/src/schema-generators/SwiftSchemaGenerator.ts New implementation for Swift schema generation.
packages/sync-rules/src/schema-generators/SchemaGenerator.ts Updated common helper function for generating column types.
packages/sync-rules/src/schema-generators/KotlinSchemaGenerator.ts New implementation for Kotlin schema generation.
packages/sync-rules/src/schema-generators/JsLegacySchemaGenerator.ts Updated import paths.
packages/sync-rules/src/schema-generators/DotNetSchemaGenerator.ts New implementation for .Net schema generation with a custom helper function for column types.
packages/sync-rules/src/schema-generators/DartSchemaGenerator.ts Updated to use the common column type helper.
packages/sync-rules/src/index.ts Updated export list to include schema generators under a common module.
.changeset/beige-poems-share.md Changeset describing the addition of new schema generators.
Comments suppressed due to low confidence (1)

packages/sync-rules/src/schema-generators/DotNetSchemaGenerator.ts:56

  • [nitpick] Consider encapsulating the helper function 'cSharpColumnType' as a private method inside the DotNetSchemaGenerator class for consistency with the approach used in other schema generators.
return `{ "${column.name}", ${cSharpColumnType(column)} }`;

@stevensJourney stevensJourney marked this pull request as ready for review April 22, 2025 07:24
@stevensJourney stevensJourney merged commit ac6ae0d into main Apr 24, 2025
22 checks passed
@stevensJourney stevensJourney deleted the kotlinswiftschema branch April 24, 2025 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants