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 8e3eb9d

Browse files
Merge pull request #86 from vapor/release
release
2 parents 9be6598 + f36c3cf commit 8e3eb9d

File tree

9 files changed

+96
-53
lines changed

9 files changed

+96
-53
lines changed

β€ŽPackage.swiftβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ let package = Package(
1212
.package(url: "https://github.com/vapor/core.git", from: "3.0.0"),
1313

1414
// Swift ORM framework (queries, models, and relations) for building NoSQL and SQL database integrations.
15-
.package(url: "https://github.com/vapor/fluent.git", from: "3.0.0-rc"),
15+
.package(url: "https://github.com/vapor/fluent.git", from: "3.0.0"),
1616

1717
// 🐘 Non-blocking, event-driven Swift client for PostgreSQL.
18-
.package(url: "https://github.com/vapor/postgresql.git", from: "1.0.0-rc"),
18+
.package(url: "https://github.com/vapor/postgresql.git", from: "1.0.0"),
1919
],
2020
targets: [
2121
.target(name: "FluentPostgreSQL", dependencies: ["Async", "FluentSQL", "PostgreSQL"]),
Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1 @@
1-
@available(*, deprecated, renamed: "PostgreSQLDataConvertible")
2-
public typealias PostgreSQLColumnStaticRepresentable = PostgreSQLDataConvertible
3-
4-
/// - warning: Deprecated.
5-
@available(*, deprecated, renamed: "PostgreSQLType")
6-
public protocol PostgreSQLJSONType: PostgreSQLType { }
7-
8-
/// - warning: Deprecated.
9-
@available(*, deprecated, renamed: "PostgreSQLType")
10-
public protocol PostgreSQLArrayType: PostgreSQLType { }
11-
12-
// - warning: Deprecated.
13-
@available(*, deprecated, message: "Use custom migration instead.")
14-
public protocol PostgreSQLEnumType { }
15-
16-
// - warning: Deprecated.
17-
@available(*, deprecated, message: "Use custom migration instead.")
18-
public protocol PostgreSQLType { }
1+
/// Nothing here yet...
Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,2 @@
11
@_exported import FluentSQL
22
@_exported import PostgreSQL
3-
4-
//extension QueryBuilder where Database == PostgreSQLDatabase {
5-
// public func keys(_ keys: PostgreSQLQuery.Key...) -> Self {
6-
// query.keys = keys
7-
// return self
8-
// }
9-
//
10-
// // MARK: Group By
11-
//
12-
// /// Adds a group by to the query builder.
13-
// ///
14-
// /// query.groupBy(\.name)
15-
// ///
16-
// /// - parameters:
17-
// /// - field: Swift `KeyPath` to field on model to group by.
18-
// /// - returns: Query builder for chaining.
19-
// public func groupBy<T>(_ field: KeyPath<Result, T>) -> Self {
20-
// return groupBy(.expression(.column(PostgreSQLDatabase.queryField(.keyPath(field))), alias: nil))
21-
// }
22-
//
23-
// /// Adds a manually created group by to the query builder.
24-
// /// - parameters:
25-
// /// - groupBy: New `Query.GroupBy` to add.
26-
// /// - returns: Query builder for chaining.
27-
// public func groupBy(_ groupBy: PostgreSQLQuery.Key) -> Self {
28-
// query.groupBy.append(groupBy)
29-
// return self
30-
// }
31-
//}

β€ŽSources/FluentPostgreSQL/Fluent+PostgreSQLUpsert.swiftβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
extension _PostgreSQLModel {
2+
/// Creates the model or updates it depending on whether a model with the same ID already exists.
23
public func create(orUpdate: Bool, on conn: DatabaseConnectable) -> Future<Self> {
34
return Self.query(on: conn).create(orUpdate: orUpdate, self)
45
}
56
}
67

78
extension QueryBuilder where Result: _PostgreSQLModel, Result.Database == Database {
9+
/// Creates the model or updates it depending on whether a model with the same ID already exists.
810
public func create(orUpdate: Bool, _ model: Result) -> Future<Result> {
911
if orUpdate {
1012
let row = SQLQueryEncoder(PostgreSQLExpression.self).encode(model)

β€ŽSources/FluentPostgreSQL/PostgreSQLEnum.swiftβ€Ž

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ public protocol PostgreSQLEnum: PostgreSQLExpressionRepresentable, CaseIterable,
22
static var postgreSQLEnumTypeName: String { get }
33
}
44

5+
public protocol PostgreSQLRawEnum: RawRepresentable, Codable, CaseIterable, ReflectionDecodable, PostgreSQLDataTypeStaticRepresentable { }
6+
7+
extension PostgreSQLRawEnum where Self.RawValue: PostgreSQLDataTypeStaticRepresentable {
8+
/// See `PostgreSQLDataTypeStaticRepresentable`.
9+
public static var postgreSQLDataType: PostgreSQLDataType {
10+
return RawValue.postgreSQLDataType
11+
}
12+
}
13+
514
extension PostgreSQLEnum {
615
/// See `PostgreSQLEnum`.
716
public static var postgreSQLEnumTypeName: String {

β€ŽSources/FluentPostgreSQL/PostgreSQLTableNameCache.swiftβ€Ž

Lines changed: 0 additions & 1 deletion
This file was deleted.

β€ŽSources/FluentPostgreSQL/PostgreSQLType.swiftβ€Ž

Lines changed: 0 additions & 1 deletion
This file was deleted.

β€ŽSources/FluentPostgreSQL/Utilities.swiftβ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
protocol AnyArray {
42
static var anyElementType: Any.Type { get }
53
}

β€ŽTests/FluentPostgreSQLTests/FluentPostgreSQLTests.swiftβ€Ž

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,86 @@ class FluentPostgreSQLTests: XCTestCase {
459459
defer { try? C.revert(on: conn).wait() }
460460
}
461461

462+
// https://github.com/vapor/fluent-postgresql/issues/85
463+
func testGH85() throws {
464+
enum Availability: UInt8, PostgreSQLRawEnum {
465+
static var allCases: [Availability] = [.everyday, .sunday, .monday, .tuesday, .wednesday, .thursday, .friday, .saturday]
466+
467+
case everyday
468+
case sunday
469+
case monday
470+
case tuesday
471+
case wednesday
472+
case thursday
473+
case friday
474+
case saturday
475+
}
476+
477+
struct Foo: PostgreSQLModel, Migration {
478+
var id: Int?
479+
var availability: Availability
480+
}
481+
482+
let conn = try benchmarker.pool.requestConnection().wait()
483+
conn.logger = DatabaseLogger(database: .psql, handler: PrintLogHandler())
484+
defer { benchmarker.pool.releaseConnection(conn) }
485+
486+
try Foo.prepare(on: conn).wait()
487+
defer { try? Foo.revert(on: conn).wait() }
488+
489+
let a = Foo(id: nil, availability: .everyday)
490+
_ = try a.save(on: conn).wait()
491+
}
492+
493+
// https://github.com/vapor/fluent-postgresql/issues/35
494+
func testGH35() throws {
495+
struct Game: PostgreSQLModel, Migration {
496+
var id: Int?
497+
var tags: [Int64]?
498+
}
499+
500+
let conn = try benchmarker.pool.requestConnection().wait()
501+
conn.logger = DatabaseLogger(database: .psql, handler: PrintLogHandler())
502+
defer { benchmarker.pool.releaseConnection(conn) }
503+
504+
try Game.prepare(on: conn).wait()
505+
defer { try? Game.revert(on: conn).wait() }
506+
507+
var a = Game(id: nil, tags: [1, 2, 3])
508+
a = try a.save(on: conn).wait()
509+
}
510+
511+
// https://github.com/vapor/fluent-postgresql/issues/54
512+
func testGH54() throws {
513+
struct User: PostgreSQLModel, Migration {
514+
var id: Int?
515+
var username: String
516+
}
517+
518+
struct AddUserIndex: PostgreSQLMigration {
519+
static func prepare(on conn: PostgreSQLConnection) -> Future<Void> {
520+
return Database.update(User.self, on: conn) { builder in
521+
builder.unique(on: \.username)
522+
}
523+
}
524+
525+
static func revert(on conn: PostgreSQLConnection) -> Future<Void> {
526+
return Database.update(User.self, on: conn) { builder in
527+
builder.deleteUnique(from: \.username)
528+
}
529+
}
530+
}
531+
532+
let conn = try benchmarker.pool.requestConnection().wait()
533+
conn.logger = DatabaseLogger(database: .psql, handler: PrintLogHandler())
534+
defer { benchmarker.pool.releaseConnection(conn) }
535+
536+
try User.prepare(on: conn).wait()
537+
defer { try? User.revert(on: conn).wait() }
538+
try AddUserIndex.prepare(on: conn).wait()
539+
defer { try? AddUserIndex.revert(on: conn).wait() }
540+
}
541+
462542
static let allTests = [
463543
("testBenchmark", testBenchmark),
464544
("testNestedStruct", testNestedStruct),
@@ -475,6 +555,8 @@ class FluentPostgreSQLTests: XCTestCase {
475555
("testCustomFilter", testCustomFilter),
476556
("testCreateOrUpdate", testCreateOrUpdate),
477557
("testEnumArray", testEnumArray),
558+
("testGH85", testGH85),
559+
("testGH35", testGH35),
478560
]
479561
}
480562

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /