Giter Club home page Giter Club logo

Comments (10)

groue avatar groue commented on May 17, 2024

Would you please reformat your code as below:

```swift
// yeah, Swift
do {
    // correctly indented
}
```

It will help a lot reading your question :-)

// yeah, Swift
do {
    // correctly indented
}

from grdb.swift.

mtissington avatar mtissington commented on May 17, 2024

yes, having a great difficult with code formatting ... seems to want to strip out tabs and cr/lf

from grdb.swift.

mtissington avatar mtissington commented on May 17, 2024

ok, that should do ..

from grdb.swift.

groue avatar groue commented on May 17, 2024

Thanks ;-)

OK now it's crystal clear. The inDatabase method executes its closure argument in a protected dispatch queue. And a database complains if it is used outside of this queue:

dbQueue.inDatabase { db in
    // In the queue of `db`
    try! dbQueueMerge.inDatabase {dbMerge in
        // In the queue of `dbMerge`
        // And there `db` complains it is not in its queue:
        try db.execute(...)
    }
}

OK. That's a pattern that is not supported today. I have to think about it.

Meanwhile, you have two possible workarounds:

1- First fetch all data in the source database queue, and then write in the destination database queue. It's much less memory efficient than your tight and sharp loop, I agree. But if you don't have too much data to copy, this solution can be an acceptable workaround.

2- If you actually copy the whole content of a database in another, use the backup method.

from grdb.swift.

mtissington avatar mtissington commented on May 17, 2024

Hmm, I was afraid you would tell me something like that. I would have thought that merging a second database is a (fairly) common need. In the merge process PK values change so I'll have to go with option one.

Hope you can figure something out ... and thanks for the speedy replies!

from grdb.swift.

groue avatar groue commented on May 17, 2024

I would have thought that merging a second database is a (fairly) common need.

There are my needs, the ones of my coworkers, and the ones of users like you who are kind enough to ask for a feature. Now the merge is on the list of feature requests :-)

Hope you can figure something out

So do I. Until this time, use a workaround, and stay tuned on GRDB :-)

from grdb.swift.

groue avatar groue commented on May 17, 2024

@mtissington OK I eventually managed to find a solution:

dbQueue1.inDatabase { db1 in 
    dbQueue2.inDatabase { db2 in 
        // Both db1 and db2 can be used here.
    }
}

from grdb.swift.

mtissington avatar mtissington commented on May 17, 2024

cool, will give it a try ....

from grdb.swift.

groue avatar groue commented on May 17, 2024

The fix has shipped in v0.66.0.

from grdb.swift.

mtissington avatar mtissington commented on May 17, 2024

confirmed that this now works - thanks

            try dbQueue.inTransaction { db in
                try dbQueueMerge.inDatabase {dbMerge in

from grdb.swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.