public MlResult DeleteDocument(string documentUri, string database = null)
        {
            StartTimer();
            var result = MlRestApi.QueryMarkLogic(_connection, JavascriptQueryCreator.DeleteDocument(documentUri), database);

            StopTimer();
            return(result);
        }
        public MlResult QueryString(string query, string database = null)
        {
            StartTimer();
            var result = MlRestApi.QueryMarkLogic(_connection, query, database);

            StopTimer();
            return(result);
        }
        public MlResult IngestDocument <T>(T document, DocumentProperties properties, string database = null)
        {
            if (string.IsNullOrEmpty(properties.DocumentUri))
            {
                throw new ArgumentException("Properties.DocumentUri can not be empty");
            }
            StartTimer();
            var documentJson = JsonConvert.SerializeObject(document);

            var result = MlRestApi.QueryMarkLogic(_connection, JavascriptQueryCreator.IngestDocument(documentJson, properties), database);

            StopTimer();
            return(result);
        }
        public T GetDocument <T>(string docId, string database = null) where T : new()
        {
            StartTimer();
            var result = MlRestApi.QueryMarkLogic(_connection, string.Format("fn.doc('{0}')", docId), database);

            StopTimer();
            if (result.Success)
            {
                var deserialzedObject = JsonConvert.DeserializeObject <T>(result.StringResult);
                return(deserialzedObject);
            }

            throw new MarkLogicException("Exception while querying marklogic", result.Exception);
        }
        public T Query <T>(string query, string database = null) where T : new()
        {
            StartTimer();
            var result = MlRestApi.QueryMarkLogic(_connection, query, database);

            StopTimer();
            if (result.Success)
            {
                var deserialzedObject = JsonConvert.DeserializeObject <T>(result.StringResult);
                return(deserialzedObject);
            }

            throw new MarkLogicException("Exception while querying marklogic", result.Exception);
        }
        public DateTime?GetDocumentTimestamp(string docId, string database = null)
        {
            var query = $"var a = xdmp.documentTimestamp('{docId}');if(a!=null) fn.adjustDateTimeToTimezone(xdmp.timestampToWallclock(a));else null;";

            StartTimer();
            var result = MlRestApi.QueryMarkLogic(_connection, query, database);

            StopTimer();
            if (result.Success)
            {
                if (string.IsNullOrWhiteSpace(result.StringResult))
                {
                    return(null);
                }
                return(DateTime.ParseExact(result.StringResult.Trim(), "yyyy-MM-ddTHH:mm:ss.FFFFFFFK", null));
            }

            throw new MarkLogicException("Exception while querying marklogic", result.Exception);
        }