Package for interfacing with MySQL databases from Julia
The package is registered in
METADATA.jl and so can be installed with
The package is tested against the current Julia
0.6 release and nightly on Linux and OS X.
Contributions are very welcome, as are feature requests and suggestions. Please open an issue if you encounter any problems or would just like to ask a question.
MySQL.connect(host::String, user::String, passwd::String; db::String = "", port = "3306", socket::String = MySQL.API.MYSQL_DEFAULT_SOCKET, opts = Dict())
Connect to a mysql database, returns a
MySQL.Connection object to be passed to other API functions
MySQL.Connection object from the remote database:
Get the insert id of the most recently executed SQL statement:
MySQL.escape(conn::MySQL.Connection, str::String) -> String
Escape an SQL statement
MySQL.execute!(conn, sql) => # of affected rows
Execute an SQL statement without returning results (useful for DDL statements, update, delete, etc.)
MySQL.query(conn, sql, sink=Data.Table; append::Bool=false) => sink
Execute an SQL statement and return the results in
sink, which can be any valid
Data.Sink (interface from DataStreams.jl). By default, a NamedTuple of Vectors are returned.
append=true as a keyword argument will cause the resultset to be appended to the sink instead of replacing.
To get the results as a
DataFrame, you can just do
MySQL.query(conn, sql, DataFrame).
See list of DataStreams implementations here
MySQL.Query(conn, sql, sink=Data.Table; append::Bool=false) => MySQL.Query
execute an sql statement and return a
MySQL.Query object. Result rows can be iterated as NamedTuples via
query is the
MySQL.Query object. Results can also be streamed to any valid
MySQL.Stmt(conn, sql) => MySQL.Stmt
Prepare an SQL statement that may contain
? parameter placeholders.
MySQL.Stmt may then be executed by calling
MySQL.execute!(stmt, params) where
params are the values to be bound to the
? placeholders in the original SQL statement. Params must be provided for every
? and will be matched in the same order they appeared in the original SQL statement.
Bulk statement execution can be accomplished by "streaming" a param source like:
source is any valid
Data.Source (from DataStreams.jl). As with
source must provide enough params and will be matched in the same order.
6 days ago