Skip to content

Commit

Permalink
Release Candidate 1 (#140)
Browse files Browse the repository at this point in the history
* rc 1

* update ci
  • Loading branch information
tanner0101 authored Feb 28, 2020
1 parent 4265268 commit 36ab616
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 108 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: test
on:
- pull_request
jobs:
xenial:
fluent-postgres-driver_xenial:
container:
image: vapor/swift:5.2-xenial
services:
Expand All @@ -20,7 +20,7 @@ jobs:
- run: swift test --enable-test-discovery --sanitize=thread
env:
POSTGRES_HOSTNAME: psql
bionic:
fluent-postgres-driver_bionic:
container:
image: vapor/swift:5.2-bionic
services:
Expand Down
18 changes: 9 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
// swift-tools-version:5.1
// swift-tools-version:5.2
import PackageDescription

let package = Package(
name: "fluent-postgres-driver",
platforms: [
.macOS(.v10_14)
.macOS(.v10_15)
],
products: [
.library(name: "FluentPostgresDriver", targets: ["FluentPostgresDriver"]),
],
dependencies: [
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.0.0-beta.5"),
.package(url: "https://github.com/vapor/postgres-kit.git", from: "2.0.0-beta.2"),
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.0.0-rc.1"),
.package(url: "https://github.com/vapor/postgres-kit.git", from: "2.0.0-rc.1"),
],
targets: [
.target(name: "FluentPostgresDriver", dependencies: [
"FluentKit",
"FluentSQL",
"PostgresKit",
.product(name: "FluentKit", package: "fluent-kit"),
.product(name: "FluentSQL", package: "fluent-kit"),
.product(name: "PostgresKit", package: "postgres-kit"),
]),
.testTarget(name: "FluentPostgresDriverTests", dependencies: [
"FluentBenchmark",
"FluentPostgresDriver",
.product(name: "FluentBenchmark", package: "fluent-kit"),
.target(name: "FluentPostgresDriver"),
]),
]
)
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
<p align="center">
<img src="https://user-images.githubusercontent.com/1342803/59065097-ec656880-8879-11e9-9e80-2e393dc313c1.png" alt="FluentPostgresDriver">
<img
src="https://user-images.githubusercontent.com/1342803/59065097-ec656880-8879-11e9-9e80-2e393dc313c1.png"
height="64"
alt="FluentPostgresDriver"
>
<br>
<br>
<a href="https://api.vapor.codes/fluent-postgres-driver/master/FluentPostgresDriver/index.html">
<img src="http://img.shields.io/badge/api-docs-2196f3.svg" alt="Documentation">
<a href="https://docs.vapor.codes/4.0/">
<img src="http://img.shields.io/badge/read_the-docs-2196f3.svg" alt="Documentation">
</a>
<a href="https://discord.gg/vapor">
<img src="https://img.shields.io/discord/431917998102675485.svg" alt="Team Chat">
</a>
<a href="LICENSE">
<img src="http://img.shields.io/badge/license-MIT-brightgreen.svg" alt="MIT License">
</a>
<a href="https://circleci.com/gh/vapor/fluent-postgres-driver">
<img src="https://circleci.com/gh/vapor/fluent-postgres-driver.svg?style=shield" alt="Continuous Integration">
<a href="https://github.com/vapor/fluent-postgres-driver/actions">
<img src="https://github.com/vapor/fluent-postgres-driver/workflows/test/badge.svg" alt="Continuous Integration">
</a>
<a href="https://swift.org">
<img src="http://img.shields.io/badge/swift-5.1-brightgreen.svg" alt="Swift 5.1">
<img src="http://img.shields.io/badge/swift-5.2-brightgreen.svg" alt="Swift 5.2">
</a>
</p>
67 changes: 67 additions & 0 deletions Sources/FluentPostgresDriver/FluentPostgresConfiguration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
extension DatabaseConfigurationFactory {
public static func postgres(
url: URL,
maxConnectionsPerEventLoop: Int = 1
) throws -> DatabaseConfigurationFactory {
guard let configuration = PostgresConfiguration(url: url) else {
throw FluentPostgresError.invalidURL(url)
}
return .postgres(
configuration: configuration,
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop
)
}

public static func postgres(
hostname: String,
port: Int = 5432,
username: String,
password: String,
database: String? = nil,
tlsConfiguration: TLSConfiguration? = nil,
maxConnectionsPerEventLoop: Int = 1
) -> DatabaseConfigurationFactory {
return .postgres(
configuration: .init(
hostname: hostname,
port: port,
username: username,
password: password,
database: database,
tlsConfiguration: tlsConfiguration
),
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop
)
}

public static func postgres(
configuration: PostgresConfiguration,
maxConnectionsPerEventLoop: Int = 1
) -> DatabaseConfigurationFactory {
return DatabaseConfigurationFactory {
FluentPostgresConfiguration(
middleware: [],
configuration: configuration,
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop
)
}
}
}

struct FluentPostgresConfiguration: DatabaseConfiguration {
var middleware: [AnyModelMiddleware]
let configuration: PostgresConfiguration
let maxConnectionsPerEventLoop: Int

func makeDriver(for databases: Databases) -> DatabaseDriver {
let db = PostgresConnectionSource(
configuration: configuration
)
let pool = EventLoopGroupConnectionPool(
source: db,
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
on: databases.eventLoopGroup
)
return _FluentPostgresDriver(pool: pool)
}
}
70 changes: 0 additions & 70 deletions Sources/FluentPostgresDriver/FluentPostgresDriver.swift
Original file line number Diff line number Diff line change
@@ -1,73 +1,3 @@
extension DatabaseConfigurationFactory {
public static func postgres(
url: URL,
maxConnectionsPerEventLoop: Int = 1
) throws -> DatabaseConfigurationFactory {
guard let configuration = PostgresConfiguration(url: url) else {
throw FluentPostgresError.invalidURL(url)
}
return .postgres(
configuration: configuration,
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop
)
}

public static func postgres(
hostname: String,
port: Int = 5432,
username: String,
password: String,
database: String? = nil,
tlsConfiguration: TLSConfiguration? = nil,
maxConnectionsPerEventLoop: Int = 1
) -> DatabaseConfigurationFactory {
return .postgres(
configuration: .init(
hostname: hostname,
port: port,
username: username,
password: password,
database: database,
tlsConfiguration: tlsConfiguration
),
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop
)
}

public static func postgres(
configuration: PostgresConfiguration,
maxConnectionsPerEventLoop: Int = 1
) -> DatabaseConfigurationFactory {
return DatabaseConfigurationFactory {
FluentPostgresConfiguration(
middleware: [],
configuration: configuration,
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop
)
}
}
}

struct FluentPostgresConfiguration: DatabaseConfiguration {
var middleware: [AnyModelMiddleware]
let configuration: PostgresConfiguration
let maxConnectionsPerEventLoop: Int

func makeDriver(for databases: Databases) -> DatabaseDriver {
let db = PostgresConnectionSource(
configuration: configuration
)
let pool = EventLoopGroupConnectionPool(
source: db,
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
on: databases.eventLoopGroup
)
return _FluentPostgresDriver(pool: pool)
}


}

enum FluentPostgresError: Error {
case invalidURL(URL)
}
Expand Down
12 changes: 0 additions & 12 deletions Sources/FluentPostgresDriver/PostgresConverterDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,4 @@ struct PostgresConverterDelegate: SQLConverterDelegate {
return nil
}
}

