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 7c266b5

Browse files
authored
Clean up row decoding (#193)
* Based on the work in PostgresKit to improve row decoding performance, clean up the corresponding API at this layer to call through instead of half-reimplementing (incorrectly) the same logic. * CI cleanup - update Swift versions, use generic names, don't over-test, use new checkout action
1 parent 33d502d commit 7c266b5

File tree

2 files changed

+42
-49
lines changed

2 files changed

+42
-49
lines changed

‎.github/workflows/test.yml

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ jobs:
99
dbimage:
1010
- postgres:14
1111
- postgres:13
12-
- postgres:12
1312
- postgres:11
1413
dbauth:
1514
- trust
@@ -18,69 +17,72 @@ jobs:
1817
swiftver:
1918
- swift:5.2
2019
- swift:5.5
20+
- swift:5.6
2121
- swiftlang/swift:nightly-main
2222
swiftos:
2323
- focal
24+
include:
25+
- swiftver: swift:5.2
26+
test_flag: --enable-test-discovery
2427
container: ${{ format('{0}-{1}', matrix.swiftver, matrix.swiftos) }}
2528
runs-on: ubuntu-latest
2629
env:
2730
LOG_LEVEL: debug
28-
POSTGRES_DB_A: 'vapor_database'
29-
POSTGRES_DB_B: 'vapor_database'
30-
POSTGRES_USER_A: 'vapor_username'
31-
POSTGRES_USER_B: 'vapor_username'
32-
POSTGRES_PASSWORD_A: 'vapor_password'
33-
POSTGRES_PASSWORD_B: 'vapor_password'
31+
POSTGRES_DB_A: 'test_database'
32+
POSTGRES_DB_B: 'test_database'
33+
POSTGRES_USER_A: 'test_username'
34+
POSTGRES_USER_B: 'test_username'
35+
POSTGRES_PASSWORD_A: 'test_password'
36+
POSTGRES_PASSWORD_B: 'test_password'
3437
POSTGRES_HOSTNAME_A: 'psql-a'
3538
POSTGRES_HOSTNAME_B: 'psql-b'
3639
POSTGRES_HOST_AUTH_METHOD: ${{ matrix.dbauth }}
3740
services:
3841
psql-a:
3942
image: ${{ matrix.dbimage }}
4043
env:
41-
POSTGRES_USER: 'vapor_username'
42-
POSTGRES_DB: 'vapor_database'
43-
POSTGRES_PASSWORD: 'vapor_password'
44+
POSTGRES_USER: 'test_username'
45+
POSTGRES_DB: 'test_database'
46+
POSTGRES_PASSWORD: 'test_password'
4447
POSTGRES_HOST_AUTH_METHOD: ${{ matrix.dbauth }}
4548
POSTGRES_INITDB_ARGS: --auth-host=${{ matrix.dbauth }}
4649
psql-b:
4750
image: ${{ matrix.dbimage }}
4851
env:
49-
POSTGRES_USER: 'vapor_username'
50-
POSTGRES_DB: 'vapor_database'
51-
POSTGRES_PASSWORD: 'vapor_password'
52+
POSTGRES_USER: 'test_username'
53+
POSTGRES_DB: 'test_database'
54+
POSTGRES_PASSWORD: 'test_password'
5255
POSTGRES_HOST_AUTH_METHOD: ${{ matrix.dbauth }}
5356
POSTGRES_INITDB_ARGS: --auth-host=${{ matrix.dbauth }}
5457
steps:
5558
- name: Check out package
56-
uses: actions/checkout@v2
59+
uses: actions/checkout@v3
5760
- name: Run all tests with Thread Sanitizer
58-
run: swift test --enable-test-discovery --sanitize=thread
61+
run: swift test ${{ matrix.test_flag }} --sanitize=thread
5962

6063
macos-all:
6164
strategy:
6265
fail-fast: false
6366
matrix:
67+
# Only test latest version and one auth method on macOS
6468
dbimage:
65-
# Only test the lastest version on macOS, let Linux do the rest
6669
- postgresql@14
6770
dbauth:
68-
# Only test one auth method on macOS, Linux tests will cover the others
6971
- scram-sha-256
7072
xcode:
7173
- latest-stable
72-
- latest
74+
#- latest
7375
runs-on: macos-11
7476
env:
7577
LOG_LEVEL: debug
7678
POSTGRES_HOSTNAME_A: 127.0.0.1
7779
POSTGRES_HOSTNAME_B: 127.0.0.1
78-
POSTGRES_USER_A: 'vapor_username'
79-
POSTGRES_USER_B: 'vapor_username'
80-
POSTGRES_PASSWORD_A: 'vapor_password'
81-
POSTGRES_PASSWORD_B: 'vapor_password'
82-
POSTGRES_DB_A: 'vapor_database_a'
83-
POSTGRES_DB_B: 'vapor_database_b'
80+
POSTGRES_USER_A: 'test_username'
81+
POSTGRES_USER_B: 'test_username'
82+
POSTGRES_PASSWORD_A: 'test_password'
83+
POSTGRES_PASSWORD_B: 'test_password'
84+
POSTGRES_DB_A: 'test_database_a'
85+
POSTGRES_DB_B: 'test_database_b'
8486
steps:
8587
- name: Select latest available Xcode
8688
uses: maxim-lobanov/setup-xcode@v1
@@ -100,7 +102,7 @@ jobs:
100102
psql $POSTGRES_DB_B <<<"ALTER SCHEMA public OWNER TO $POSTGRES_USER_B;"
101103
timeout-minutes: 2
102104
- name: Checkout code
103-
uses: actions/checkout@v2
105+
uses: actions/checkout@v3
104106
- name: Run all tests with Thread Sanitizer
105107
run: |
106108
swift test --sanitize=thread -Xlinker -rpath \

‎Sources/FluentPostgresDriver/PostgresRow+Database.swift

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import class Foundation.JSONDecoder
2-
31
extension PostgresRow {
42
internal func databaseOutput(using decoder: PostgresDataDecoder) -> DatabaseOutput {
53
_PostgresDatabaseOutput(
@@ -10,40 +8,33 @@ extension PostgresRow {
108
}
119

1210
private struct _PostgresDatabaseOutput: DatabaseOutput {
13-
let row: PostgresRow
14-
let decoder: PostgresDataDecoder
15-
11+
let row: SQLRow
12+
13+
init(row: PostgresRow, decoder: PostgresDataDecoder) {
14+
self.row = row.sql(decoder: decoder)
15+
}
16+
1617
var description: String {
17-
self.row.description
18+
String(describing:self.row)
1819
}
1920

20-
func decodeNil(_ key: FieldKey) throws -> Bool {
21-
if let data = self.row.column(self.columnName(key)) {
22-
return data.type == .null
23-
} else {
24-
return true
25-
}
21+
func schema(_ schema: String) -> DatabaseOutput {
22+
_SchemaDatabaseOutput(output: self, schema: schema)
2623
}
2724

2825
func contains(_ key: FieldKey) -> Bool {
29-
self.row.column(self.columnName(key))!=nil
26+
self.row.contains(column:self.columnName(key))
3027
}
3128

32-
func schema(_ schema: String) -> DatabaseOutput {
33-
_SchemaDatabaseOutput(
34-
output: self,
35-
schema: schema
36-
)
29+
func decodeNil(_ key: FieldKey) throws -> Bool {
30+
try self.row.decodeNil(column: self.columnName(key))
3731
}
3832

39-
func decode<T>(_ key: FieldKey, as type: T.Type) throws -> T
40-
where T: Decodable
41-
{
42-
try self.row.sql(decoder: self.decoder)
43-
.decode(column: self.columnName(key), as: T.self)
33+
func decode<T>(_ key: FieldKey, as type: T.Type) throws -> T where T: Decodable {
34+
try self.row.decode(column: self.columnName(key), as: T.self)
4435
}
4536

46-
func columnName(_ key: FieldKey) -> String {
37+
privatefunc columnName(_ key: FieldKey) -> String {
4738
switch key {
4839
case .id:
4940
return "id"

0 commit comments

Comments
(0)

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