Skip to content

sqlite driver should support attaching a database #324

Open
@neilotoole

Description

@neilotoole

Is your feature request related to a problem? Please describe.

Other drivers (e.g. Postgres) have inherent support for SQL SCHEMA (and usually CATALOG). SQLite doesn't have CATALOG support, but by attaching a database, it effectively has SCHEMA support.

Issue #270 exposes the ability to switch schema per query. But we can't implement this functionality for SQLite until there's a means to attach databases.

Describe the solution you'd like
It should be possible to attach databases to a SQLite source, at a minimum, after the source has been added, and maybe when creating the soruce. An example implementation might be:

# Attach when adding the source (maybe?)
$ sq add --driver=sqlite3 ./main.db --attach ./sales.db --attach-as sales

# Attach after the fact
$ sq src attach @sqlite ./sales.db
$ sq src attach @sqlite ./inventory.db --name inven

$ sq src detach @sqlite sales
$ sq src detach @sqlite inven

Note that the sq src attach form is only an example of a possible implementation. Maybe sq config edit @sqlite or such could work too.

Describe alternatives you've considered
N/A

Additional context

  • Do we need a means to list the attached databases?
  • Would the attached databases show up in sq src (get source details), or maybe sq src -j?
  • How to store details in the config file? Maybe something like:
handle: "@sakila/sl3"
driver: sqlite3
location: sqlite3:///Users/neilotoole/work/sq/sq/drivers/sqlite3/testdata/sakila.db
extra:
  sqlite3:
    attach:
      - name: sales
        path: ./sales.db
      - name: inven
        path: ./inventory.db
  • Should the path of the attached db be stored as an absolute filepath, or as relative to the main db file (whose filepath is already stored as an absolute path)?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions