Creates a SPARQL pattern that binds entity IRI(s) to a variable using either BIND or VALUES clause.

Uses BIND for single entities when targeting Oxigraph (better performance). Uses VALUES for multiple entities or other SPARQL engines (avoids SP031 error in Virtuoso).

Supports both full IRIs and prefixed names (e.g., "schema:Person" or "http://schema.org/Person").

import { variable } from '@rdfjs/data-model';
import { sparql } from '@tpluscode/sparql-builder';

// Single entity with BIND (Oxigraph) - full IRI
const pattern = createBindOrValuesPattern(
'http://example.org/entity1',
variable('subject'),
{ flavour: 'oxigraph' }
);

// With prefixed name
const pattern2 = createBindOrValuesPattern(
'ex:entity1',
variable('subject'),
{
flavour: 'oxigraph',
prefixMap: { 'ex': 'http://example.org/' }
}
);

// Multiple entities with VALUES
const pattern3 = createBindOrValuesPattern(
['http://example.org/entity1', 'http://example.org/entity2'],
variable('subject')
);

// Compose with other patterns
const typePattern = sparql`${variable('subject')} a <http://schema.org/Person> .`;
// Can be combined in WHERE clauses
  • Parameters

    • entityIRI: string | string[]

      Single IRI or array of IRIs to bind (can be full IRIs or prefixed names)

    • variable: Variable

      RDF Variable to bind the IRI(s) to

    • Optionaloptions: BindOrValuesOptions

      Configuration for BIND vs VALUES behavior and prefix mappings

    Returns SparqlTemplateResult

    SparqlTemplateResult pattern that can be composed with other sparql-builder patterns