Skip to content

Commit

Permalink
fix: update queries with now bind
Browse files Browse the repository at this point in the history
  • Loading branch information
adlerfaulkner committed Mar 3, 2023
1 parent 04baacd commit 978e9d9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 32 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@comake/skl-js-engine",
"version": "0.3.1",
"version": "0.3.2",
"description": "Standard Knowledge Language Javascript Engine",
"keywords": [
"skl",
Expand Down
40 changes: 21 additions & 19 deletions src/storage/sparql/SparqlUpdateBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import type {
GraphQuads,
Triple,
InsertDeleteOperation,
SelectQuery,
UpdateOperation,
BindPattern,
} from 'sparqljs';
import {
rdfTypeNamedNode,
Expand Down Expand Up @@ -221,14 +221,22 @@ export class SparqlUpdateBuilder {
updates.push({
updateType: 'deletewhere',
delete: deletions,
} as InsertDeleteOperation);
});
}
if (insertions.length > 0) {
const insert = { updateType: 'insert', insert: insertions } as InsertDeleteOperation;
if (this.setTimestamps) {
insert.where = [ this.selectNow() ];
updates.push({
updateType: 'insertdelete',
delete: [],
insert: insertions,
where: [ this.bindNow() ],
});
} else {
updates.push({
updateType: 'insert',
insert: insertions,
});
}
updates.push(insert);
}
return updates;
}
Expand All @@ -241,21 +249,15 @@ export class SparqlUpdateBuilder {
};
}

private selectNow(): SelectQuery {
private bindNow(): BindPattern {
return {
type: 'query',
queryType: 'SELECT',
prefixes: {},
variables: [ now ],
where: [{
type: 'bind',
variable: now,
expression: {
type: 'operation',
operator: 'now',
args: [],
},
}],
type: 'bind',
variable: now,
expression: {
type: 'operation',
operator: 'now',
args: [],
},
};
}
}
2 changes: 1 addition & 1 deletion test/deploy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"main": "./dist/index.js",
"dependencies": {
"@comake/skl-js-engine": "file:./comake-skl-js-engine-0.3.1.tgz",
"@comake/skl-js-engine": "file:./comake-skl-js-engine-0.3.2.tgz",
"jsonld": "^6.0.0"
},
"devDependencies": {
Expand Down
15 changes: 6 additions & 9 deletions test/unit/storage/sparql/SparqlUpdateBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ describe('A SparqlUpdateBuilder', (): void => {
}],
},
{
updateType: 'insert',
updateType: 'insertdelete',
delete: [],
insert: [
{
type: 'graph',
Expand All @@ -217,21 +218,17 @@ describe('A SparqlUpdateBuilder', (): void => {
],
},
],
where: [{
type: 'query',
queryType: 'SELECT',
prefixes: {},
variables: [ now ],
where: [{
where: [
{
type: 'bind',
variable: now,
expression: {
type: 'operation',
operator: 'now',
args: [],
},
}],
}],
},
],
},
],
};
Expand Down

0 comments on commit 978e9d9

Please sign in to comment.