couchdb_utilities
Advanced tools
Comparing version 1.0.12-prerelease to 1.0.12
60
index.js
@@ -16,3 +16,3 @@ exports.printMsg = function() { | ||
} | ||
}; | ||
}; //validateConnection | ||
@@ -27,3 +27,3 @@ exports.getServerVersion = function ( couchURL ) { | ||
} | ||
}; | ||
}; //getServerVersion | ||
@@ -38,3 +38,3 @@ exports.responseDuration = function ( couchURL ) { | ||
} | ||
}; | ||
}; //responseDuration | ||
@@ -47,3 +47,3 @@ // database Utilities | ||
return JSON.parse( Obj.responseString); | ||
}; | ||
}; //listDatabases | ||
@@ -60,3 +60,3 @@ | ||
} | ||
}; | ||
}; //databaseExists | ||
@@ -72,3 +72,3 @@ exports.createDatabase = function ( couchURL, databaseName ) { | ||
} | ||
}; | ||
}; //createDatabase | ||
@@ -84,3 +84,3 @@ exports.deleteDatabase = function ( couchURL, databaseName ) { | ||
} | ||
}; | ||
}; // deleteDatabase | ||
@@ -91,3 +91,3 @@ exports.getDatabaseDetails = function ( couchURL, databaseName ) { | ||
return JSON.parse( Obj.responseString); | ||
}; | ||
}; //getDatabaseDetails | ||
@@ -104,3 +104,3 @@ // Design Document Utilities | ||
return Obj.rows; | ||
}; | ||
}; //getDesignDocuments | ||
@@ -113,4 +113,20 @@ // Design Document Utilities | ||
return JSON.parse(Obj.responseString); | ||
}; | ||
}; //getDocumentbyID | ||
exports.getDocumentsUsingQuery = function ( couchURL, databaseName, queryString ) { | ||
var returnDocuments = [ ]; | ||
var couchDBURL = couchURL + "/" + databaseName + "/" + queryString; | ||
Obj = this.returnObjfromURL(couchDBURL); | ||
console.log(Obj); | ||
if ( Obj.responseCode == 404 ){ | ||
return false; | ||
} | ||
rows = JSON.parse ( Obj.responseString ).rows; | ||
for ( Counter = 0; Counter < rows.length; Counter++ ) { | ||
returnDocuments.push( rows[Counter].doc ); | ||
} | ||
return returnDocuments; | ||
}; //getDocumentsUsingQuery | ||
exports.createDocument = function ( couchURL, databaseName, document ) { | ||
@@ -128,7 +144,20 @@ var couchDBURL = couchURL + "/" + databaseName; | ||
} | ||
}; | ||
}; //createDocument | ||
exports.updateDocument = function ( couchURL, databaseName, document ) { | ||
var couchDBURL = couchURL + "/" + databaseName + "/" + JSON.parse( document )._id; | ||
var jsonPayload = { | ||
json: document | ||
}; | ||
Obj = this.callURL("PUT", couchDBURL, document ); | ||
if ( JSON.parse( Obj.responseString).ok == true ) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
}; //updateDocument | ||
exports.deleteDocument = function ( couchURL, databaseName, docID ) { | ||
var couchDBURL = couchURL + "/" + databaseName; | ||
// var document = this.getDocumentbyID( couchURL, databaseName, docID ); | ||
var rev = this.getDocumentbyID( couchURL, databaseName, docID )._rev; | ||
@@ -144,3 +173,3 @@ couchDBURL = couchURL + "/" + databaseName + "/" + docID + "?rev=" + rev; | ||
} | ||
}; | ||
}; //deleteDocument | ||
@@ -167,3 +196,3 @@ // Internal Methods | ||
}; | ||
}; // returnObjfromURL | ||
@@ -196,3 +225,2 @@ exports.callURL = function ( Method, URL, Payload, headers ) { | ||
return returnObj; | ||
}; | ||
}; // callURL |
{ | ||
"name": "couchdb_utilities", | ||
"version": "v1.0.12prerelease", | ||
"version": "v1.0.12", | ||
"description": "This package contains utilties to use and support couchdb environments.", | ||
@@ -13,3 +13,3 @@ "main": "index.js", | ||
"bugs": { | ||
"url": "https://github.com/hvetsa/couchdb_utilities" | ||
"url": "https://github.com/hvetsa/couchdb_utilities/issues" | ||
}, | ||
@@ -16,0 +16,0 @@ "license": "ISC", |
@@ -71,6 +71,5 @@ # Module under development. | ||
``` | ||
### Design Document Utilities | ||
``` | ||
var Array = couchUtils.getDesignDocuments ( couchURL, databaseName ) { | ||
var Array = couchUtils.getDesignDocuments ( couchURL, databaseName ); | ||
``` | ||
@@ -81,11 +80,19 @@ | ||
``` | ||
var Object = couchUtils.getDocumentbyID ( couchURL, databaseName, docID ) { | ||
var Object = couchUtils.getDocumentbyID ( couchURL, databaseName, docID ); | ||
``` | ||
#### get a document using Query | ||
``` | ||
var Object = couchUtils.getDocumentsUsingQuery( couchURL, databaseName, queryString ); | ||
``` | ||
#### create a Document | ||
``` | ||
var Boolean = couchUtils.createDocument( couchURL, databaseName, jsonString ) { | ||
var Boolean = couchUtils.createDocument( couchURL, databaseName, jsonString ); | ||
``` | ||
#### Update a Document | ||
``` | ||
var Boolean = couchUtils.updateDocument( couchURL, databaseName, jsonString ); | ||
``` | ||
#### delete a Document | ||
``` | ||
var Boolean = couchUtils.deleteDocument( couchURL, databaseName, docID ) { | ||
var Boolean = couchUtils.deleteDocument( couchURL, databaseName, docID ); | ||
``` |
76
test.js
@@ -1,1 +0,75 @@ | ||
console.log("test"); | ||
var couchUtils = require('couchdb_utilities'); | ||
var CouchURL = process.env.CouchURL; | ||
console.log("***********listDatabases**************"); | ||
console.log( couchUtils.listDatabases( CouchURL ) ); | ||
console.log("***********databaseExists**************"); | ||
console.log( couchUtils.databaseExists( CouchURL, "test_backup" ) ); | ||
console.log( couchUtils.databaseExists( CouchURL, "GhostDB" ) ); | ||
console.log("***********createDatabase**************"); | ||
console.log( couchUtils.createDatabase( CouchURL, "test" ) ); | ||
console.log( couchUtils.createDatabase( CouchURL, "testtemp" ) ); | ||
console.log( couchUtils.listDatabases( CouchURL ) ); | ||
console.log( couchUtils.deleteDatabase( CouchURL, "testtemp" ) ); | ||
console.log( couchUtils.listDatabases( CouchURL ) ); | ||
console.log("***********validateConnection**************"); | ||
console.log( couchUtils.validateConnection( CouchURL ) ); | ||
console.log("***********getServerVersion**************"); | ||
console.log( couchUtils.getServerVersion( CouchURL ) ); | ||
console.log("***********responseDuration**************"); | ||
console.log( couchUtils.responseDuration( CouchURL ) ); | ||
console.log("***********getDatabaseDetails**************"); | ||
console.log( couchUtils.getDatabaseDetails( CouchURL, "test_backup" ) ); | ||
console.log("***********getDesignDocuments**************"); | ||
console.log( couchUtils.getDesignDocuments( CouchURL, "test" ) ); | ||
console.log("***********getDocumentbyID**************"); | ||
console.log( couchUtils.getDocumentbyID( CouchURL, "test", "_design/View" ) ); | ||
console.log("***********createDocument**************"); | ||
console.log( couchUtils.createDocument( CouchURL, "test", '{"_id": "doc1", "okxbabc": "bkjdfbakj"}' ) ); | ||
console.log( couchUtils.createDocument( CouchURL, "test", '{"_id": "doc2", "okxbabc": "bkjdfbakj"}' ) ); | ||
console.log( couchUtils.getDocumentbyID( CouchURL, "test", "doc1" ) ); | ||
console.log( couchUtils.getDocumentbyID( CouchURL, "test", "doc2" ) ); | ||
console.log("***********updateDocument**************"); | ||
console.log( couchUtils.getDocumentbyID( CouchURL, "test", "updateDocumentTest" ) ); | ||
console.log( couchUtils.createDocument( CouchURL, "test", '{"_id": "updateDocumentTest", "revision": "One"}' ) ); | ||
console.log( couchUtils.getDocumentbyID( CouchURL, "test", "updateDocumentTest" ) ); | ||
Obj = couchUtils.getDocumentbyID( CouchURL, "test", "updateDocumentTest" ); | ||
Obj.revision = "Two"; | ||
console.log( couchUtils.updateDocument( CouchURL, "test", JSON.stringify ( Obj ) ) ); | ||
console.log( couchUtils.getDocumentbyID( CouchURL, "test", "updateDocumentTest" ) ); | ||
console.log( couchUtils.deleteDocument( CouchURL, "test", "updateDocumentTest" ) ); | ||
console.log( couchUtils.getDocumentbyID( CouchURL, "test", "updateDocumentTest" ) ); | ||
console.log("***********deleteDocument**************"); | ||
console.log( couchUtils.createDocument( CouchURL, "test", '{"_id": "doc3", "okxbabc": "bkjdfbakj"}' ) ); | ||
console.log( couchUtils.getDocumentbyID( CouchURL, "test", "doc3" ) ); | ||
console.log( couchUtils.deleteDocument( CouchURL, "test", "doc3" ) ); | ||
console.log( couchUtils.getDocumentbyID( CouchURL, "test", "doc3" ) ); | ||
console.log( couchUtils.getDocumentbyID( CouchURL, "test", "doc4" ) ); | ||
console.log( couchUtils.deleteDocument( CouchURL, "test", "doc4" ) ); | ||
console.log("***********getDocumentsUsingQuery**************"); | ||
console.log ( couchUtils.getDocumentsUsingQuery( CouchURL, "test", "/_design/Report/_search/Search?include_docs=true&limit=3&sort=[\"-reportTime\"]&query=docType:Report" ) ); | ||
console.log("***********End of Testing**************"); | ||
console.log("***************************************"); | ||
console.log("***************************************"); | ||
console.log("***************************************"); | ||
console.log("***************************************"); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
12965
222
1
97
2