BUG. [addObjects] add some different object
izouxv opened this issue · 2 comments
izouxv commented
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)
}
Oyvindkg commented
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
izouxv commented
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