Last active
November 4, 2015 17:34
-
-
Save aclemen1/15e45da9a1f874734a52 to your computer and use it in GitHub Desktop.
Accès aux données d'UNISIS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# `unisis/public/database` | |
```r | |
library(modulr) | |
"unisis/public/database" %imports% | |
"https://gist.githubusercontent.com/aclemen1/15e45da9a1f874734a52/raw/unisis-public-database.Rmd" | |
``` | |
## Definition | |
```{r} | |
library(modulr) | |
"modulr/vault" %digests% | |
"https://gist.githubusercontent.com/aclemen1/3fcc508cb40ddac6c1e3/raw/modulr-vault.Rmd" | |
"unisis/public/database" %requires% | |
list(vault = "modulr/vault", | |
credentials = "unisis/public/database_SECRET_") %provides% | |
function() { | |
library(DBI) | |
library(RMySQL) | |
if(credentials$client == "bec") { | |
user <- | |
vault$decrypt("m4ODLQ7+bnPjROwH6TiNgg==", credentials$client_key) | |
password <- | |
vault$decrypt("bZv91LcCcHl45q3ZXAWD9Q==", credentials$client_key) | |
} | |
get_table <- function(table_name, schema) { | |
conn <- RMySQL::dbConnect( | |
DBI::dbDriver("MySQL"), | |
user = user, | |
password = password, | |
host = vault$decrypt("5V78/RIttNpaxYby/mF10HBkIgO38fV6WpVkghTPPFM=", | |
credentials$general_key), | |
dbname = schema | |
) | |
on.exit(RMySQL::dbDisconnect(conn)) | |
query_string <- sprintf('SELECT * FROM %s."%s"', | |
schema, | |
table_name) | |
rs <- DBI::dbGetQuery(conn,query_string) | |
return(rs) | |
} | |
list( | |
get_table = get_table | |
) | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment