Setting a Default Output Mode in SQLite Using an Alias
Abenezer Belachew ยท June 15, 2024
2 min read
-
This probably doesn't need to be a post, but I want to document it so I don't forget and end up searching for a solution again.
-
The
.modedot-command in SQLite sets the output mode so that the query response is formatted in a specified way. -
To see the list of available output modes, you can execute
.modefollowed by some random text:
sqlite> .mode karate
Error: mode should be one of: ascii box column csv html insert json line list markdown qbox quote table tabs tcl
- The available output modes in my version of SQLite are:
ascii,box,column,csv,html,insert,json,line,list,markdown,qbox,quote,table,tabs, andtcl. - Personally, I prefer the
boxoutput mode because it's easier to read the contents compared to other modes but I don't want to remember to type.mode boxeverytime I open a SQLite db.
sqlite>.mode box
sqlite> select * from shakespear limit 5;
โโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Dataline โ Play โ PlayerLinenumber โ ActSceneLine โ Player โ PlayerLine โ
โโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ 1 โ Henry IV โ โ โ โ ACT I โ
โโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ 2 โ Henry IV โ โ โ โ SCENE I. London. The palace. โ
โโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ 3 โ Henry IV โ โ โ โ Enter KING HENRY, LORD JOHN OF LANCASTER, the EARL of WESTMO โ
โ โ โ โ โ โ RELAND, SIR WALTER BLUNT, and others โ
โโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ 4 โ Henry IV โ 1 โ 1.1.1 โ KING HENRY IV โ So shaken as we are, so wan with care, โ
โโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ 5 โ Henry IV โ 1 โ 1.1.2 โ KING HENRY IV โ Find we a time for frighted peace to pant, โ
โโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Anyways, instead of having to type .mode box every single time I open a SQLite db, I added the following alias to my shell profile:
alias sqlite='sqlite3 -cmd ".mode box"'
This alias sets the output mode to box automatically whenever I open a SQLite database.
finito.