-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
97 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
]), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
67
Sources/FluentPostgresDriver/FluentPostgresConfiguration.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters