Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 27 additions & 25 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ jobs:
dbimage:
- postgres:14
- postgres:13
- postgres:12
- postgres:11
dbauth:
- trust
Expand All @@ -18,69 +17,72 @@ jobs:
swiftver:
- swift:5.2
- swift:5.5
- swift:5.6
- swiftlang/swift:nightly-main
swiftos:
- focal
include:
- swiftver: swift:5.2
test_flag: --enable-test-discovery
container: ${{ format('{0}-{1}', matrix.swiftver, matrix.swiftos) }}
runs-on: ubuntu-latest
env:
LOG_LEVEL: debug
POSTGRES_DB_A: 'vapor_database'
POSTGRES_DB_B: 'vapor_database'
POSTGRES_USER_A: 'vapor_username'
POSTGRES_USER_B: 'vapor_username'
POSTGRES_PASSWORD_A: 'vapor_password'
POSTGRES_PASSWORD_B: 'vapor_password'
POSTGRES_DB_A: 'test_database'
POSTGRES_DB_B: 'test_database'
POSTGRES_USER_A: 'test_username'
POSTGRES_USER_B: 'test_username'
POSTGRES_PASSWORD_A: 'test_password'
POSTGRES_PASSWORD_B: 'test_password'
POSTGRES_HOSTNAME_A: 'psql-a'
POSTGRES_HOSTNAME_B: 'psql-b'
POSTGRES_HOST_AUTH_METHOD: ${{ matrix.dbauth }}
services:
psql-a:
image: ${{ matrix.dbimage }}
env:
POSTGRES_USER: 'vapor_username'
POSTGRES_DB: 'vapor_database'
POSTGRES_PASSWORD: 'vapor_password'
POSTGRES_USER: 'test_username'
POSTGRES_DB: 'test_database'
POSTGRES_PASSWORD: 'test_password'
POSTGRES_HOST_AUTH_METHOD: ${{ matrix.dbauth }}
POSTGRES_INITDB_ARGS: --auth-host=${{ matrix.dbauth }}
psql-b:
image: ${{ matrix.dbimage }}
env:
POSTGRES_USER: 'vapor_username'
POSTGRES_DB: 'vapor_database'
POSTGRES_PASSWORD: 'vapor_password'
POSTGRES_USER: 'test_username'
POSTGRES_DB: 'test_database'
POSTGRES_PASSWORD: 'test_password'
POSTGRES_HOST_AUTH_METHOD: ${{ matrix.dbauth }}
POSTGRES_INITDB_ARGS: --auth-host=${{ matrix.dbauth }}
steps:
- name: Check out package
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Run all tests with Thread Sanitizer
run: swift test --enable-test-discovery --sanitize=thread
run: swift test ${{ matrix.test_flag }} --sanitize=thread

macos-all:
strategy:
fail-fast: false
matrix:
# Only test latest version and one auth method on macOS
dbimage:
# Only test the lastest version on macOS, let Linux do the rest
- postgresql@14
dbauth:
# Only test one auth method on macOS, Linux tests will cover the others
- scram-sha-256
xcode:
- latest-stable
- latest
#- latest
runs-on: macos-11
env:
LOG_LEVEL: debug
POSTGRES_HOSTNAME_A: 127.0.0.1
POSTGRES_HOSTNAME_B: 127.0.0.1
POSTGRES_USER_A: 'vapor_username'
POSTGRES_USER_B: 'vapor_username'
POSTGRES_PASSWORD_A: 'vapor_password'
POSTGRES_PASSWORD_B: 'vapor_password'
POSTGRES_DB_A: 'vapor_database_a'
POSTGRES_DB_B: 'vapor_database_b'
POSTGRES_USER_A: 'test_username'
POSTGRES_USER_B: 'test_username'
POSTGRES_PASSWORD_A: 'test_password'
POSTGRES_PASSWORD_B: 'test_password'
POSTGRES_DB_A: 'test_database_a'
POSTGRES_DB_B: 'test_database_b'
steps:
- name: Select latest available Xcode
uses: maxim-lobanov/setup-xcode@v1
Expand All @@ -100,7 +102,7 @@ jobs:
psql $POSTGRES_DB_B <<<"ALTER SCHEMA public OWNER TO $POSTGRES_USER_B;"
timeout-minutes: 2
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Run all tests with Thread Sanitizer
run: |
swift test --sanitize=thread -Xlinker -rpath \
Expand Down
39 changes: 15 additions & 24 deletions Sources/FluentPostgresDriver/PostgresRow+Database.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import class Foundation.JSONDecoder

extension PostgresRow {
internal func databaseOutput(using decoder: PostgresDataDecoder) -> DatabaseOutput {
_PostgresDatabaseOutput(
Expand All @@ -10,40 +8,33 @@ extension PostgresRow {
}

private struct _PostgresDatabaseOutput: DatabaseOutput {
let row: PostgresRow
let decoder: PostgresDataDecoder

let row: SQLRow

init(row: PostgresRow, decoder: PostgresDataDecoder) {
self.row = row.sql(decoder: decoder)
}

var description: String {
self.row.description
String(describing: self.row)
}

func decodeNil(_ key: FieldKey) throws -> Bool {
if let data = self.row.column(self.columnName(key)) {
return data.type == .null
} else {
return true
}
func schema(_ schema: String) -> DatabaseOutput {
_SchemaDatabaseOutput(output: self, schema: schema)
}

func contains(_ key: FieldKey) -> Bool {
self.row.column(self.columnName(key)) != nil
self.row.contains(column: self.columnName(key))
}

func schema(_ schema: String) -> DatabaseOutput {
_SchemaDatabaseOutput(
output: self,
schema: schema
)
func decodeNil(_ key: FieldKey) throws -> Bool {
try self.row.decodeNil(column: self.columnName(key))
}

func decode<T>(_ key: FieldKey, as type: T.Type) throws -> T
where T: Decodable
{
try self.row.sql(decoder: self.decoder)
.decode(column: self.columnName(key), as: T.self)
func decode<T>(_ key: FieldKey, as type: T.Type) throws -> T where T: Decodable {
try self.row.decode(column: self.columnName(key), as: T.self)
}

func columnName(_ key: FieldKey) -> String {
private func columnName(_ key: FieldKey) -> String {
switch key {
case .id:
return "id"
Expand Down