Skip to contents

Connect to a GlareDB database

Usage

glaredb_connect(
  data_dir_or_cloud_url = NULL,
  ...,
  spill_path = NULL,
  disable_tls = FALSE,
  cloud_addr = "https://console.glaredb.com",
  location = NULL,
  storage_options = NULL,
  env = parent.frame()
)

Arguments

data_dir_or_cloud_url

A character of path to a local GlareDB database or a cloud URL or NULL. If NULL, a in-memory database is used.

...

Ignored.

spill_path

TODO

disable_tls

TRUE or FALSE to indicating whether to disable TLS.

cloud_addr

A character of a GlareDB cloud URL.

location

TODO

storage_options

Named character vector of storage options or NULL (default).

env

The connected environment, an environment class or NULL (means the global env). GlareDB can resister some class of R objects inside the environment automatically, so you can access the objects inside this environment by the object name in the query. The default, the caller environment is used.

Value

GlareDB connection object

Examples

# Create a connection of in-memory database
con <- glaredb_connect()

# The print result shows the connected environment
con
#> GlareDB connection
#>   Connected to <environment: 0x5645ed6c4ff0>

# The connected environment can be accessed by `$.env`
con$.env
#> <environment: 0x5645ed6c4ff0>

# Create a table to the database and insert data
glaredb_execute("CREATE TABLE my_table (a int)", con)
glaredb_execute("INSERT INTO my_table VALUES (1), (2)", con)

# Query the data and assign the result to a variable
res <- glaredb_sql("SELECT * FROM my_table", con)

# Since the result `res` exists in the connected environment,
# it can be resolved by the object name in the query
exists("res", envir = con$.env)
#> [1] TRUE

glaredb_sql("SELECT * FROM res", con) |>
  as_glaredb_table()
#> ┌───────┐
#> │     a │
#> │    ── │
#> │ Int32 │
#> ╞═══════╡
#> │     1 │
#> │     2 │
#> └───────┘