- Notifications
You must be signed in to change notification settings - Fork1
c42f/SQLREPL.jl
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A Julia REPL mode for PostgreSQL powered byReplMaker.jl,LibPQ.jl andSQLStrings.jl.
Install the package with Julia's Pkg mode:
pkg> add SQLREPLTo connect the REPL mode, you'll need a connection string for your Postgresdatabase. You can then use:
julia>using SQLREPLjulia> SQLREPL.connect("your_connection_string")REPL mode SQL initialized. Press ) to enter and backspace to exit."Prompt(\"SQL>\",...)"
Now press) to enter the REPL mode. You can create tables and do some simpledata insertion and extraction with standard SQL syntax:
SQL> create table foo (xtext, yint);SQL>insert into foovalues ('hi',1);SQL>insert into foovalues ('ho ho',2);SQL>select*from foo2×2 DataFrame Row │ x y │ String? Int32? ─────┼─────────────────1 │ hi12 │ ho ho2
Thanks to SQLStrings.jl, you can also interpolate local Julia values into yourexpression. Let's setmin_y in the JuliaMain module:
julia> min_y=2
And we can now use$min_y within our queries:
SQL>select*from foowhere y>= $min_y1×2 DataFrame Row │ x y │ String? Int32? ─────┼─────────────────1 │ ho ho2
For more complex data manipulation, the REPL mode can be combined withprogrammatic access via the normal Julia REPL:
julia>using LibPQ, SQLStringsjulia> conn= LibPQ.Connection("");julia>for y=1:10 msg="Hi$y" LibPQ.execute(conn,sql`insert into foo values ($msg,$y)`)end
thence
SQL>select*from foo12×2 DataFrame Row │ x y │ String? Int32? ─────┼─────────────────1 │ hi12 │ ho ho23 │ Hi114 │ Hi225 │ Hi336 │ Hi447 │ Hi558 │ Hi669 │ Hi7710 │ Hi8811 │ Hi9912 │ Hi1010
To edit multi-line SQL statements easily, surround your statement with brackets:
SQL> (select*from foowhere y>5and y<=7)2×2 DataFrame Row │ x y │ String? Int32? ─────┼─────────────────1 │ Hi662 │ Hi77
Alternatively, to insert a line, the usual key bindingALT+Enter can always be used.
The resultingDataFrame is available in theans variable back in the JuliaREPL. Starting with
SQL> (select*from foowhere y>5and y<=7);
we then have
julia> ans2×2 DataFrame Row │ x y │ String? Int32? ─────┼─────────────────1 │ Hi662 │ Hi77
To inspect table schema you can use thepsql-like meta-command\d:
SQL> \d foo2×5 DataFrame Row │ column_name data_type character_maximum_length column_default is_nullable │ String? String?Union{Missing, Int32} String? String? ─────┼───────────────────────────────────────────────────────────────────────────────1 │ xtext missing missing YES2 │ yinteger missing missing YES
In the future we might implement more of thepsql meta-commands.
This package arose froma discussion on Julia discourse.
About
A Julia REPL mode for SQL
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.