Last active
May 4, 2016 13:44
-
-
Save kid/a8e183d6175b13dcbf51d7e3eda55911 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import request from 'request' | |
import SparqlHttp from 'sparql-http-client' | |
const endpointUrl = process.env.MU_SPARQL_ENDPOINT !== undefined | |
? process.env.MU_SPARQL_ENDPOINT | |
: 'http://database:8890/sparql' | |
function call(ctx, fn, query options) { | |
return new Promise((resolve, reject) => { | |
const requestCallback = (err, res) => { | |
if (err) { | |
reject(err) | |
} else if (res.statusCode >= 300) { | |
const err = new Error(`${res.statusCode} ${res.statusMessage}`) | |
err.res = res | |
reject(err) | |
} else { | |
resolve(res) | |
} | |
} | |
return fn.call(ctx, query, requestCallback, options) | |
}) | |
} | |
export const endpoint = new SparqlHttp({ | |
request: SparqlHttp.requestModuleRequest(request), | |
endpointUrl: endpointUrl, | |
updateUrl: endpointUrl | |
}) | |
export function constructQuery (query, options) { | |
return call(endpoint, endpoint.constructQuery, query, options) | |
} | |
export function selectQuery (query, options) { | |
return call(endpoint, endpoint.selectQuery, query, options) | |
} | |
export function updateQuery (query, options) { | |
return call(endpoint, endpoint.updateQuery, query, options) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment