Skip to content

Commit

Permalink
removing throwing from Model atomic create + fix id overwrite bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tanner0101 committed Jun 16, 2018
1 parent 30d769b commit 1ad690c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Sources/FluentMySQL/Exports.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ extension QueryBuilder where Result: Model, Result.Database == Database, Databas
}

extension Model where Database == MySQLDatabase {
public func create(orIgnore: Bool, on conn: DatabaseConnectable) throws -> Future<Self> {
public func create(orIgnore: Bool, on conn: DatabaseConnectable) -> Future<Self> {
return Self.query(on: conn).create(orIgnore: orIgnore, self)
}
public func create(orUpdate: Bool, on conn: DatabaseConnectable) throws -> Future<Self> {
public func create(orUpdate: Bool, on conn: DatabaseConnectable) -> Future<Self> {
return Self.query(on: conn).create(orUpdate: orUpdate, self)
}
}
13 changes: 11 additions & 2 deletions Sources/FluentMySQL/MySQLDatabase+QuerySupporting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ extension MySQLDatabase: QuerySupporting {
copy.fluentID = UUID() as? M.ID
}
case .didCreate:
if M.ID.self is Int.Type {
if let idType = M.ID.self as? UInt64Initializable.Type, copy.fluentID == nil {
// FIXME: support other Int types
copy.fluentID = conn.lastMetadata?.lastInsertID.flatMap(Int.init) as? M.ID
copy.fluentID = conn.lastMetadata?.lastInsertID.flatMap(idType.init) as? M.ID
}
default: break
}
Expand Down Expand Up @@ -391,3 +391,12 @@ extension MySQLDatabase: QuerySupporting {
query.orderBy.append(orderBy)
}
}

internal protocol UInt64Initializable {
init(_ uint64: UInt64)
}

extension Int32: UInt64Initializable { }
extension Int64: UInt64Initializable { }
extension UInt32: UInt64Initializable { }
extension UInt64: UInt64Initializable { }

0 comments on commit 1ad690c

Please sign in to comment.