Skip to content

Structured Queries macro @Table not compatible with default settings of MutablePersistableRecord table naming #58

@whoyawn

Description

@whoyawn

Description

I followed the migration docs and it had no mention of removal of MutablePersistableRecord and FetchableRecord, so when I called inserted to seed my database, I got a crash of
error: SQLite error 1: no such table: {SINGULAR_SPELLED_NAME_OF_TABLE}

Checklist

  • I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • I have determined whether this bug is also reproducible in a vanilla GRDB project.
  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

The workaround is either switching the table name via @Table("syncUp") or declaring static var databaseTableName = "syncUps"

I would like to be able to use the default @Table macro without any other changes to the naming of the table. The cleanup of FetchableRecord and MutablePersistableRecord and the use of the new seeding function is also not documented, in the migration guide, I would like to see all the new APIs that should be used with 0.2.2 moving from 0.1.0

Actual behavior

Here is it demonstrated in the example project:

Add this back under the @Table struct SyncUp { ... }

extension SyncUp: Codable, MutablePersistableRecord {
    
    mutating func didInsert(_ inserted: InsertionSuccess) {
        id = Int(inserted.rowID)
     }
}

extension Theme: Codable {}

and where seedSampleData() is defined, add this line

      try! SyncUp(id: 4, seconds: 60, theme: .appOrange, title: "Design").inserted(self)

Then run the project, and we'll see:

SyncUps/Schema.swift:171: Fatal error: 'try!' expression unexpectedly raised an error: SQLite error 1: no such table: syncUp

Reproducing project

mutablePersistableRecordBug.patch

apply this patch to the example project

SharingGRDB version information

0.2.2

Sharing version information

2.4.0

GRDB version information

7.4.1

Destination operating system

iOS 18

Xcode version information

No response

Swift Compiler version information

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions