#' @title insert
#' @description Inserts records into the database
#' @details Inserts records into the database, one at a time
#' @author Jared P. Lander
#' @export insert
#' @rdname insert
#' @param db An OrientDB Object generated by \code{\link{dbInfo}}
#' @param object A named list
#' @param type Type of database to be written, can only be 'document' (default) or 'graph'
#' @return A response object indicating success or failure
#' @examples
#' \dontrun{
#' db <- dbInfo(host='127.0.0.1', database='GratefulDeadConcerts',
#' username='admin', password='admin', port='2480')
#' # note, below where the list name is 'class', there should be an at-symbol in front of 'class'
#' # but the R engine will not allow this
#' insert(db, object=list('class'='V', type='song', song_type='cover', name='Super Cool Song'))
#' }
#'
insert <- function(db, object, type=c('document', 'graph'))
{
type <- match.arg(type)
# make sure it's a database object
assertthat::assert_that(is.OrientDB(db))
# for now we require object to be a list
assertthat::assert_that(is.list(object))
# make sure it's a named list
assertthat::assert_that(!is.null(names(object)))
assertthat::assert_that(length(names(object)) == length(object))
# build the URL for the POST command
theURL <- buildDBURL(db, type='document')
httr::POST(theURL, body=object, encode='json')
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.