Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2e76609

Browse files
Support .dictionary(of:) data type (#156)
* support dict data type * update * ci
1 parent a4abae7 commit 2e76609

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
lines changed

‎.github/workflows/test.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
1-
name: Test Matrix
2-
1+
name: test
32
on:
43
pull_request:
54
push:
65
branches:
76
- master
8-
9-
defaults:
10-
run:
11-
shell: bash
12-
137
jobs:
14-
15-
Linux:
8+
linux:
169
runs-on: ubuntu-latest
1710
strategy:
1811
fail-fast: false

‎Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let package = Package(
1010
.library(name: "FluentPostgresDriver", targets: ["FluentPostgresDriver"]),
1111
],
1212
dependencies: [
13-
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.0.0-rc.2"),
13+
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.0.0-rc.2.7"),
1414
.package(url: "https://github.com/vapor/postgres-kit.git", from: "2.0.0"),
1515
],
1616
targets: [

‎Sources/FluentPostgresDriver/PostgresConverterDelegate.swift

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,47 @@ import FluentSQL
33
struct PostgresConverterDelegate: SQLConverterDelegate {
44
func customDataType(_ dataType: DatabaseSchema.DataType) -> SQLExpression? {
55
switch dataType {
6-
case .uint8:
7-
return SQLRaw(#""char""#)
86
case .uuid:
97
return SQLRaw("UUID")
108
case .bool:
119
return SQLRaw("BOOL")
1210
case .data:
1311
return SQLRaw("BYTEA")
12+
case .date:
13+
return SQLRaw("DATE")
1414
case .datetime:
1515
return SQLRaw("TIMESTAMPTZ")
1616
case .double:
1717
return SQLRaw("DOUBLE PRECISION")
18-
case .json:
18+
case .dictionary:
1919
return SQLRaw("JSONB")
20+
case .array(of: let type):
21+
if let type = type, let dataType = self.customDataType(type) {
22+
return SQLArrayDataType(dataType: dataType)
23+
} else {
24+
return SQLRaw("JSONB")
25+
}
2026
case .enum(let value):
2127
return SQLIdentifier(value.name)
22-
default:
28+
case .int8, .uint8:
29+
return SQLRaw(#""char""#)
30+
case .int16, .uint16:
31+
return SQLRaw("SMALLINT")
32+
case .int32, .uint32:
33+
return SQLRaw("INT")
34+
case .int64, .uint64:
35+
return SQLRaw("BIGINT")
36+
case .string:
37+
return SQLRaw("TEXT")
38+
case .time:
39+
return SQLRaw("TIME")
40+
case .float:
41+
return SQLRaw("FLOAT")
42+
case .custom:
2343
return nil
2444
}
2545
}
2646

27-
2847
func nestedFieldExpression(_ column: String, _ path: [String]) -> SQLExpression {
2948
switch path.count {
3049
case 1:
@@ -37,3 +56,11 @@ struct PostgresConverterDelegate: SQLConverterDelegate {
3756
}
3857
}
3958
}
59+
60+
private struct SQLArrayDataType: SQLExpression {
61+
let dataType: SQLExpression
62+
func serialize(to serializer: inout SQLSerializer) {
63+
self.dataType.serialize(to: &serializer)
64+
serializer.write("[]")
65+
}
66+
}

‎Tests/FluentPostgresDriverTests/FluentPostgresDriverTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import XCTest
55

66
final class FluentPostgresDriverTests: XCTestCase {
77
func testAll() throws { try self.benchmarker.testAll() }
8+
9+
#if Xcode
810
func testAggregate() throws { try self.benchmarker.testAggregate() }
911
func testArray() throws { try self.benchmarker.testArray() }
1012
func testBatch() throws { try self.benchmarker.testBatch() }
@@ -34,6 +36,7 @@ final class FluentPostgresDriverTests: XCTestCase {
3436
func testTimestamp() throws { try self.benchmarker.testTimestamp() }
3537
func testTransaction() throws { try self.benchmarker.testTransaction() }
3638
func testUnique() throws { try self.benchmarker.testUnique() }
39+
#endif
3740

3841
func testDatabaseError() throws {
3942
let sql = (self.db as! SQLDatabase)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /