stardog-js
Node.js library for communicating with the Stardog HTTP server.
Installation
$ npm i request$ npm i stardog-js
request
is defined as a peer-dependency and thus has to be installed separately.
Testing
Run Stardog HTTP server on http://localhost:5820.
$ npm test
Import
Using CommonJS
Requirements (Node.js >= 8.0.0).
const Stardog = ;
Using ESM
Use --experimental-modules flag and .mjs extension (Node.js >= 8.6.0).
;
Usage
Create instances
// Create instance with only endpoint (required option) const stardog = endpoint: 'http://localhost:5820'; // Create instance with credentials and database name (optional) const stardog = endpoint: 'http://localhost:5820' database: 'database' auth: user: 'user' pass: 'pass' ;
Invoke methods
// Credentials and database are optional,// this have lower priority than constructor settings const data = await stardog;
Examples
; const stardogAdminDatabase = endpoint: 'http://localhost:5820' database: 'database' auth: user: 'admin' pass: 'admin' ; const stardogAdmin = endpoint: 'http://localhost:5820' auth: user: 'admin' pass: 'admin' ; const stardog = endpoint: 'http://localhost:5820'; async { const data1 = await stardogAdminDatabase; const data2 = await stardogAdmin; const data3 = await stardog;};
API
Databases
createDatabase
Create new database.
stardog;
dropDatabase
Drop database.
stardog;
sizeDatabase
Get size database.
const size = await stardog;
listDatabases
Get list databases.
const databases = await stardog;
existsDatabase
Check exists database.
if await stardog console;
metaDatabase
Get metadata options for database.
// Returns all metadata options const meta = await stardog; /*options: { 'database.archetypes': '', 'database.connection.timeout': '', 'database.name': '', 'database.namespaces': '', 'database.online': '', 'database.time.creation': '', 'database.time.modification': '', 'icv.active.graphs': '', 'icv.consistency.automatic': '', 'icv.enabled': '', 'icv.reasoning.enabled': '', 'index.differential.enable.limit': '', 'index.differential.merge.limit': '', 'index.differential.size': '', 'index.literals.canonical': '', 'index.named.graphs': '', 'index.persist': '', 'index.persist.sync': '', 'index.size': '', 'index.statistics.update.automatic': '', 'index.type': '', 'preserve.bnode.ids': '', 'query.all.graphs': '', 'query.timeout': '', 'reasoning.approximate': '', 'reasoning.consistency.automatic': '', 'reasoning.punning.enabled': '', 'reasoning.sameas': '', 'reasoning.schema.graphs': '', 'reasoning.schema.timeout': '', 'reasoning.type': '', 'reasoning.virtual.graph.enabled': '', 'search.enabled': '', 'search.reindex.mode': '', 'spatial.enabled': '', 'strict.parsing': '', 'transaction.isolation': '', 'transaction.logging': ''}*/ // Get custom fields const meta = await stardog;
onDatabase
Bring the database online.
stardog;
offDatabase
Bring the database offline.
stardog;
copyDatabase
Copy database.
// Bring the database offline await stardog; // Copy database 'from' to database 'to' await stardog;
exportDatabase
Export database.
stardog; // Export database with accept stardog;
Graphs
dropGraph
Drop named graph.
stardog;
copyGraph
Copy named graph.
stardog;
moveGraph
Move named graph.
stardog;
addGraph
Insert data from source named graph to destination.
stardog;
listGraphs
Get list of named graphs.
const graphs = await stardog;
existsGraph
Check exists named graph.
const exists = await stardog;
Queries
query
Execute query.
const data = await stardog; // Set accept to 'text/boolean', returns true or false const data = await stardog; const data = await stardog; // Query to named graph 'tag:stardog:api:context:default' const data = await stardog; // Query to two named graphs const data = await stardog;
ask
Alias for query
with accept text/boolean
.
const data = await stardog; // Equal query const data = await stardog;
update
Execute update query.
stardog; stardog; // Insert to named graph 'urn:graph' stardog; // Remove from named graph 'urn:graph' stardog;