UNPKG

@tpluscode/sparql-builder

Version:

Simple JS library to build SPARQL queries

27 lines (26 loc) 831 B
import { sparql } from '@tpluscode/rdf-string'; import prologue from './partials/prologue.js'; // eslint-disable-next-line no-unused-vars export default function Builder(type) { return { type, ...prologue(), build({ base, prefixes } = {}) { const queryResult = this._getTemplateResult().toString({ base, prefixes, }); if (this.prologueResult) { return `${this.prologueResult}\n\n${queryResult}`; } return queryResult; }, _toPartialString(options) { let result = this._getTemplateResult(); if (this.type === 'SELECT') { result = sparql `{ ${result} }`; } return result._toPartialString(options); }, }; }