GRDB.swift v1.1.0 Release Notes

  • ๐Ÿš€ Released July 1, 2017 • diff

    ๐Ÿ†• New

    • ๐Ÿ“š DatabaseAggregate is the protocol for custom aggregate functions (fixes #236, documentation):

      struct MySum : DatabaseAggregate {
          var sum: Int = 0
      
          mutating func step(_ dbValues: [DatabaseValue]) {
              if let int = Int.fromDatabaseValue(dbValues[0]) {
                  sum += int
              }
          }
      
          func finalize() -> DatabaseValueConvertible? {
              return sum
          }
      }
      
      let dbQueue = DatabaseQueue()
      let fn = DatabaseFunction("mysum", argumentCount: 1, aggregate: MySum.self)
      dbQueue.add(function: fn)
      try dbQueue.inDatabase { db in
          try db.execute("CREATE TABLE test(i)")
          try db.execute("INSERT INTO test(i) VALUES (1)")
          try db.execute("INSERT INTO test(i) VALUES (2)")
          try Int.fetchOne(db, "SELECT mysum(i) FROM test")! // 3
      }
      

    ๐Ÿ›  Fixed

    • ๐Ÿ“š QueryInterfaceRequest.order(_:) clears the eventual reversed flag, and better reflects the documentation of this method: "Any previous ordering is replaced."

    ๐Ÿ—„ Deprecated

    • ๐Ÿ—„ TableMapping.primaryKeyRowComparator is deprecated, without any replacement.

    API diff

     final class DatabaseFunction {
    +    init<Aggregate: DatabaseAggregate>(_ name: String, argumentCount: Int32? = nil, pure: Bool = false, aggregate: Aggregate.Type)
     }
    
    +protocol DatabaseAggregate {
    +    init()
    +    mutating func step(_ dbValues: [DatabaseValue]) throws
    +    func finalize() throws -> DatabaseValueConvertible?
    +}
    
     extension TableMapping {
    +    @available(*, deprecated)
         static func primaryKeyRowComparator(_ db: Database) throws -> (Row, Row) -> Bool
     }