Skip to content

Commit

Permalink
Support the models-with-spaces FluentKit work (#48)
Browse files Browse the repository at this point in the history
* Support the models-with-spaces FluentKit work

* Require correct version of FluentKit with models-with-spaces support

* Minimal CI update
  • Loading branch information
gwynne authored May 11, 2022
1 parent 7fa5280 commit f979b1e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 25 deletions.
29 changes: 5 additions & 24 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,10 @@ jobs:
dbimage:
- mongo
runner:
# 5.2 Stable
- swift:5.2-xenial
- swift:5.2-bionic
# 5.2 Unstable
- swiftlang/swift:nightly-5.2-xenial
- swiftlang/swift:nightly-5.2-bionic
# 5.3 Unstable
- swiftlang/swift:nightly-5.3-xenial
- swiftlang/swift:nightly-5.3-bionic
# Master Unsable
#- swiftlang/swift:nightly-master-xenial
#- swiftlang/swift:nightly-master-bionic
#- swiftlang/swift:nightly-master-focal
#- swiftlang/swift:nightly-master-centos8
#- swiftlang/swift:nightly-master-amazonlinux2
#include:
# - runner: swiftlang/swift:nightly-master-centos8
# installcmd: dnf install -y zlib-devel
# - runner: swiftlang/swift:nightly-master-amazonlinux2
# installcmd: yum install -y zlib-devel
#exclude:
# - runner: swiftlang/swift:nightly-master-amazonlinux2
# dbimage: mysql:8.0
- swift:5.2-focal
- swift:5.5-focal
- swift:5.6-focal
- swiftlang/swift:nightly-main-focal
container: ${{ matrix.runner }}
runs-on: ubuntu-latest
services:
Expand All @@ -41,7 +22,7 @@ jobs:
image: ${{ matrix.dbimage }}
steps:
- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Run tests with Thread Sanitizer
run: swift test --enable-test-discovery --sanitize=thread
env:
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let package = Package(
.library(name: "FluentMongoDriver", targets: ["FluentMongoDriver"]),
],
dependencies: [
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.0.0"),
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.24.0"),
.package(url: "https://github.com/OpenKitten/MongoKitten.git", from: "6.6.4"),
],
targets: [
Expand Down
5 changes: 5 additions & 0 deletions Sources/FluentMongoDriver/FieldKey+Mongo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ extension DatabaseQuery.Field {
switch self {
case .path(let path, _):
return path.map { $0.makeMongoKey() }.joined(separator: ".")
case .extendedPath(let path, _, _):
return path.map { $0.makeMongoKey() }.joined(separator: ".")
case .custom:
throw FluentMongoError.unsupportedField
}
Expand All @@ -29,6 +31,9 @@ extension DatabaseQuery.Field {
switch self {
case .path(let path, let schema):
return "\(schema).\(path.map { $0.makeMongoKey() }.joined(separator: "."))"
case .extendedPath(let path, let schema, let space):
guard space == nil else { fatalError("unsupported") }
return "\(schema).\(path.map { $0.makeMongoKey() }.joined(separator: "."))"
case .custom:
throw FluentMongoError.unsupportedField
}
Expand Down
24 changes: 24 additions & 0 deletions Sources/FluentMongoDriver/MongoDB+Join.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,30 @@ extension DatabaseQuery {
case .custom:
fatalError()
}
case .extendedJoin(let schema, let space, let alias, let method, let foreignKey, let localKey):
guard space == nil else { fatalError("unsupported") }
switch method {
case .left:
stages.append(lookup(
from: schema,
localField: try localKey.makeProjectedMongoPath(),
foreignField: try foreignKey.makeMongoPath(),
as: alias ?? schema
))
case .inner:
stages.append(lookup(
from: schema,
localField: try localKey.makeProjectedMongoPath(),
foreignField: try foreignKey.makeMongoPath(),
as: alias ?? schema
))

stages.append(AggregateBuilderStage(document: [
"$unwind": "$\(alias ?? schema)"
]))
case .custom:
fatalError()
}
case .custom:
throw FluentMongoError.unsupportedJoin
}
Expand Down

0 comments on commit f979b1e

Please sign in to comment.