@tpluscode/sparql-builder
Version:
Simple JS library to build SPARQL queries
35 lines (34 loc) • 954 B
JavaScript
import { sparql } from '@tpluscode/rdf-string';
import { graph } from './execute.js';
import WHERE from './partials/WHERE.js';
import LIMIT from './partials/LIMIT.js';
import FROM from './partials/FROM.js';
import Builder from './index.js';
const builder = (strings, ...values) => ({
...Builder('CONSTRUCT'),
...graph,
...WHERE({
required: true,
}),
...LIMIT(),
...FROM(),
shorthand: false,
constructTemplate: sparql(strings, ...values),
_getTemplateResult() {
if (this.shorthand) {
return sparql `CONSTRUCT
${this.fromClause()}
WHERE { ${this.constructTemplate} }
${this.limitOffsetClause()}`;
}
return sparql `CONSTRUCT { ${this.constructTemplate} }
${this.fromClause()}
${this.whereClause()}
${this.limitOffsetClause()}`;
},
});
builder.WHERE = (strings, ...values) => ({
...builder(strings, ...values),
shorthand: true,
});
export const CONSTRUCT = builder;