Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
helje5 committed Mar 19, 2024
2 parents c016296 + 15ee334 commit 13d1016
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 29 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- swift:5.10-jammy
container: ${{ matrix.image }}
steps:
- name: Install SQLite
Expand Down
134 changes: 134 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

<img src="https://zeezide.com/img/lighter/docc-record-type.png" />
<img src="https://zeezide.com/img/lighter/docc-target.png" />
Expand Down
2 changes: 1 addition & 1 deletion Sources/Lighter/Lighter.docc/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions Sources/Lighter/Lighter.docc/Lighter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions Sources/Lighter/Lighter.docc/LighterAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ dependency free code for a database: <doc:SQLiteAPI>.

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:
Expand Down Expand Up @@ -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 <doc:Configuration>, the database structure conforms to e.g.:
- ``SQLDatabase``: This handles opening the database etc.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Sources/Lighter/Lighter.docc/Linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions Sources/Lighter/Lighter.docc/Mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Sources/Lighter/Lighter.docc/Northwind.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions Sources/Lighter/Lighter.docc/SQLiteAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion Tests/NorthwindTests/NorthwindTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 13d1016

Please sign in to comment.