TablePlus icon indicating copy to clipboard operation
TablePlus copied to clipboard

[Question | Feature Request] Open database and execute bootsprap commands via CLI

Open aa-ndrej opened this issue 10 months ago • 3 comments

  1. Which driver are you using and version of it: SQLite

  2. Which TablePlus build number are you using: 600

Question / Feature request:

When creating a database connection and saving it in the connection list, we have the option to define bootstrap commands. For most of our projects using SQLite, we always enable foreign key support with PRAGMA foreign_keys = ON;.

Image

However, we usually have a shortcut in each project that opens the database in TablePlus via a CLI command like: open -a TablePlus \"file://$(pwd)/storage/db.sqlite\" This is more convenient for everyone using the project.

Is it possible to open a database connection via the command line while specifying these bootstrap commands? Or is there another way to enable foreign key support when opening an SQLite database via the command line?

Other related issues:

  • https://github.com/TablePlus/TablePlus/issues/393
  • https://github.com/TablePlus/TablePlus/issues/227
  • https://github.com/TablePlus/TablePlus/issues/3109

aa-ndrej avatar Mar 23 '25 11:03 aa-ndrej

I know it is a bit hack, but you can do something like this

open -a TablePlus "sqlite://@%2FUsers%2Fr%2FDownloads%2Ftest.sqlite3/test.sqlite3?table=YOU_TABLE_NAME&raw=YOUR_COLUMN_ID=VALUE;PRAGMA foreign_keys = ON;"

huyphams avatar Mar 25 '25 07:03 huyphams

It will open connection, open the table, filter with column=value and then also execute the PRAGMA foreign_keys = ON;

huyphams avatar Mar 25 '25 07:03 huyphams

Unfortunately, I tried several variations but couldn't get it to work.

Did the command PRAGMA foreign_keys = ON execute successfully on your end? Were foreign key constraints enforced afterward?

Seems like PRAGMA are not working in queries, only pragma functions but there is no such function for the foreign_keys PRAGMA. :/

aa-ndrej avatar Mar 26 '25 14:03 aa-ndrej