R/000-wrappers.R

Defines functions `rq_to_sql` `prql_to_pl` `prql_get_targets` `pl_to_rq` `compiler_version` `compile` `[[<-.savvy_prqlr__sealed` `$<-.savvy_prqlr__sealed` .savvy_extract_ptr

# Generated by savvy: do not edit by hand
#
# Note:
#   This wrapper file is named as `000-wrappers.R` so that this file is loaded
#   first, which allows users to override the functions defined here (e.g., a
#   print() method for an enum).

#' @useDynLib prqlr, .registration = TRUE
#' @keywords internal
NULL

# Check class and extract the external pointer embedded in the environment
.savvy_extract_ptr <- function(e, class) {
  if(is.null(e)) {
    return(NULL)
  }

  if(inherits(e, class)) {
    e$.ptr
  } else {
    msg <- paste0("Expected ", class, ", got ", class(e)[1])
    stop(msg, call. = FALSE)
  }
}

# Prohibit modifying environments

#' @export
`$<-.savvy_prqlr__sealed` <- function(x, name, value) {
  class <- gsub("__bundle$", "", class(x)[1])
  stop(class, " cannot be modified", call. = FALSE)
}

#' @export
`[[<-.savvy_prqlr__sealed` <- function(x, i, value) {
  class <- gsub("__bundle$", "", class(x)[1])
  stop(class, " cannot be modified", call. = FALSE)
}

#' @title Compile a PRQL query into a SQL query
#' @param prql_query a PRQL query string.
#' @param target a compile target name to use.
#' @param format a logical flag. Whether to format the SQL query.
#' @param signature_comment a logical flag. Whether to add a signature comment to the output SQL query.
#' @return a list contains a SQL string or an error message.
#' @noRd
`compile` <- function(`prql_query`, `target`, `format`, `signature_comment`, `display`) {
  .Call(savvy_compile__impl, `prql_query`, `target`, `format`, `signature_comment`, `display`)
}

#' @title prqlc's version
#' @return a prqlc's version string
#' @noRd
`compiler_version` <- function() {
  .Call(savvy_compiler_version__impl)
}

#' @noRd
`pl_to_rq` <- function(`pl_json`) {
  .Call(savvy_pl_to_rq__impl, `pl_json`)
}

#' @title Get available target names
#' @description Get available target names for the `target` option of the [prql_compile()] function.
#' @return a character vector of target names.
#' @examples
#' prql_get_targets()
#' @export
`prql_get_targets` <- function() {
  .Call(savvy_prql_get_targets__impl)
}

#' @noRd
`prql_to_pl` <- function(`prql_query`) {
  .Call(savvy_prql_to_pl__impl, `prql_query`)
}

#' @noRd
`rq_to_sql` <- function(`rq_json`) {
  .Call(savvy_rq_to_sql__impl, `rq_json`)
}

Try the prqlr package in your browser

Any scripts or data that you put into this service are public.

prqlr documentation built on April 12, 2025, 1:47 a.m.