-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconnections-pane.qmd
45 lines (30 loc) · 2.17 KB
/
connections-pane.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
---
title: "Connections Pane"
---
The Connections Pane allows you to explore database connections created within your R or Python sessions.
It also includes basic support for storing and managing connection strings for future usage.
![Connections Pane](images/connections-pane.png)
## Opening a connection using R
To open a connection in Positron Connections Pane, you need to connect to a database using any
package that supports the connections contract, such as [odbc](https://github.com/r-dbi/odbc), [sparklyr](https://github.com/rstudio/sparklyr),
[bigrquery](https://github.com/r-dbi/bigrquery), and others.
The Positron Connections Pane implements [RStudio's connections contract](https://rstudio.github.io/rstudio-extensions/connections-contract.html); this means that any package that works within RStudio's Connections Pane should work within the Positron Connections Pane.
Here is an example of how to open a connection using the [connections](https://github.com/rstudio/connections) package to open a SQLite connection:
``` r
tmp <- tempfile()
dir.create(tmp)
dbplyr::nycflights13_sqlite(path = tmp)
con <- connections::connection_open(RSQLite::SQLite(), file.path(tmp, "nycflights13.sqlite"))
```
You can also open an existing connection from the Variables Pane, as shown below for Python, and you can find more information about connecting to a specific database [from Posit Solutions Engineering](https://solutions.posit.co/connections/db/databases/).
## Opening a connection using Python
Currently we support connections created using the [sqlite3](https://docs.python.org/3/library/sqlite3.html) and [SQLAlchemy](https://www.sqlalchemy.org) modules.
To open a connection in the Connections Pane, create a top level object that represents the connection/engine.
``` python
import sqlite3
conn = sqlite3.connect("nycflights13.sqlite")
```
You can then either use `%connection_show conn` to open the connection in the Connections Pane or click on
the database icon that appears close to the object name in the Variables Pane.
![Variables Pane showing a connection object](images/connections-pane-variables-pane.png)
That will bring up the Connections Pane, allowing you to navigate the database.