## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  # Quack needs a running server and DuckDB 1.5.3 or newer, neither of which is
  # available when this vignette is built. The examples are shown with their
  # expected output rather than executed.
  eval = FALSE
)

## ----setup--------------------------------------------------------------------
# library(ducklake)
# library(dplyr)

## ----version-check------------------------------------------------------------
# packageVersion("duckdb")
# #> [1] '1.5.3'

## ----install------------------------------------------------------------------
# install_quack()
# #> Installed quack extension.
# #> Loaded quack extension.

## ----read---------------------------------------------------------------------
# adsl <- quack_query(
#   "quack:trial-server.example.org",
#   "SELECT * FROM trial.adsl",
#   token = "super_secret"
# )
# 
# adsl
# #>   USUBJID SAFFL AGE
# #> 1  01-001     Y  45
# #> 2  01-002     N  52

## ----analyze------------------------------------------------------------------
# adsl |>
#   group_by(SAFFL) |>
#   summarise(n = n(), mean_age = mean(AGE))
# #> # A tibble: 2 x 3
# #>   SAFFL     n mean_age
# #>   <chr> <int>    <dbl>
# #> 1 N         1       52
# #> 2 Y         1       45

## ----read-filtered------------------------------------------------------------
# quack_query(
#   "quack:trial-server.example.org",
#   "SELECT USUBJID, AGE FROM trial.adsl WHERE SAFFL = 'Y' AND AGE >= 18",
#   token = "super_secret"
# )
# #>   USUBJID AGE
# #> 1  01-001  45

## ----write--------------------------------------------------------------------
# quack_query(
#   "quack:trial-server.example.org",
#   "INSERT INTO trial.adsl VALUES ('01-099', 'Y', 70)",
#   token = "super_secret"
# )
# #>   Count
# #> 1     1

## ----attach-------------------------------------------------------------------
# attach_quack("warehouse", "quack:data.example.org", token = "super_secret")
# 
# get_ducklake_table("warehouse.sales") |>
#   filter(region == "EMEA") |>
#   collect()
# 
# detach_quack("warehouse")

## ----build-lake---------------------------------------------------------------
# attach_ducklake("trial", lake_path = "~/lakes/trial")
# 
# with_transaction(
#   create_table(mtcars, "vehicles"),
#   author = "You",
#   commit_message = "Seed the shared lake"
# )

## ----serve--------------------------------------------------------------------
# install_quack()
# quack_serve(token = "super_secret")
# #> Quack server listening on "quack:localhost".

## ----stop---------------------------------------------------------------------
# quack_stop()
# #> Quack server on "quack:localhost" stopped.

