R/flt_query.R

Defines functions flt_query

Documented in flt_query

#' Create Flight Query
#'
#' Create a flight query object for use in \code{run} function
#'
#' This function uses a connection object to create a flight query object.
#' These can be manipulated using the \code{filter}, \code{select} and other
#' functions before passing to \code{run} to execute and return a dataframe.
#' This object won't work by itself - you will need to set a database, select elements
#' etc for it to work.
#'
#' @param conn A connection object generated by \code{connect}
#' @param ems_name A string, indicating the name of the EMS server. Will return an informative error if you use the wrong name.
#' @param data_file An string, indicating the name of the .db file where the query tree metadata will be stored locally.
#' @return A FltQuery object to be manipulated and then run.
#'
#' @examples
#' \dontrun{
#' conn <- connect("joe.bloggs", "mypassword")
#' qry <- flt_query(conn, "my-ems", data_file = "metadata.db")
#' }
#'
#' @export
flt_query <- function(conn, ems_name, data_file) {

    ems_name <- match.arg(ems_name, retrieve_ems_instances(conn), several.ok = FALSE)

    obj <- list()
    class(obj) <- 'FltQuery'
    # Instantiating other objects
    obj$connection <- conn
    obj$ems        <- ems(conn)
    obj$ems_id     <- get_id(obj$ems, ems_name)
    obj$flight     <- flight(conn, obj$ems_id, data_file)

    # object data
    obj$queryset <- list()
    obj$columns  <- list()
    obj <- reset(obj)

    return(obj)
  }
ge-flight-analytics/Rems documentation built on May 17, 2023, 8:02 a.m.