Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/atomgraph/sparql-builder
Type-safe SPARQL query builder written in TypeScript
https://github.com/atomgraph/sparql-builder
javascript knowledge-graph linked-data query-builder rdf semantic-web sparql sparql-builder sparql-query-builder triplestore typescript
Last synced: about 1 month ago
JSON representation
Type-safe SPARQL query builder written in TypeScript
- Host: GitHub
- URL: https://github.com/atomgraph/sparql-builder
- Owner: AtomGraph
- Created: 2019-03-13T00:00:05.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T11:13:03.000Z (almost 2 years ago)
- Last Synced: 2024-11-14T16:48:25.144Z (about 1 month ago)
- Topics: javascript, knowledge-graph, linked-data, query-builder, rdf, semantic-web, sparql, sparql-builder, sparql-query-builder, triplestore, typescript
- Language: TypeScript
- Homepage:
- Size: 282 KB
- Stars: 16
- Watchers: 4
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sparql-builder
SPARQL query builder written in TypeScript. Can be used from both TypeScript and JavaScript, although type-safety is lost in JavaScript.It [exposes the following classes](dist/index.d.ts):
* `QueryBuilder` - builder base class
* `SelectBuilder` - `SELECT` query builder
* `DescribeBuilder` - `DESCRIBE` query builder## Build
The [`build-dist.sh`](build-dist.sh) script does the following:
* compiles the TypeScript code using `tsc`
* runs unit tests using `npm test`
* packages the library with `webpack`
- for use in the browser (`window` target, output in `dist/window`)
- for use with Node.js (`commonjs2` target, output in `dist/node`)## Usage
The builder is published as [`sparql-builder`](https://www.npmjs.com/package/sparql-builder) package on npm. Import it into your `package.json`:
```json
"dependencies": {
"sparql-builder": "^1.0.6"
}
```## Example:
Code in `test.ts`:
```typescript
import { SelectBuilder } from 'sparql-builder';let query = "SELECT ?s { ?s ?p ?o }";
let builder = SelectBuilder.fromString(query).
limit(42).
offset(66).
orderBy(SelectBuilder.ordering(SelectBuilder.var("s"), true)).
orderBy(SelectBuilder.ordering(SelectBuilder.var("p")));console.log(builder.toString());
```Output of `tsc && node test.js`:
```sparql
SELECT ?s WHERE { ?s ?p ?o. }
ORDER BY DESC (?s) (?p)
OFFSET 66
LIMIT 42
```