You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Connect to a mysql database. Returns a [`MySQL.Connection`](#mysqlconnection) object to be passed to other API functions.
66
66
67
-
Options are passed via dictionary. The available keys are below and a descrition of the options can be found in the [MySQL documentation](https://dev.mysql.com/doc/refman/8.0/en/mysql-options.html).
67
+
Options are passed via dictionary. The available keys are below and a description of the options can be found in the [MySQL documentation](https://dev.mysql.com/doc/refman/8.0/en/mysql-options.html).
Execute an SQL statement and return the results in the `sink`, which can be any valid `Data.Sink` (interface from [DataStreams.jl](https://github.com/JuliaData/DataStreams.jl)). By default, a NamedTuple of Vectors is returned.
129
+
Execute an SQL statement and return the results as a MySQL.Query object (see [MySQL.Query](#mysqlquery)).
130
130
131
-
Passing `append=true` as a keyword argument will cause the resultset to be _appended_ to the sink instead of replacing.
132
-
133
-
To get the results as a `DataFrame`, you can just do `MySQL.query(conn, sql, DataFrame)`.
134
-
135
-
See list of DataStreams implementations [here](https://github.com/JuliaData/DataStreams.jl#list-of-known-implementations)
131
+
The results can be materialized as a data sink that implements the Tables.jl interface.
132
+
E.g. `MySQL.Query(conn, sql) |> DataFrame` or `MySQL.Query(conn, sql) |> columntable`
A prepared SQL statement that may contain `?` parameter placeholders.
169
166
170
-
A `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.
171
-
172
-
Bulk statement execution can be accomplished by "streaming" a param source like:
A `MySQL.Stmt` may then be executed by calling `MySQL.execute!(stmt, params)` where
168
+
`params` is a vector with the values to be bound to the `?` placeholders in the
169
+
original SQL statement. Params must be provided for every `?` and will be matched in the same order they
170
+
appeared in the original SQL statement.
177
171
178
-
where `source` is any valid `Data.Source` (from DataStreams.jl). As with `MySQL.execute!`, the `source` must provide enough params and will be matched in the same order.
172
+
Alternately, a source implementing the Tables.jl interface can be streamed by executing
173
+
`MySQL.execute!(itr, stmt)`. Each row must have a value for each param.
Execute an SQL statement and return a `MySQL.Query` object. Result rows can be iterated as NamedTuples via `Data.rows(query)` where `query` is the `MySQL.Query` object. Results can also be streamed to any valid `Data.Sink` via `Data.stream!(query, sink)`.
180
+
181
+
Execute an SQL statement and return a `MySQL.Query` object. Result rows can be iterated.
186
182
187
183
### Example
188
184
@@ -193,7 +189,7 @@ using DataFrames
193
189
194
190
conn = MySQL.connect("localhost", "root", "password", db ="test_db")
195
191
196
-
foo = MySQL.query(conn, """SELECT COUNT(*) FROM my_first_table;""", DataFrame)
192
+
foo = MySQL.query(conn, """SELECT COUNT(*) FROM my_first_table;""") |>DataFrame
197
193
num_foo = foo[1,1]
198
194
199
195
my_stmt = MySQL.Stmt(conn, """INSERT INTO my_second_table ('foo_id','foo_name') VALUES (?,?);""")
execute an sql statement and return the results in `sink`, which can be any valid `Data.Sink` (interface from DataStreams.jl), and `args...` are any necessary arguments to the sink. By default, a NamedTuple of Vectors are returned.
97
-
98
-
Passing `append=true` as a keyword argument will cause the resultset to be _appended_ to the sink instead of replacing.
99
-
100
-
To get the results as a `DataFrame`, you can just do `MySQL.query(conn, sql, DataFrame)`.
101
-
102
-
See list of DataStreams implementations [here](https://github.com/JuliaData/DataStreams.jl#list-of-known-implementations)
Prepare an SQL statement that may contain `?` parameter placeholders.
11
11
12
-
A `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.
12
+
A `MySQL.Stmt` may then be executed by calling `MySQL.execute!(stmt, params)` where
13
+
`params` is a vector with the values to be bound to the `?` placeholders in the
14
+
original SQL statement. Params must be provided for every `?` and will be matched in the same order they
15
+
appeared in the original SQL statement.
13
16
14
-
Bulk statement execution can be accomplished by "streaming" a param source like:
15
-
16
-
Data.stream!(source, stmt)
17
-
18
-
where `source` is any valid `Data.Source` (from DataStreams.jl). As with `MySQL.execute!`, the `source` must provide enough params and will be matched in the same order.
17
+
Alternately, a source implementing the Tables.jl interface can be streamed by executing
18
+
`MySQL.execute!(itr, stmt)`. Each row must have a value for each param.
execute an sql statement and return a `MySQL.Query` object. Result rows can be iterated as NamedTuples via `Data.rows(query)` where `query` is the `MySQL.Query` object. Results can also be streamed to any valid `Data.Sink` via `Data.stream!(query, sink)`.
67
+
Execute an SQL statement and return a `MySQL.Query` object. Result rows can be
68
+
iterated as NamedTuples via `Data.rows(query)` where `query` is the `MySQL.Query`
69
+
object.
70
+
71
+
To materialize the results as a `DataFrame`, use `MySQL.query(conn, sql) |> DataFrame`.
0 commit comments