Oyvindkg / swiftydb

💀Neither supported nor maintained for years. A type-safe, protocol-based, pure Swift database offering effortless persistence of any object

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BUG. [addObjects] add some different object

izouxv opened this issue · comments

public func addObjects <S: Storable> (objects: [S], update: Bool = true) -> Result<Bool> {
    guard objects.count > 0 else {
        return Result.Success(true)
    }

    do {
        if !(try tableExistsForType(S)) {
            //!!! BUG !!! , if objects is different model, they have different table, 
            createTableForTypeRepresentedByObject(objects.first!)
        }

        let insertStatement = StatementGenerator.insertStatementForType(S.self, update: update)


        try databaseQueue.transaction { (database) -> Void in
            let statement = try database.prepare(insertStatement)

            defer {
                /* If an error occurs, try to finalize the statement */
                let _ = try? statement.finalize()
            }

            for object in objects {
                let data = self.dataFromObject(object)
                try statement.executeUpdate(data)
            }
        }
    } catch let error {
        return Result.Error(error)
    }

    return Result.Success(true)
}

You are correct. Thanks for pointing it out.

This is fixed in the upcoming v2.0.

An initial description can be found here: https://github.com/Oyvindkg/swiftydb/tree/dev

i clone your SwifiyDB at https://github.com/izouxv/Swiftydb, and it support carthage, some new feature on the reps' simple branch. my gmail is izouxv@gmail.com, may be we can discuss it