Skip to content

Commit

Permalink
Merge pull request #86 from vapor/release
Browse files Browse the repository at this point in the history
release
  • Loading branch information
tanner0101 authored Jul 26, 2018
2 parents 9be6598 + f36c3cf commit 8e3eb9d
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 53 deletions.
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ let package = Package(
.package(url: "https://github.com/vapor/core.git", from: "3.0.0"),

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

// 🐘 Non-blocking, event-driven Swift client for PostgreSQL.
.package(url: "https://github.com/vapor/postgresql.git", from: "1.0.0-rc"),
.package(url: "https://github.com/vapor/postgresql.git", from: "1.0.0"),
],
targets: [
.target(name: "FluentPostgreSQL", dependencies: ["Async", "FluentSQL", "PostgreSQL"]),
Expand Down
19 changes: 1 addition & 18 deletions Sources/FluentPostgreSQL/Deprecated.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1 @@
@available(*, deprecated, renamed: "PostgreSQLDataConvertible")
public typealias PostgreSQLColumnStaticRepresentable = PostgreSQLDataConvertible

/// - warning: Deprecated.
@available(*, deprecated, renamed: "PostgreSQLType")
public protocol PostgreSQLJSONType: PostgreSQLType { }

/// - warning: Deprecated.
@available(*, deprecated, renamed: "PostgreSQLType")
public protocol PostgreSQLArrayType: PostgreSQLType { }

// - warning: Deprecated.
@available(*, deprecated, message: "Use custom migration instead.")
public protocol PostgreSQLEnumType { }

// - warning: Deprecated.
@available(*, deprecated, message: "Use custom migration instead.")
public protocol PostgreSQLType { }
/// Nothing here yet...
29 changes: 0 additions & 29 deletions Sources/FluentPostgreSQL/Exports.swift
Original file line number Diff line number Diff line change
@@ -1,31 +1,2 @@
@_exported import FluentSQL
@_exported import PostgreSQL

//extension QueryBuilder where Database == PostgreSQLDatabase {
// public func keys(_ keys: PostgreSQLQuery.Key...) -> Self {
// query.keys = keys
// return self
// }
//
// // MARK: Group By
//
// /// Adds a group by to the query builder.
// ///
// /// query.groupBy(\.name)
// ///
// /// - parameters:
// /// - field: Swift `KeyPath` to field on model to group by.
// /// - returns: Query builder for chaining.
// public func groupBy<T>(_ field: KeyPath<Result, T>) -> Self {
// return groupBy(.expression(.column(PostgreSQLDatabase.queryField(.keyPath(field))), alias: nil))
// }
//
// /// Adds a manually created group by to the query builder.
// /// - parameters:
// /// - groupBy: New `Query.GroupBy` to add.
// /// - returns: Query builder for chaining.
// public func groupBy(_ groupBy: PostgreSQLQuery.Key) -> Self {
// query.groupBy.append(groupBy)
// return self
// }
//}
2 changes: 2 additions & 0 deletions Sources/FluentPostgreSQL/Fluent+PostgreSQLUpsert.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
extension _PostgreSQLModel {
/// Creates the model or updates it depending on whether a model with the same ID already exists.
public func create(orUpdate: Bool, on conn: DatabaseConnectable) -> Future<Self> {
return Self.query(on: conn).create(orUpdate: orUpdate, self)
}
}

extension QueryBuilder where Result: _PostgreSQLModel, Result.Database == Database {
/// Creates the model or updates it depending on whether a model with the same ID already exists.
public func create(orUpdate: Bool, _ model: Result) -> Future<Result> {
if orUpdate {
let row = SQLQueryEncoder(PostgreSQLExpression.self).encode(model)
Expand Down
9 changes: 9 additions & 0 deletions Sources/FluentPostgreSQL/PostgreSQLEnum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ public protocol PostgreSQLEnum: PostgreSQLExpressionRepresentable, CaseIterable,
static var postgreSQLEnumTypeName: String { get }
}

public protocol PostgreSQLRawEnum: RawRepresentable, Codable, CaseIterable, ReflectionDecodable, PostgreSQLDataTypeStaticRepresentable { }

extension PostgreSQLRawEnum where Self.RawValue: PostgreSQLDataTypeStaticRepresentable {
/// See `PostgreSQLDataTypeStaticRepresentable`.
public static var postgreSQLDataType: PostgreSQLDataType {
return RawValue.postgreSQLDataType
}
}

extension PostgreSQLEnum {
/// See `PostgreSQLEnum`.
public static var postgreSQLEnumTypeName: String {
Expand Down
1 change: 0 additions & 1 deletion Sources/FluentPostgreSQL/PostgreSQLTableNameCache.swift

This file was deleted.

1 change: 0 additions & 1 deletion Sources/FluentPostgreSQL/PostgreSQLType.swift

This file was deleted.

2 changes: 0 additions & 2 deletions Sources/FluentPostgreSQL/Utilities.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


protocol AnyArray {
static var anyElementType: Any.Type { get }
}
Expand Down
82 changes: 82 additions & 0 deletions Tests/FluentPostgreSQLTests/FluentPostgreSQLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,86 @@ class FluentPostgreSQLTests: XCTestCase {
defer { try? C.revert(on: conn).wait() }
}

// https://github.com/vapor/fluent-postgresql/issues/85
func testGH85() throws {
enum Availability: UInt8, PostgreSQLRawEnum {
static var allCases: [Availability] = [.everyday, .sunday, .monday, .tuesday, .wednesday, .thursday, .friday, .saturday]

case everyday
case sunday
case monday
case tuesday
case wednesday
case thursday
case friday
case saturday
}

struct Foo: PostgreSQLModel, Migration {
var id: Int?
var availability: Availability
}

let conn = try benchmarker.pool.requestConnection().wait()
conn.logger = DatabaseLogger(database: .psql, handler: PrintLogHandler())
defer { benchmarker.pool.releaseConnection(conn) }

try Foo.prepare(on: conn).wait()
defer { try? Foo.revert(on: conn).wait() }

let a = Foo(id: nil, availability: .everyday)
_ = try a.save(on: conn).wait()
}

// https://github.com/vapor/fluent-postgresql/issues/35
func testGH35() throws {
struct Game: PostgreSQLModel, Migration {
var id: Int?
var tags: [Int64]?
}

let conn = try benchmarker.pool.requestConnection().wait()
conn.logger = DatabaseLogger(database: .psql, handler: PrintLogHandler())
defer { benchmarker.pool.releaseConnection(conn) }

try Game.prepare(on: conn).wait()
defer { try? Game.revert(on: conn).wait() }

var a = Game(id: nil, tags: [1, 2, 3])
a = try a.save(on: conn).wait()
}

// https://github.com/vapor/fluent-postgresql/issues/54
func testGH54() throws {
struct User: PostgreSQLModel, Migration {
var id: Int?
var username: String
}

struct AddUserIndex: PostgreSQLMigration {
static func prepare(on conn: PostgreSQLConnection) -> Future<Void> {
return Database.update(User.self, on: conn) { builder in
builder.unique(on: \.username)
}
}

static func revert(on conn: PostgreSQLConnection) -> Future<Void> {
return Database.update(User.self, on: conn) { builder in
builder.deleteUnique(from: \.username)
}
}
}

let conn = try benchmarker.pool.requestConnection().wait()
conn.logger = DatabaseLogger(database: .psql, handler: PrintLogHandler())
defer { benchmarker.pool.releaseConnection(conn) }

try User.prepare(on: conn).wait()
defer { try? User.revert(on: conn).wait() }
try AddUserIndex.prepare(on: conn).wait()
defer { try? AddUserIndex.revert(on: conn).wait() }
}

static let allTests = [
("testBenchmark", testBenchmark),
("testNestedStruct", testNestedStruct),
Expand All @@ -475,6 +555,8 @@ class FluentPostgreSQLTests: XCTestCase {
("testCustomFilter", testCustomFilter),
("testCreateOrUpdate", testCreateOrUpdate),
("testEnumArray", testEnumArray),
("testGH85", testGH85),
("testGH35", testGH35),
]
}

Expand Down

0 comments on commit 8e3eb9d

Please sign in to comment.