Lighter-swift / Lighter

Swift APIs for SQLite: Type-safe down to the schema. Very, very, fast. Dependency free.
https://lighter-swift.github.io/documentation/lighter/
MIT License
427 stars 11 forks source link

Codegen issue with multi-line create table statements #23

Closed finestructure closed 1 year ago

finestructure commented 1 year ago

I ran sqlite2swift against the chinook db with Lighter 1.0.26 and Swift 5.9 (Xcode 15.0) and it produced the following Swift code:

    /// The SQL used to create the `albums` table.
    public static let create = #"CREATE TABLE "albums"
(
    [AlbumId] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    [Title] NVARCHAR(160)  NOT NULL,
    [ArtistId] INTEGER  NOT NULL,
    FOREIGN KEY ([ArtistId]) REFERENCES "artists" ([ArtistId]) 
        ON DELETE NO ACTION ON UPDATE NO ACTION
);"#

Changing it to

    /// The SQL used to create the `albums` table.
    public static let create = #"""
        CREATE TABLE "albums"
        (
            [AlbumId] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
            [Title] NVARCHAR(160)  NOT NULL,
            [ArtistId] INTEGER  NOT NULL,
            FOREIGN KEY ([ArtistId]) REFERENCES "artists" ([ArtistId])
                ON DELETE NO ACTION ON UPDATE NO ACTION
        );
        """#

for all the tables gets it to compile.

finestructure commented 1 year ago

The config used was the default config:

❯ swift run sqlite2swift Lighter.json Foo ~/Downloads/chinook.db ~/Downloads/Chinook.swift
Building for debugging...
[80/80] Linking sqlite2swift
Build complete! (3.93s)
❯ cat Lighter.json
{
  "__doc__": "Configuration used for the manual, builtin codegen.",

  "databaseExtensions" : [ "sqlite3", "db", "sqlite" ],
  "sqlExtensions"      : [ "sql" ],

  "CodeStyle": {
    "functionCommentStyle" : "**",
    "indent"               : "  ",
    "lineLength"           : 80
  },

  "EmbeddedLighter": {
    "selects": {
      "syncYield"  : "none",
      "syncArray"  : { "columns": 6, "sorts": 2 },
      "asyncArray" : { "columns": 6, "sorts": 2 }
    },
    "updates": {
      "keyBased"       : 6,
      "predicateBased" : 6
    },
    "inserts": 6
  }
}
helje5 commented 1 year ago

Hm, looks like newline detection stopped working. Maybe the DB has CRs only? Will check.

helje5 commented 1 year ago

That's a nice one! Unicode compose issue for \r\n:

          if value.contains("\n") { // meh

"\n" doesn't match.

helje5 commented 1 year ago

Fixed