queryDbFromFile: Run a query against a database

Description Usage Arguments Details Value Examples

Description

This function allows you to run a query against a database, returning the results in a tibble.

Usage

1
queryDbFromFile(server, database, filename, ...)

Arguments

server

The name of the DSN for the server you want to connect to

database

The name of the database that you want to run the query against

filename

A path to a file to read the query from.

...

Named parameters to interpolate into the query

Details

The query is read from the file that is passed as an argument. See queryDb if you want to pass the query as a string instead.

The connection to the server is made by odbc and uses the name of a DSN to connect to. This removes any requirement to hard code in usernames, passwords and connection strings into files.

Parameters can be used in queries by either specifying each parameter and it's value after the query parameter, or by specifying all of the parameters in a named list.

Value

The results of the query as a tibble

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## Not run: 
queryDbFromFile("MyServerName", "MyDatabase", "file.sql")

queryDbFromFile("MyServerName",
                "MyDatabase",
                "file.sql",
                id = 1,
                date = Sys.Date())

params <- list(id = 1, date = Sys.Date())
queryDbFromFile("MyServerName",
                "MyDatabase",
                "file.sql",
                params)

## End(Not run)

tomjemmett/sqlhelpers documentation built on July 23, 2019, 6:41 p.m.