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 413ddb2

Browse files
alpha (vapor#116)
* alpha * update to 5.1 image * update
1 parent 2afac78 commit 413ddb2

19 files changed

+219
-1974
lines changed

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
/*.xcodeproj
55
Package.resolved
66
DerivedData
7+
.swiftpm
78

‎Package.swift‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.0
1+
// swift-tools-version:5.1
22
import PackageDescription
33

44
let package = Package(
@@ -7,23 +7,18 @@ let package = Package(
77
.library(name: "FluentPostgresDriver", targets: ["FluentPostgresDriver"]),
88
],
99
dependencies: [
10-
.package(url: "https://github.com/vapor/fluent-kit.git", .branch("master")),
11-
.package(url: "https://github.com/vapor/nio-postgres.git", .branch("master")),
12-
.package(url: "https://github.com/vapor/sql.git", .branch("master")),
13-
.package(url: "https://github.com/vapor/nio-kit.git", .branch("master")),
10+
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.0.0-alpha"),
11+
.package(url: "https://github.com/vapor/postgres-kit.git", from: "2.0.0-alpha"),
1412
],
1513
targets: [
1614
.target(name: "FluentPostgresDriver", dependencies: [
1715
"FluentKit",
1816
"FluentSQL",
19-
"NIOKit",
20-
"NIOPostgres",
21-
"SQLKit"
17+
"PostgresKit",
2218
]),
2319
.testTarget(name: "FluentPostgresDriverTests", dependencies: [
2420
"FluentBenchmark",
2521
"FluentPostgresDriver",
26-
"SQLKitBenchmark"
2722
]),
2823
]
2924
)

‎README.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
<p align="center">
2-
<img src="https://user-images.githubusercontent.com/1342803/36623958-dc6f07f0-18d7-11e8-8c6c-01737f496de9.png" height="64" alt="Fluent PostgreSQL">
2+
<img src="https://user-images.githubusercontent.com/1342803/59063319-d190f500-8875-11e9-8fe6-16197dd56d0f.png" alt="FluentPostgresDriver">
33
<br>
44
<br>
5-
<a href="http://docs.vapor.codes/3.0/">
6-
<img src="http://img.shields.io/badge/read_the-docs-2196f3.svg" alt="Documentation">
5+
<a href="https://api.vapor.codes/fluent-postgres-driver/master/FluentPostgresDriver/index.html">
6+
<img src="http://img.shields.io/badge/api-docs-2196f3.svg" alt="Documentation">
77
</a>
88
<a href="https://discord.gg/vapor">
99
<img src="https://img.shields.io/discord/431917998102675485.svg" alt="Team Chat">
1010
</a>
1111
<a href="LICENSE">
1212
<img src="http://img.shields.io/badge/license-MIT-brightgreen.svg" alt="MIT License">
1313
</a>
14-
<a href="https://circleci.com/gh/vapor/fluent-postgresql">
15-
<img src="https://circleci.com/gh/vapor/fluent-postgresql.svg?style=shield" alt="Continuous Integration">
14+
<a href="https://circleci.com/gh/vapor/fluent-postgres-driver">
15+
<img src="https://circleci.com/gh/vapor/fluent-postgres-driver.svg?style=shield" alt="Continuous Integration">
1616
</a>
1717
<a href="https://swift.org">
18-
<img src="http://img.shields.io/badge/swift-5-brightgreen.svg" alt="Swift 5">
18+
<img src="http://img.shields.io/badge/swift-5.1-brightgreen.svg" alt="Swift 5.1">
1919
</a>
2020
</p>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
extension ConnectionPool: Database where Source.Connection: Database {
2+
public var eventLoop: EventLoop {
3+
return self.source.eventLoop
4+
}
5+
6+
public func execute(_ schema: DatabaseSchema) -> EventLoopFuture<Void> {
7+
return self.withConnection { 0ドル.execute(schema) }
8+
}
9+
10+
public func execute(_ query: DatabaseQuery, _ onOutput: @escaping (DatabaseOutput) throws -> ()) -> EventLoopFuture<Void> {
11+
return self.withConnection { 0ドル.execute(query, onOutput) }
12+
}
13+
14+
public func withConnection<T>(_ closure: @escaping (Database) -> EventLoopFuture<T>) -> EventLoopFuture<T> {
15+
return self.withConnection { (conn: Source.Connection) in
16+
return closure(conn)
17+
}
18+
}
19+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
extension Databases {
2+
public mutating func postgres(
3+
config: PostgresConfiguration,
4+
poolConfig: ConnectionPoolConfig = .init(),
5+
as id: DatabaseID = .psql,
6+
isDefault: Bool = true
7+
) {
8+
let db = PostgresConnectionSource(
9+
configuration: config,
10+
on: self.eventLoop
11+
)
12+
let pool = ConnectionPool(config: poolConfig, source: db)
13+
self.add(pool, as: id, isDefault: isDefault)
14+
}
15+
}
16+
17+
extension DatabaseID {
18+
public static var psql: DatabaseID {
19+
return .init(string: "psql")
20+
}
21+
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
@_exported import FluentKit
2-
@_exported import SQLKit
3-
@_exported import NIOKit
4-
@_exported import NIOPostgres
2+
@_exported import PostgresKit

‎Sources/FluentPostgresDriver/Postgres+Fluent.swift‎

Lines changed: 0 additions & 108 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import FluentSQL
2+
3+
extension PostgresConnection: Database {
4+
public func withConnection<T>(_ closure: @escaping (Database) -> EventLoopFuture<T>) -> EventLoopFuture<T> {
5+
return closure(self)
6+
}
7+
8+
public func execute(_ query: DatabaseQuery, _ onOutput: @escaping (DatabaseOutput) throws -> ()) -> EventLoopFuture<Void> {
9+
var sql = SQLQueryConverter(delegate: PostgresConverterDelegate())
10+
.convert(query)
11+
switch query.action {
12+
case .create:
13+
sql = PostgresReturning(sql)
14+
default: break
15+
}
16+
return self.execute(sql: sql) { row in
17+
try onOutput(row as! PostgresRow)
18+
}
19+
}
20+
21+
public func execute(_ schema: DatabaseSchema) -> EventLoopFuture<Void> {
22+
let sql = SQLSchemaConverter(delegate: PostgresConverterDelegate())
23+
.convert(schema)
24+
return self.execute(sql: sql) { row in
25+
fatalError("unexpected output")
26+
}
27+
}
28+
}
29+
30+
private struct PostgresReturning: SQLExpression {
31+
let base: SQLExpression
32+
init(_ base: SQLExpression) {
33+
self.base = base
34+
}
35+
36+
func serialize(to serializer: inout SQLSerializer) {
37+
self.base.serialize(to: &serializer)
38+
serializer.write(#" RETURNING id as "fluentID""#)
39+
}
40+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import FluentSQL
2+
3+
struct PostgresConverterDelegate: SQLConverterDelegate {
4+
func customDataType(_ dataType: DatabaseSchema.DataType) -> SQLExpression? {
5+
switch dataType {
6+
case .uuid:
7+
return SQLRaw("UUID")
8+
default:
9+
return nil
10+
}
11+
}
12+
13+
func nestedFieldExpression(_ column: String, _ path: [String]) -> SQLExpression {
14+
return SQLRaw("\(column)->>'\(path[0])'")
15+
}
16+
}

0 commit comments

Comments
(0)

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