{"id":15389343,"url":"https://github.com/tpluscode/sparql-builder","last_synced_at":"2025-04-14T00:37:41.907Z","repository":{"id":40676797,"uuid":"241647610","full_name":"tpluscode/sparql-builder","owner":"tpluscode","description":"Build SPARQL with string templates","archived":false,"fork":false,"pushed_at":"2025-03-10T22:33:22.000Z","size":2078,"stargazers_count":14,"open_issues_count":3,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T14:52:20.886Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://tpluscode.github.io/sparql-builder/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tpluscode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-19T14:50:12.000Z","updated_at":"2024-11-15T14:14:36.000Z","dependencies_parsed_at":"2024-05-06T11:29:13.978Z","dependency_job_id":"ca713d28-2bfc-4a30-9494-e542a4d76ca4","html_url":"https://github.com/tpluscode/sparql-builder","commit_stats":{"total_commits":234,"total_committers":5,"mean_commits":46.8,"dds":0.2435897435897436,"last_synced_commit":"c71e09a9d945b173a6c5be692eb934a6c5afcc50"},"previous_names":[],"tags_count":58,"template":false,"template_full_name":"tpluscode/ts-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpluscode%2Fsparql-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpluscode%2Fsparql-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpluscode%2Fsparql-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpluscode%2Fsparql-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tpluscode","download_url":"https://codeload.github.com/tpluscode/sparql-builder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248803806,"owners_count":21164122,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T15:00:08.895Z","updated_at":"2025-04-14T00:37:41.882Z","avatar_url":"https://github.com/tpluscode.png","language":"TypeScript","readme":"\u003e # @tpluscode/sparql-builder ![Test](https://github.com/tpluscode/sparql-builder/workflows/Test/badge.svg) [![codecov](https://codecov.io/gh/tpluscode/sparql-builder/branch/master/graph/badge.svg)](https://codecov.io/gh/tpluscode/sparql-builder) [![npm version](https://badge.fury.io/js/%40tpluscode%2Fsparql-builder.svg)](https://badge.fury.io/js/%40tpluscode%2Fsparql-builder)\n\nSimple library to create SPARQL queries with tagged ES Template Strings\n\n## How is it different from simply string concatenation/plain templates?\n\n1. Focuses on graph patterns. No need to remember exact syntax\n1. Still looks like SPARQL, having a familiar structure and little glue code\n1. Has the IDE provide syntactic hints of valid SPARQL keywords\n1. Ensures correct formatting of terms (URI nodes, literals variables) via [@tpluscode/rdf-string](https://github.com/tpluscode/rdf-string)\n1. Automatically shortens URIs with [`@zazuko/prefixes`](http://npm.im/@zazuko/prefixes)\n\n## Installation\n\n```\nnpm i -S @tpluscode/sparql-builder\n```\n\nTo be able to execute queries against a remote endpoint install a peer\ndependency:\n\n```\nnpm i -S sparql-http-client\n```\n\n## Usage\n\n### Build a SPARQL query string\n\n```js\nimport rdf from '@zazuko/env'\nimport { SELECT } from '@tpluscode/sparql-builder'\n\nconst ex = rdf.namespace('http://example.com/')\nconst { foaf } = rdf.ns\n\n/*\n    PREFIX foaf: \u003chttp://xmlns.com/foaf/0.1/\u003e\n\n    SELECT ?person ?name\n    FROM \u003chttp://example.com/People\u003e\n    WHERE \n    {\n      ?person a foaf:Person ;\n              foaf:name ?name .\n    }\n*/\nconst person = rdf.variable('person')\nconst query = \n  SELECT`${person} ?name`\n  .FROM(ex.People)\n  .WHERE`\n    ${person} a ${foaf.Person} ; \n              ${foaf.name} ?name .\n  `.build()\n```\n\n### Executing a query\n\nUsing [`sparql-http-client`](https://github.com/zazuko/sparql-http-client)\n\n```js\nimport rdf from '@zazuko/env'\nimport SparqlHttp from 'sparql-http-client'\nimport { ASK } from '@tpluscode/sparql-builder'\n\nconst { dbo } = rdf.ns\nconst dbr = rdf.namespace('http://dbpedia.org/resource/')\n\nconst client = new SparqlHttp({\n  factory: rdf,\n  endpointUrl: 'http://dbpedia.org/sparql',\n})\n\nconst scoobyDoo = dbr('Scooby-Doo')\n\n/*\n    PREFIX dbo: \u003chttp://dbpedia.org/ontology/\u003e\n\n    ASK {\n        \u003chttp://dbpedia.org/resource/Scooby-Doo\u003e a dbo:Person .\n    }\n */\nASK`${scoobyDoo} a ${dbo.Person}`\n  .execute(client)\n  .then(isScoobyAPerson =\u003e {\n    // Fun fact: DBpedia seems to claim that Scooby-Doo is indeed a Person...\n    return isScoobyAPerson\n  })\n```\n\n## Running examples\n\nThe example in [`docs/examples`](docs/examples) can be executed locally. To do so, first replace the package import to point to the repository root.\n\n```diff\n-const { /* */ } = require('@tpluscode/sparql-builder')\n+const { /* */ } = require('../..')\n```\n\nThen simply `npm run example`.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftpluscode%2Fsparql-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftpluscode%2Fsparql-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftpluscode%2Fsparql-builder/lists"}