Skip to content

ATTACH/DETACH database #19

Answered by rkistner
rodydavis asked this question in Q&A
Discussion options

You must be logged in to vote

While we don't have an explicit API for that, you can still use ATTACH / DETACH directly in queries.

Since we're using a connection pool, ATTACH needs to be called on every connection you want to use it from. One way to do that is using a SqliteOpenFactory, such as in this example.

Then add this in the open call:

    db.execute("ATTACH ? AS other", ['other.db']);

If you only want to attach temporarily, you can do so within a connection lock or transaction, which only uses a single connection at a time:

  await db.readLock((ctx) async {
    // Everything inside this lock uses the same database connection
    try {
      await ctx.getAll("ATTACH ? AS other", ['other.db']);
      print(await

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kobiebotha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #18 on November 13, 2023 12:53.