From 7b7469c48da624f373cd0d0ac8924928520327d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helge=20He=C3=9F?= Date: Thu, 12 Oct 2023 19:41:52 +0200 Subject: [PATCH 1/4] Fix Northwind.swift links ... --- README.md | 2 +- Sources/Lighter/Lighter.docc/GettingStarted.md | 2 +- Sources/Lighter/Lighter.docc/Lighter.md | 6 +++--- Sources/Lighter/Lighter.docc/LighterAPI.md | 12 ++++++------ Sources/Lighter/Lighter.docc/Linux.md | 4 ++-- Sources/Lighter/Lighter.docc/Mapping.md | 2 +- Sources/Lighter/Lighter.docc/Northwind.md | 8 ++++---- Sources/Lighter/Lighter.docc/SQLiteAPI.md | 10 +++++----- Tests/NorthwindTests/NorthwindTests.swift | 2 +- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 0b570a6..3c43eae 100644 --- a/README.md +++ b/README.md @@ -265,7 +265,7 @@ needed. The Lighter code generator can also generate API comments for the database types. -Example: [Northwind Database](https://lighter-swift.github.io/NorthwindSQLite.swift/documentation/northwind/employee). +Example: [Northwind Database](https://Northwind-swift.github.io/NorthwindSQLite.swift/documentation/northwind/employee). diff --git a/Sources/Lighter/Lighter.docc/GettingStarted.md b/Sources/Lighter/Lighter.docc/GettingStarted.md index a829d54..8483266 100644 --- a/Sources/Lighter/Lighter.docc/GettingStarted.md +++ b/Sources/Lighter/Lighter.docc/GettingStarted.md @@ -24,7 +24,7 @@ Five quick steps: make sure it is copied into the project (i.e. not a reference to some outside file). Don't have one handy? The - [Northwind](https://github.com/Lighter-swift/NorthwindSQLite.swift) + [Northwind](https://github.com/Northwind-swift/NorthwindSQLite.swift) database is a nice one to play with: [download here](https://github.com/Lighter-swift/NorthwindSQLite.swift/blob/develop/dist/northwind.db). **Make sure it is** selected as **a resource** of the Xcode target. diff --git a/Sources/Lighter/Lighter.docc/Lighter.md b/Sources/Lighter/Lighter.docc/Lighter.md index 3bbd093..7b88d9d 100644 --- a/Sources/Lighter/Lighter.docc/Lighter.md +++ b/Sources/Lighter/Lighter.docc/Lighter.md @@ -58,7 +58,7 @@ let product = try await db.products.find(42) let orders = try await db.orders.fetch(for: product) ``` If desired, it generates beautiful DocC documentation within the generated code -([Example](https://lighter-swift.github.io/NorthwindSQLite.swift/documentation/northwind/employee)). +([Example](https://Northwind-swift.github.io/NorthwindSQLite.swift/documentation/northwind/employee)). ## Lighter Toolkit Components @@ -83,10 +83,10 @@ There are two associated repositories: - [Examples](https://github.com/Lighter-swift/Examples/): Contains examples on how to use the toolset, including a few SwiftUI applications and even a server side API. -- [NorthwindSQLite.swift](https://github.com/Lighter-swift/NorthwindSQLite.swift): +- [NorthwindSQLite.swift](https://github.com/Northwind-swift/NorthwindSQLite.swift): A version of the Microsoft Access 2000 Northwind sample database, re-engineered for SQLite3, and packaged up as a Swift package - ([DocC Documentation](https://lighter-swift.github.io/NorthwindSQLite.swift/documentation/northwind/))! + ([DocC Documentation](https://Northwind-swift.github.io/NorthwindSQLite.swift/documentation/northwind/))! ## Topics diff --git a/Sources/Lighter/Lighter.docc/LighterAPI.md b/Sources/Lighter/Lighter.docc/LighterAPI.md index 1f43613..3cbb077 100644 --- a/Sources/Lighter/Lighter.docc/LighterAPI.md +++ b/Sources/Lighter/Lighter.docc/LighterAPI.md @@ -22,10 +22,10 @@ dependency free code for a database: . The code generators generate one Swift structure representing the Database itself (e.g. -[Northwind](https://lighter-swift.github.io/NorthwindSQLite.swift/documentation/northwind/northwind)) +[Northwind](https://Northwind-swift.github.io/NorthwindSQLite.swift/documentation/northwind/northwind)) and one Swift structure for each SQL table or view (e.g. -[Product](https://lighter-swift.github.io/NorthwindSQLite.swift/documentation/northwind/product)). +[Product](https://Northwind-swift.github.io/NorthwindSQLite.swift/documentation/northwind/product)). If the database is embedded into the app or library (as a resource file), it can be directly used like this: @@ -96,17 +96,17 @@ async let category = database.categories.find(for: product) The code generators generate one Swift structure representing the Database itself (e.g. -[Northwind](https://lighter-swift.github.io/NorthwindSQLite.swift/documentation/northwind/northwind)) +[Northwind](https://Northwind-swift.github.io/NorthwindSQLite.swift/documentation/northwind/northwind)) and one Swift structure for each SQL table or view (e.g. -[Product](https://lighter-swift.github.io/NorthwindSQLite.swift/documentation/northwind/product)). +[Product](https://Northwind-swift.github.io/NorthwindSQLite.swift/documentation/northwind/product)). ### Database Structure The name of the structure is derived from the database file name. E.g. if it is called "northwind.db", the default name mapping produces a structure with the name -"[Northwind](https://lighter-swift.github.io/NorthwindSQLite.swift/documentation/northwind/northwind)". +"[Northwind](https://Northwind-swift.github.io/NorthwindSQLite.swift/documentation/northwind/northwind)". Depending on the , the database structure conforms to e.g.: - ``SQLDatabase``: This handles opening the database etc. @@ -320,7 +320,7 @@ ORDER BY City, CompanyName ``` Northwind comes with a set of example views, e.g. -[CustomerAndSuppliersByCity](https://lighter-swift.github.io/NorthwindSQLite.swift/documentation/northwind/customerandsuppliersbycity). +[CustomerAndSuppliersByCity](https://Northwind-swift.github.io/NorthwindSQLite.swift/documentation/northwind/customerandsuppliersbycity). ## Topics diff --git a/Sources/Lighter/Lighter.docc/Linux.md b/Sources/Lighter/Lighter.docc/Linux.md index f3610cc..903633b 100644 --- a/Sources/Lighter/Lighter.docc/Linux.md +++ b/Sources/Lighter/Lighter.docc/Linux.md @@ -30,7 +30,7 @@ Example server: ```swift #!/usr/bin/swift sh import MacroExpress // @Macro-swift -import Northwind // @Lighter-swift/NorthwindSQLite.swift +import Northwind // @Northwind-swift/NorthwindSQLite.swift let db = Northwind.module! let app = express() @@ -57,7 +57,7 @@ var package = Package( dependencies: [ .package(url: "https://Lighter-swift/Lighter.git", from: "1.0.2"), - .package(url: "https://Lighter-swift/NorthwindSQLite.swift.git", + .package(url: "https://Northwind-swift/NorthwindSQLite.swift.git", from: "1.0.0"), .package(url: "https://github.com/Macro-swift/MacroExpress.git", from: "1.0.2") diff --git a/Sources/Lighter/Lighter.docc/Mapping.md b/Sources/Lighter/Lighter.docc/Mapping.md index 8e98a09..d855327 100644 --- a/Sources/Lighter/Lighter.docc/Mapping.md +++ b/Sources/Lighter/Lighter.docc/Mapping.md @@ -114,7 +114,7 @@ Those are the things required during column mapping both ways. There are various options on where to place more general mapping code. Let's assume the record structure mapped for the Northwind -[Product Category](https://lighter-swift.github.io/NorthwindSQLite.swift/documentation/northwind/category) +[Product Category](https://Northwind-swift.github.io/NorthwindSQLite.swift/documentation/northwind/category) table. It looks like this: ```swift public struct Category : Identifiable, Codable { diff --git a/Sources/Lighter/Lighter.docc/Northwind.md b/Sources/Lighter/Lighter.docc/Northwind.md index b884609..d7de89e 100644 --- a/Sources/Lighter/Lighter.docc/Northwind.md +++ b/Sources/Lighter/Lighter.docc/Northwind.md @@ -7,7 +7,7 @@ Using the Northwind example database. The Northwind database is a common database example that has been ported to SQLite. Lighter provides a Swift version of that in the -[NorthwindSQLite.swift](https://github.com/Lighter-swift/NorthwindSQLite.swift) +[NorthwindSQLite.swift](https://github.com/Northwind-swift/NorthwindSQLite.swift) repository. > Note: The particular SQLite version of the Northwind database is quite @@ -16,11 +16,11 @@ repository. > That actually makes it a good example on how to deal with such databases in > Lighter. -The Swift Northwind API: [Documentation](https://Lighter-swift.github.io/NorthwindSQLite.swift/documentation/northwind/). +The Swift Northwind API: [Documentation](https://Northwind-swift.github.io/NorthwindSQLite.swift/documentation/northwind/). ## Demos -Examples based on the [Northwind](https://Lighter-swift.github.io/NorthwindSQLite.swift/documentation/northwind/) Database: +Examples based on the [Northwind](https://Northwind-swift.github.io/NorthwindSQLite.swift/documentation/northwind/) Database: - [NorthwindWebAPI](https://github.com/Lighter-swift/Examples/tree/develop/Sources/NorthwindWebAPI/) (A server side Swift example @@ -34,7 +34,7 @@ Examples based on the [Northwind](https://Lighter-swift.github.io/NorthwindSQLit ## Getting Started -Add the `https://Lighter-swift.github.io/NorthwindSQLite.swift` as a package +Add the `https://Northwind-swift.github.io/NorthwindSQLite.swift` as a package dependency to a Swift Package Manager package. Then just import `Northwind` and run queries against the database: diff --git a/Sources/Lighter/Lighter.docc/SQLiteAPI.md b/Sources/Lighter/Lighter.docc/SQLiteAPI.md index 1e5e9ad..ce4646f 100644 --- a/Sources/Lighter/Lighter.docc/SQLiteAPI.md +++ b/Sources/Lighter/Lighter.docc/SQLiteAPI.md @@ -250,7 +250,7 @@ ORDER BY City, CompanyName ``` Northwind comes with a set of example views, e.g. -[CustomerAndSuppliersByCity](https://lighter-swift.github.io/NorthwindSQLite.swift/documentation/northwind/customerandsuppliersbycity). +[CustomerAndSuppliersByCity](https://Northwind-swift.github.io/NorthwindSQLite.swift/documentation/northwind/customerandsuppliersbycity). ### Advanced SQLite API @@ -403,11 +403,11 @@ It has a slight overhead over just extracting the values directly and the default values need to be applied). An example just selecting the -[`id`](https://lighter-swift.github.io/NorthwindSQLite.swift/documentation/northwind/product/id-7350h/), +[`id`](https://Northwind-swift.github.io/NorthwindSQLite.swift/documentation/northwind/product/id-7350h/), the -[`name`](https://lighter-swift.github.io/NorthwindSQLite.swift/documentation/northwind/product/productname/) +[`name`](https://Northwind-swift.github.io/NorthwindSQLite.swift/documentation/northwind/product/productname/) and the -[`quantityPerUnit`](https://lighter-swift.github.io/NorthwindSQLite.swift/documentation/northwind/product/quantityperunit/): +[`quantityPerUnit`](https://Northwind-swift.github.io/NorthwindSQLite.swift/documentation/northwind/product/quantityperunit/): ```swift sqlite3_prepare_v2( db, @@ -441,7 +441,7 @@ CREATE TABLE Products ( ); ``` The `product` value would contain `nil` for the -[`categoryId`](https://lighter-swift.github.io/NorthwindSQLite.swift/documentation/northwind/product/categoryid) +[`categoryId`](https://Northwind-swift.github.io/NorthwindSQLite.swift/documentation/northwind/product/categoryid) property (because it is optional) and `0` for the `discontinued` property (because that is the specified table default value). diff --git a/Tests/NorthwindTests/NorthwindTests.swift b/Tests/NorthwindTests/NorthwindTests.swift index 4e596fa..5989afc 100644 --- a/Tests/NorthwindTests/NorthwindTests.swift +++ b/Tests/NorthwindTests/NorthwindTests.swift @@ -11,7 +11,7 @@ import Foundation final class NorthwindTests: XCTestCase { let url = URL(fileURLWithPath: - "/Users/helge/dev/Swift/Lighter/NorthwindSQLite.swift/src/create.sql" + "/Users/helge/dev/Swift/Northwind/NorthwindSQLite.swift/src/create.sql" ) var hasFile: Bool { FileManager.default.isReadableFile(atPath: url.path) From f63a304926cad5598cce1d10b7aae9283acbfa25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helge=20He=C3=9F?= Date: Thu, 12 Oct 2023 19:45:21 +0200 Subject: [PATCH 2/4] Fix Northwind.swift link --- Sources/Lighter/Lighter.docc/Mapping.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Lighter/Lighter.docc/Mapping.md b/Sources/Lighter/Lighter.docc/Mapping.md index d855327..1c36814 100644 --- a/Sources/Lighter/Lighter.docc/Mapping.md +++ b/Sources/Lighter/Lighter.docc/Mapping.md @@ -127,7 +127,7 @@ public struct Category : Identifiable, Codable { ``` It carries an embedded JPEG in the -[picture](https://lighter-swift.github.io/NorthwindSQLite.swift/documentation/northwind/category/picture) +[picture](https://Northwind-swift.github.io/NorthwindSQLite.swift/documentation/northwind/category/picture) column, as a BLOB (i.e. just bytes). It would be nice to have this mapped to a `UIImage` for display. And maybe make the `categoryName` available as just `name`, and remove the From dee8e47b90fa766758f5c30b7750de3e68e14389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helge=20He=C3=9F?= Date: Sat, 3 Feb 2024 14:00:40 +0100 Subject: [PATCH 3/4] GHA: Test against Swift 5.9.2 release ... --- .github/workflows/swift.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index 4536514..d274502 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -11,10 +11,8 @@ jobs: fail-fast: false matrix: image: - - swift:5.5.1-xenial - - swift:5.6.2-focal - swift:5.8.1-jammy - - swiftlang/swift:nightly-5.9-focal + - swift:5.9.2-focal container: ${{ matrix.image }} steps: - name: Install SQLite From 15ee334e5eac18f619734144beeffe750072dc94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helge=20He=C3=9F?= Date: Tue, 19 Mar 2024 14:30:01 +0100 Subject: [PATCH 4/4] Add Swift 5.10 manifest ... --- .github/workflows/swift.yml | 2 +- Package@swift-5.10.swift | 134 ++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 Package@swift-5.10.swift diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index d274502..781c035 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -11,8 +11,8 @@ jobs: fail-fast: false matrix: image: - - swift:5.8.1-jammy - swift:5.9.2-focal + - swift:5.10-jammy container: ${{ matrix.image }} steps: - name: Install SQLite diff --git a/Package@swift-5.10.swift b/Package@swift-5.10.swift new file mode 100644 index 0000000..4cc868d --- /dev/null +++ b/Package@swift-5.10.swift @@ -0,0 +1,134 @@ +// swift-tools-version:5.10 + +import PackageDescription + +var package = Package( + name: "Lighter", + + platforms: [ + .macOS(.v10_15), .iOS(.v13), .visionOS(.v1), .watchOS(.v7), .tvOS(.v12) + ], + + products: [ + .library(name: "Lighter", targets: [ "Lighter" ]), + .library(name: "SQLite3Schema", targets: [ "SQLite3Schema" ]), + + .executable(name: "sqlite2swift", targets: [ "sqlite2swift" ]), + + .plugin(name: "Enlighter", targets: [ "Enlighter" ]), + .plugin(name: "Generate Code for SQLite", + targets: [ "Generate Code for SQLite" ]) + ], + + targets: [ + // A small library used to fetch schema information from SQLite3 databases. + .target(name: "SQLite3Schema", exclude: [ "README.md" ]), + + // Lighter is a shared lib providing common protocols used by Enlighter + // generated models and such. + // Note that Lighter isn't that useful w/o code generation (i.e. as a + // standalone lib). + .target(name: "Lighter"), + + + // MARK: - Plugin Support + + // The CodeGenAST is a small and hacky helper lib that can format/render + // Swift source code. + .target(name : "LighterCodeGenAST", + path : "Plugins/Libraries/LighterCodeGenAST", + exclude : [ "README.md" ]), + + // This library contains all the code generation, to be used by different + // clients. + .target(name : "LighterGeneration", + dependencies : [ "LighterCodeGenAST", "SQLite3Schema" ], + path : "Plugins/Libraries/LighterGeneration", + exclude : [ "README.md", "LighterConfiguration/README.md" ]), + + + // MARK: - Tests + + .testTarget(name: "CodeGenASTTests", dependencies: [ "LighterCodeGenAST" ]), + .testTarget(name: "EntityGenTests", dependencies: [ "LighterGeneration" ]), + .testTarget(name: "LighterOperationGenTests", + dependencies: [ "LighterGeneration" ]), + .testTarget(name: "ContactsDatabaseTests", dependencies: [ "Lighter" ], + exclude: [ "contacts-create.sql" ]), + + + // MARK: - Plugins and supporting Tools + + .executableTarget(name : "sqlite2swift", + dependencies : [ "LighterGeneration" ], + path : "Plugins/Tools/sqlite2swift", + exclude : [ "README.md" ]), + + .plugin(name: "Enlighter", capability: .buildTool(), + dependencies: [ "sqlite2swift" ]), + + .plugin( + name: "Generate Code for SQLite", + capability: .command( + intent: .custom( + verb: "sqlite2swift", + description: + "Generate Swift code for SQLite DBs into the Sources directory." + ), + permissions: [ + .writeToPackageDirectory(reason: + "The plugin needs access to generate the source file.") + ] + ), + dependencies: [ "sqlite2swift" ], + path: "Plugins/GenerateCodeForSQLite" + ), + + + // MARK: - Internal Plugin for Generating Variadics + + .executableTarget(name : "GenerateInternalVariadics", + dependencies : [ "LighterCodeGenAST", + "LighterGeneration" ], + path : "Plugins/Tools/GenerateInternalVariadics", + exclude : [ "README.md" ]), + .plugin( + name: "Generate Variadics into Lighter (Internal)", + capability: .command( + intent: .custom( + verb: "write-internal-variadics", + description: + "Generate the variadic queries into the Sources/Lighter directory." + ), + permissions: [ + .writeToPackageDirectory( + reason: "The plugin needs access to generate the source file.") + ] + ), + dependencies: [ "GenerateInternalVariadics" ], + path: "Plugins/WriteInternalVariadics" + ), + + + // MARK: - Environment specific tests + .testTarget(name: "FiveThirtyEightTests", + dependencies: [ "LighterGeneration" ]), + .testTarget(name: "NorthwindTests", + dependencies: [ "LighterGeneration" ]) + ] +) + +#if !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS)) +package.products += [ .library(name: "SQLite3", targets: [ "SQLite3" ]) ] +package.targets += [ + .systemLibrary(name: "SQLite3", + path: "Sources/SQLite3-Linux", + providers: [ .apt(["libsqlite3-dev"]) ]) +] +package.targets + .first(where: { $0.name == "SQLite3Schema" })? + .dependencies.append("SQLite3") +package.targets + .first(where: { $0.name == "Lighter" })? + .dependencies.append("SQLite3") +#endif // not-Darwin