@oxilite/d1 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/dist/driver.d.ts +24 -1
- package/dist/driver.js +35 -1
- package/package.json +2 -2
- package/wasm/node/oxilite_wasm_bg.wasm +0 -0
- package/wasm/web/oxilite_wasm_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -23,6 +23,20 @@ npx oxilite-d1 schema > migrations/0001_oxilite.sql # --no-graph-index
|
|
|
23
23
|
npx wrangler d1 migrations apply my-graph --remote
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
+
> **Upgrading to 0.3.0 from 0.2.x:** 0.3.0 adds the `schema_graphs`, `shapes_index`,
|
|
27
|
+
> `shapes_in` and `datalog_work` tables. A D1 store is opened with `open_existing`, so no
|
|
28
|
+
> DDL runs per request and an existing database will report `no such table: schema_graphs`
|
|
29
|
+
> until you apply a new migration. Regenerate and apply it:
|
|
30
|
+
>
|
|
31
|
+
> ```bash
|
|
32
|
+
> npx wrangler d1 migrations create my-graph oxilite-0-3-0
|
|
33
|
+
> npx oxilite-d1 schema > migrations/0002_oxilite-0-3-0.sql
|
|
34
|
+
> npx wrangler d1 migrations apply my-graph --remote
|
|
35
|
+
> ```
|
|
36
|
+
>
|
|
37
|
+
> Every statement is `CREATE TABLE IF NOT EXISTS`, so re-applying it is safe and your data
|
|
38
|
+
> is untouched.
|
|
39
|
+
|
|
26
40
|
## 2. Query it from a Worker
|
|
27
41
|
|
|
28
42
|
```ts
|
package/dist/driver.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CypherOptions, type CypherResult, type CypherValue, type CredentialOptions, type DocumentFilter, type Drift, type JsonLdOptions, type PresentationKeys, type StoredDocument, type Term, type DumpOptions, type LoadData, type LoadOptions, type Quad, type QueryOptions, type QueryResult, type TermLike } from "@oxilite/common";
|
|
1
|
+
import { type CypherOptions, type DatalogMaterializeResult, type DatalogOptions, type DatalogResult, type CypherResult, type CypherValue, type CredentialOptions, type DocumentFilter, type Drift, type JsonLdOptions, type PresentationKeys, type StoredDocument, type Term, type DumpOptions, type LoadData, type LoadOptions, type Quad, type QueryOptions, type QueryResult, type TermLike } from "@oxilite/common";
|
|
2
2
|
/** The subset of the Cloudflare D1 binding API used by oxilite. */
|
|
3
3
|
export interface D1PreparedStatementLike {
|
|
4
4
|
raw(): Promise<unknown[][]>;
|
|
@@ -26,6 +26,9 @@ export interface WasmEngine {
|
|
|
26
26
|
queryJson(sparql: string): WasmJob;
|
|
27
27
|
explain(sparql: string): string;
|
|
28
28
|
cypher(query: string, params?: string | null, options?: string | null): WasmJob;
|
|
29
|
+
datalog?(program: string, options?: string | null): WasmJob;
|
|
30
|
+
datalog_materialize?(program: string, options?: string | null): WasmJob;
|
|
31
|
+
explain_datalog?(program: string, options?: string | null): string;
|
|
29
32
|
explainCypher(query: string, params?: string | null, options?: string | null): string;
|
|
30
33
|
update(sparql: string, baseIri?: string | null): WasmJob;
|
|
31
34
|
explainUpdate(sparql: string): string;
|
|
@@ -85,6 +88,26 @@ export declare class D1Store {
|
|
|
85
88
|
* writing statement reads, then applies its changes as one D1 batch.
|
|
86
89
|
*/
|
|
87
90
|
cypher(query: string, params?: Record<string, CypherValue>, options?: CypherOptions): Promise<CypherResult>;
|
|
91
|
+
/**
|
|
92
|
+
* A Datalog program over the same quads: recursive rules with stratified negation,
|
|
93
|
+
* constraints and aggregation. A program whose recursion is linear is one SQL statement, so
|
|
94
|
+
* it costs one round trip here as it does anywhere; a component that has to be iterated
|
|
95
|
+
* costs one per round, which `rounds` reports.
|
|
96
|
+
*/
|
|
97
|
+
datalog(program: string, options?: DatalogOptions): Promise<DatalogResult>;
|
|
98
|
+
/**
|
|
99
|
+
* Stores what a Datalog program derives as inferences, in the table OWL 2 RL
|
|
100
|
+
* materialization uses, so SPARQL and Cypher see them with `includeInferred`. The writes
|
|
101
|
+
* are one D1 batch.
|
|
102
|
+
*/
|
|
103
|
+
datalogMaterialize(program: string, options?: DatalogOptions): Promise<DatalogMaterializeResult>;
|
|
104
|
+
/** How a Datalog program runs: its strata, the strategy per recursive component, the SQL. */
|
|
105
|
+
explainDatalog(program: string, options?: DatalogOptions): string;
|
|
106
|
+
/**
|
|
107
|
+
* The Datalog frontend is an opt-in feature of the WebAssembly core, so say which build is
|
|
108
|
+
* needed rather than failing with "not a function".
|
|
109
|
+
*/
|
|
110
|
+
private requireDatalog;
|
|
88
111
|
/** How a Cypher statement runs: its SPARQL, the SQL, and what runs in Rust. */
|
|
89
112
|
explainCypher(query: string, params?: Record<string, CypherValue>, options?: CypherOptions): string;
|
|
90
113
|
/** SPARQL query: `Map[]` for SELECT, `boolean` for ASK, `Quad[]` for CONSTRUCT/DESCRIBE, or a string with `results_format`. */
|
package/dist/driver.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// The core (WebAssembly) never touches the database. Each operation is a job: the driver
|
|
4
4
|
// feeds it the response of every request it asks for, until it is done. Atomic requests
|
|
5
5
|
// become one `db.batch()` — D1's only transaction.
|
|
6
|
-
import { JsonLdError, cypherResult, documentText, filterJson, fromJson, jsonLdError, storedDocument, loadDataToString, outputToResult, toJson, } from "@oxilite/common";
|
|
6
|
+
import { JsonLdError, cypherResult, datalogResult, documentText, filterJson, fromJson, jsonLdError, storedDocument, loadDataToString, outputToResult, toJson, } from "@oxilite/common";
|
|
7
7
|
/** A term hash collision (two different terms with the same 59-bit id). */
|
|
8
8
|
export class OxiliteCollisionError extends Error {
|
|
9
9
|
}
|
|
@@ -110,6 +110,40 @@ export class D1Store {
|
|
|
110
110
|
const out = (await this.run(this.engine.cypher(query, JSON.stringify(params), JSON.stringify(options))));
|
|
111
111
|
return cypherResult(out);
|
|
112
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* A Datalog program over the same quads: recursive rules with stratified negation,
|
|
115
|
+
* constraints and aggregation. A program whose recursion is linear is one SQL statement, so
|
|
116
|
+
* it costs one round trip here as it does anywhere; a component that has to be iterated
|
|
117
|
+
* costs one per round, which `rounds` reports.
|
|
118
|
+
*/
|
|
119
|
+
async datalog(program, options = {}) {
|
|
120
|
+
const datalog = this.requireDatalog(this.engine.datalog);
|
|
121
|
+
const out = (await this.run(datalog(program, JSON.stringify(options))));
|
|
122
|
+
return datalogResult(out);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Stores what a Datalog program derives as inferences, in the table OWL 2 RL
|
|
126
|
+
* materialization uses, so SPARQL and Cypher see them with `includeInferred`. The writes
|
|
127
|
+
* are one D1 batch.
|
|
128
|
+
*/
|
|
129
|
+
async datalogMaterialize(program, options = {}) {
|
|
130
|
+
const materialize = this.requireDatalog(this.engine.datalog_materialize);
|
|
131
|
+
return (await this.run(materialize(program, JSON.stringify(options))));
|
|
132
|
+
}
|
|
133
|
+
/** How a Datalog program runs: its strata, the strategy per recursive component, the SQL. */
|
|
134
|
+
explainDatalog(program, options = {}) {
|
|
135
|
+
return this.requireDatalog(this.engine.explain_datalog)(program, JSON.stringify(options));
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The Datalog frontend is an opt-in feature of the WebAssembly core, so say which build is
|
|
139
|
+
* needed rather than failing with "not a function".
|
|
140
|
+
*/
|
|
141
|
+
requireDatalog(method) {
|
|
142
|
+
if (method === undefined) {
|
|
143
|
+
throw new Error("this build of the oxilite WebAssembly core has no Datalog frontend; rebuild it with the `datalog` feature");
|
|
144
|
+
}
|
|
145
|
+
return method.bind(this.engine);
|
|
146
|
+
}
|
|
113
147
|
/** How a Cypher statement runs: its SPARQL, the SQL, and what runs in Rust. */
|
|
114
148
|
explainCypher(query, params = {}, options = {}) {
|
|
115
149
|
return this.engine.explainCypher(query, JSON.stringify(params), JSON.stringify(options));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxilite/d1",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "oxilite on Cloudflare D1 and Durable Objects: an Oxigraph-compatible SPARQL 1.1 and openCypher store (WebAssembly core)",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"test": "vitest run"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@oxilite/common": "0.
|
|
35
|
+
"@oxilite/common": "0.3.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"miniflare": "^4"
|
|
Binary file
|
|
Binary file
|