Skip to content
This repository has been archived by the owner on Nov 13, 2020. It is now read-only.

BUG. [addObjects] add some different object #28

Closed
izouxv opened this issue Sep 9, 2016 · 2 comments
Closed

BUG. [addObjects] add some different object #28

izouxv opened this issue Sep 9, 2016 · 2 comments

Comments

@izouxv
Copy link

izouxv commented Sep 9, 2016

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
Copy link
Owner

Oyvindkg commented Sep 9, 2016

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
Copy link
Author

izouxv commented Sep 12, 2016

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants