Skip to content

Commit 731f39c

Browse files
authored
Fix #160 by adding a Getting Started section to the manual (#162)
1 parent 30c7704 commit 731f39c

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

docs/src/index.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,32 @@
33
```@contents
44
```
55

6-
## High-level interface
6+
## Getting started
7+
8+
The MySQL.jl package provides a client library for Julia to interface with a mysql server. The package can be installed by doing:
9+
10+
```julia
11+
] add MySQL
12+
```
13+
14+
Once installed, you start using the package by making a connection to the mysql database by doing something like:
15+
16+
```julia
17+
conn = DBInterface.connect(MySQL.Connection, host, user, passwd)
18+
```
19+
20+
This utilizes the DBInterface.jl package method `connect` and passes in `MySQL.Connection` as the first argument to signal the type of database we're connecting to. `DBInterface.connect` also supports a host of options like the port to connect to, whether to use a socket, where an options file is located etc. To see the full list of supported keyword arguments, see the help for [`DBInterface.connect`](@ref).
21+
22+
Once connected, there are two ways to submit queries to the server:
23+
24+
* `stmt = DBInterface.prepare(conn, sql); DBInterface.execute(stmt, params)`: first prepare a SQL statement against the database, then execute it with optional params. This allows re-executing the same statement repeatedly in an efficient way.
25+
* `DBInterface.execute(conn, sql, params)`: directly execute a SQL statement against the database, optionally passing params to be bound to markers.
26+
27+
Both execution methods return a `Cursor` object that supports the [Tables.jl](https://juliadata.github.io/Tables.jl/stable/) interface, which allows materializing a query resultset in a number of ways, like `DataFrame(x)`, `CSV.write("results.csv", x)`, etc.
28+
29+
MySQL.jl attempts to provide a convenient `MySQL.load(table, conn, table_name)` function for generically loading Tables.jl-compatible sources into database tables. While the mysql API has some utilities for even making this possible, just note that it can be tricky to do generically in practice due to specific modifications needed in `CREATE TABLE` and column type statements.
30+
31+
## API reference
732
```@docs
833
DBInterface.connect
934
DBInterface.close!

0 commit comments

Comments
 (0)