Skip to content

sparna-git/spoty-query-engine

Repository files navigation

spoty-query-engine

This is an attempt to compile a Comunica Query Engine by following the tutorial at https://comunica.dev/docs/modify/getting_started/

Test the default query engine

  • npm init
  • Add dependency npm install @comunica/query-sparql
  • Copy code in query-sparql-engine.js
  • Make sure to use an "await" function
  • Run code with node query-sparql-engine.js

Test the use of a custom config

	const myEngine = await new QueryEngineFactory().create({
	    configPath: 'config/config.json', // Relative or absolute path 
	});
  • run with node query-custom.js

Test a link traversal config

	const myEngine = await new QueryEngineFactory().create({
	    // configPath: 'config/config.json', // Relative or absolute path 
	    configPath: 'config/config-spoty.json', // Relative or absolute path 
	});

	const bindingsStream = await myEngine.queryBindings(`
	  SELECT ?s ?p ?o WHERE {
	    ?s ?p ?o
	  } LIMIT 10`, {
	  sources: ['https://fragments.dbpedia.org/2015/en'],
	});
  • run with node query-custom-link-traversal.js

Compile as an NPM package

{
  ...
  "scripts": {
    ...
    "build:engine": "comunica-compile-config config/config-default.json > engine-default.js",
    "build:lib": "tsc",
    "build": "npm run build:lib && npm run build:engine",
    "prepare": "npm run build"
  },
}
  • Compile with npm run build:engine

  • Create lib folder

  • Add in lib folder QueryEngine.ts, QueryEngineFactory.ts, index.ts and index-browser.ts with the content as provided in the doc

  • Added entries in the package.json file:

"main": "lib/index.js",
  "types": "lib/index",
  "browser": {
    "./lib/index.js": "./lib/index-browser.js",
    "./lib/index.js.map": "./lib/index-browser.js.map"
  },
  • Added .npmignore and .gitignore as documented
  • Added files section in package.json as documented:
"files": [
    "components",
    "config",
    "bin/**/*.d.ts",
    "bin/**/*.js",
    "bin/**/*.js.map",
    "lib/**/*.d.ts",
    "lib/**/*.js",
    "lib/**/*.js.map",
    "engine-default.js"
  ]
  • added a tsconfig.json to allow Typescript compiling
  • added Typescript dependency : npm i typescript --save-dev
  • /!\ downgrade Typescript version to 5.5.4 to avoid error with LRUCache. See isaacs/node-lru-cache#354 (comment):
  "devDependencies": {
    "typescript": "5.5.4"
  }

Add as a dependency to the SPoTy project

cd ../spoty
npm link spoty-query-engine

Use the dependency:

  import { QueryEngine } from 'spoty-query-engine';

  const myEngine = new QueryEngine();

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published