0

I have a project which contains multiple databases in a directory structure like this:

folder1
|_ sub1
  |_ db1
  |_ db2
|_ sub2
  |_ db1
  |_ d2

I would like to run one query against all the databases.

Is there a way to do this using Sequel, or would I need to traverse the directory and create a new database connection for each database, then run the query?

Help appreciated.

1 Answer 1

1

You can do it a couple ways but I'd do it like this untested code:

%w[
  sqlite://folder1/sub1/db1.db
  sqlite://folder1/sub1/db2.db
  sqlite://folder1/sub2/db1.db
  sqlite://folder1/sub2/db2.db
].map{ |dsn|
  DB = Sequel.connect(dsn)
  DB[:some_table].where('some' => 'value').all
}

This iterates over the DSNs for each database, opens a connection and returns the result as an array of results.

What those are is undefined since we have no idea what your table schemas are.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.