Description Usage Arguments See Also Examples
Create query functions inside an environment. Multiple queries are added to the specified environment, identified by their names.
1 | load_queries(filename, env = parent.frame())
|
filename |
Character string. |
env |
Environment to load the queries into. Default is the calling environment. |
get_queries
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 | # A package implementing DBI methods must be available.
require(RSQLite)
cat("-- name: get-fruits",
"-- Get all fruits.",
"SELECT * FROM fruit",
"",
"-- name: green-fruits",
"-- Get green fruits.",
"SELECT * FROM fruit",
"WHERE color = 'green'",
file = "queries.sql",
sep = "\n")
# Load into global environment.
load_queries("queries.sql")
unlink("queries.sql")
conn <- dbConnect(SQLite(), ":memory:")
tbl <- data.frame(name = c("apple", "orange", "pineapple"),
color = c("green", "orange", "yellow"))
success <- dbWriteTable(conn, "fruit", tbl)
`get-fruits`(conn)
# name color
# 1 apple green
# 2 orange orange
# 3 pineapple yellow
dbDisconnect(conn)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.