Skip to content

Commit

Permalink
Update connecting.md (#272)
Browse files Browse the repository at this point in the history
* Update connecting.md

* Added tip to dsn connections docs

* Updating connecting guide (#56)

* Update CHANGELOG.md

---------

Co-authored-by: Ido M <michael.ido@gmail.com>
  • Loading branch information
DaveOkpare and idomic authored Apr 5, 2023
1 parent 05d0322 commit b75b6f2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# CHANGELOG

## 0.7.1dev
* [Doc] Updating connecting guide (by @DaveOkpare) (#56)

## 0.7.0 (2023-04-05)

Expand Down
54 changes: 29 additions & 25 deletions doc/connecting.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,35 @@ Check out our guide for connecting to a database:
%load_ext sql
```

### DSN connections

```{tip}
It is recommended to use config file for connection as it's more secure and do not expose credentials.
```

To ensure the security of your credentials, you can store connection information in a configuration file, under a section name chosen to refer to your database.

For instance, suppose you have a configuration file named _dsn.ini_ that contains the following section:

```
[DB_CONFIG_1]
drivername=postgres
host=my.remote.host
port=5433
database=mydatabase
username=myuser
password=1234
```

then you can establish a connection to your database by running the following commands:

```
%config SqlMagic.dsn_filename='./dsn.ini'
%sql --section DB_CONFIG_1
```

+++

### Building connection string

One option is to use `getpass`, type your password, build your connection string and pass it to `%sql`:
Expand Down Expand Up @@ -114,31 +143,6 @@ environ["DATABASE_URL"] = f"postgresql://user:{password}@localhost/database"

+++

## DSN connections

Alternately, you can store connection info in a configuration file, under a section name chosen to refer to your database.

For example, if dsn.ini contains:

```
[DB_CONFIG_1]
drivername=postgres
host=my.remote.host
port=5433
database=mydatabase
username=myuser
password=1234
```

then you can:

```
%config SqlMagic.dsn_filename='./dsn.ini'
%sql --section DB_CONFIG_1
```

+++

## Using an existing `sqlalchemy.engine.Engine`

```{versionadded} 0.5.1
Expand Down

0 comments on commit b75b6f2

Please # to comment.