This is a shell for relational database based on scala inspired by scalikejdbc dbconsole. It helps you to execute sqls in a scala repl of Ammonite. When you want to count all of the rows of tables whose name contains some string of all of the databases immediately, what will you do? I’m not familiar with Procedure syntax and don’t know how write a sql for this, so I have to write a bash script. But now I can write simple scala to handle this problems.
- In dbshell, you can execute sqls as if in db shell client like mysql’s client.
"show databases"?
+--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+
- When a sql is returned with a error, dbshell only print the message since usually the syntax message can tell the problem.
But if you want to see the stacktrace, run dbe
dbe
@ dbe com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'row_counts' in 'field list' at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) at com.mysql.jdbc.Util.getInstance(Util.java:386) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624) ... ...
Currently dbshell is working in Linux and in Ammonite. The regular scala repl has some auto-completion problems when start it with -i params to start dbshell. So you need to install Ammonite first, than clone this repository and run “sbt packArchive” to generate executable bash file. It will be target/pack/bin/dbshell.