func nestedFieldExpression(_ column: String, _ path: [String]) -> SQLExpression {
switch path.count {
case 1:
return SQLRaw("\(column)->>'\(path[0])'")
case 2...:
let inner = path[0..<path.count - 1].map { "'\($0)'" }.joined(separator: "->")
return SQLRaw("\(column)->\(inner)->>'\(path.last!)'")
default:
fatalError()
}
}
}
16 changes: 9 additions & 7 deletions Sources/FluentPostgresDriver/PostgresRow+Database.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ private struct _PostgresDatabaseOutput: DatabaseOutput {
self.row.description
}

func contains(_ field: FieldKey) -> Bool {
return self.row.column(self.column(field)) != nil
func contains(_ path: [FieldKey]) -> Bool {
return self.row.column(self.columnName(path)) != nil
}

func schema(_ schema: String) -> DatabaseOutput {
Expand All @@ -32,18 +32,20 @@ private struct _PostgresDatabaseOutput: DatabaseOutput {
}

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

private func column(_ field: FieldKey) -> String {
private func columnName(_ path: [FieldKey]) -> String {
let field = path.map { $0.description }.joined(separator: "_")
if let schema = self.schema {
return schema + "_" + field.description
return "\(schema)_\(field)"
} else {
return field.description
return field
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ final class FluentPostgresDriverTests: XCTestCase {
func testBatch() throws { try self.benchmarker.testBatch() }
func testChildren() throws { try self.benchmarker.testChildren() }
func testChunk() throws { try self.benchmarker.testChunk() }
func testCompoundField() throws { try self.benchmarker.testCompoundField() }
func testCRUD() throws { try self.benchmarker.testCRUD() }
func testEagerLoad() throws { try self.benchmarker.testEagerLoad() }
func testEnum() throws { try self.benchmarker.testEnum() }
Expand All @@ -21,7 +20,6 @@ final class FluentPostgresDriverTests: XCTestCase {
func testMiddleware() throws { try self.benchmarker.testMiddleware() }
func testMigrator() throws { try self.benchmarker.testMigrator() }
func testModel() throws { try self.benchmarker.testModel() }
func testNestedField() throws { try self.benchmarker.testNestedField() }
func testOptionalParent() throws { try self.benchmarker.testOptionalParent() }
func testPagination() throws { try self.benchmarker.testPagination() }
func testParent() throws { try self.benchmarker.testParent() }
Expand Down

0 comments on commit 36ab616

Please sign in to comment.