@cereusdb/standard 0.3.0 → 0.4.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 +84 -2
- package/dist/external.d.ts +199 -4
- package/dist/external.js +219 -4
- package/dist/index.d.ts +199 -4
- package/dist/index.js +219 -4
- package/dist/storage.d.ts +64 -0
- package/dist/storage.js +211 -0
- package/dist/wasm/cereusdb-external.d.ts +68 -1
- package/dist/wasm/cereusdb-external.js +253 -5
- package/dist/wasm/cereusdb.d.ts +68 -1
- package/dist/wasm/cereusdb.js +253 -5
- package/dist/wasm/cereusdb_bg.wasm +0 -0
- package/dist/wasm/cereusdb_bg.wasm.d.ts +12 -0
- package/package.json +1 -1
- /package/dist/wasm/snippets/{cereusdb-object-store-0da8c74e50551289 → cereusdb-object-store-6ee0e8370430462c}/inline0.js +0 -0
package/dist/storage.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
function splitPath(path) {
|
|
2
|
+
return path.split('/').filter((segment) => segment.length > 0);
|
|
3
|
+
}
|
|
4
|
+
function isNotFound(error) {
|
|
5
|
+
const name = error?.name;
|
|
6
|
+
return name === 'NotFoundError' || name === 'TypeMismatchError';
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Keeps files in memory. Useful for tests, Node.js, and environments without
|
|
10
|
+
* OPFS. Share one instance between CereusDB instances to simulate a reload.
|
|
11
|
+
*/
|
|
12
|
+
export class MemoryStorageBackend {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.files = new Map();
|
|
15
|
+
this.locks = new Set();
|
|
16
|
+
}
|
|
17
|
+
async readFile(path) {
|
|
18
|
+
const data = this.files.get(splitPath(path).join('/'));
|
|
19
|
+
return data ? data.slice() : null;
|
|
20
|
+
}
|
|
21
|
+
async writeFile(path, data) {
|
|
22
|
+
this.files.set(splitPath(path).join('/'), data.slice());
|
|
23
|
+
}
|
|
24
|
+
async remove(path) {
|
|
25
|
+
const key = splitPath(path).join('/');
|
|
26
|
+
for (const existing of [...this.files.keys()]) {
|
|
27
|
+
if (key === '' || existing === key || existing.startsWith(`${key}/`)) {
|
|
28
|
+
this.files.delete(existing);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async list(path) {
|
|
33
|
+
const prefix = splitPath(path).join('/');
|
|
34
|
+
const entries = new Set();
|
|
35
|
+
for (const key of this.files.keys()) {
|
|
36
|
+
if (prefix !== '' && !key.startsWith(`${prefix}/`)) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const rest = prefix === '' ? key : key.slice(prefix.length + 1);
|
|
40
|
+
const [head, ...tail] = rest.split('/');
|
|
41
|
+
entries.add(tail.length > 0 ? `${head}/` : head);
|
|
42
|
+
}
|
|
43
|
+
return [...entries].sort();
|
|
44
|
+
}
|
|
45
|
+
async lock(name) {
|
|
46
|
+
if (this.locks.has(name)) {
|
|
47
|
+
throw new Error('it is already open in another CereusDB instance');
|
|
48
|
+
}
|
|
49
|
+
this.locks.add(name);
|
|
50
|
+
}
|
|
51
|
+
async unlock(name) {
|
|
52
|
+
this.locks.delete(name);
|
|
53
|
+
}
|
|
54
|
+
/** All stored file paths (for inspection and tests). */
|
|
55
|
+
paths() {
|
|
56
|
+
return [...this.files.keys()].sort();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Stores databases in the Origin Private File System (OPFS). Used for
|
|
61
|
+
* `opfs://` locations by default when the browser supports OPFS.
|
|
62
|
+
*
|
|
63
|
+
* Opening a database takes a Web Lock, so a database can be open in only one
|
|
64
|
+
* tab or worker at a time.
|
|
65
|
+
*/
|
|
66
|
+
export class OPFSStorageBackend {
|
|
67
|
+
constructor(options = {}) {
|
|
68
|
+
this.releases = new Map();
|
|
69
|
+
this.directory = options.directory ?? 'cereusdb';
|
|
70
|
+
}
|
|
71
|
+
/** Whether OPFS is available in the current environment. */
|
|
72
|
+
static isSupported() {
|
|
73
|
+
return (typeof navigator !== 'undefined' &&
|
|
74
|
+
typeof navigator.storage?.getDirectory === 'function');
|
|
75
|
+
}
|
|
76
|
+
root() {
|
|
77
|
+
this.rootPromise ?? (this.rootPromise = navigator.storage
|
|
78
|
+
.getDirectory()
|
|
79
|
+
.then((root) => root.getDirectoryHandle(this.directory, { create: true })));
|
|
80
|
+
return this.rootPromise;
|
|
81
|
+
}
|
|
82
|
+
async directoryHandle(segments, create) {
|
|
83
|
+
let directory = await this.root();
|
|
84
|
+
for (const segment of segments) {
|
|
85
|
+
try {
|
|
86
|
+
directory = await directory.getDirectoryHandle(segment, { create });
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
if (isNotFound(error)) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return directory;
|
|
96
|
+
}
|
|
97
|
+
async readFile(path) {
|
|
98
|
+
const segments = splitPath(path);
|
|
99
|
+
const name = segments.pop();
|
|
100
|
+
if (name === undefined) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
const directory = await this.directoryHandle(segments, false);
|
|
104
|
+
if (directory === null) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
const file = await (await directory.getFileHandle(name)).getFile();
|
|
109
|
+
return new Uint8Array(await file.arrayBuffer());
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
if (isNotFound(error)) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async writeFile(path, data) {
|
|
119
|
+
const segments = splitPath(path);
|
|
120
|
+
const name = segments.pop();
|
|
121
|
+
if (name === undefined) {
|
|
122
|
+
throw new Error('writeFile requires a file path');
|
|
123
|
+
}
|
|
124
|
+
const directory = await this.directoryHandle(segments, true);
|
|
125
|
+
if (directory === null) {
|
|
126
|
+
throw new Error(`cannot create directory for ${path}`);
|
|
127
|
+
}
|
|
128
|
+
const handle = await directory.getFileHandle(name, { create: true });
|
|
129
|
+
if (typeof handle.createWritable === 'function') {
|
|
130
|
+
// Writes go to a swap file that replaces the original on close().
|
|
131
|
+
const writable = await handle.createWritable();
|
|
132
|
+
try {
|
|
133
|
+
await writable.write(data);
|
|
134
|
+
await writable.close();
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
await writable.abort().catch(() => undefined);
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
// Older Safari only supports synchronous access handles (in workers).
|
|
143
|
+
const createSyncAccessHandle = handle.createSyncAccessHandle;
|
|
144
|
+
if (typeof createSyncAccessHandle !== 'function') {
|
|
145
|
+
throw new Error('this browser cannot write OPFS files outside a worker');
|
|
146
|
+
}
|
|
147
|
+
const access = await createSyncAccessHandle.call(handle);
|
|
148
|
+
try {
|
|
149
|
+
access.truncate(0);
|
|
150
|
+
access.write(data, { at: 0 });
|
|
151
|
+
access.flush();
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
access.close();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
async remove(path) {
|
|
158
|
+
const segments = splitPath(path);
|
|
159
|
+
const name = segments.pop();
|
|
160
|
+
if (name === undefined) {
|
|
161
|
+
throw new Error('remove requires a path');
|
|
162
|
+
}
|
|
163
|
+
const directory = await this.directoryHandle(segments, false);
|
|
164
|
+
if (directory === null) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
await directory.removeEntry(name, { recursive: true });
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
if (!isNotFound(error)) {
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
async list(path) {
|
|
177
|
+
const directory = await this.directoryHandle(splitPath(path), false);
|
|
178
|
+
if (directory === null) {
|
|
179
|
+
return [];
|
|
180
|
+
}
|
|
181
|
+
const entries = [];
|
|
182
|
+
const iterable = directory;
|
|
183
|
+
for await (const [name, handle] of iterable.entries()) {
|
|
184
|
+
entries.push(handle.kind === 'directory' ? `${name}/` : name);
|
|
185
|
+
}
|
|
186
|
+
return entries.sort();
|
|
187
|
+
}
|
|
188
|
+
async lock(name) {
|
|
189
|
+
if (typeof navigator === 'undefined' || navigator.locks === undefined) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
await new Promise((resolve, reject) => {
|
|
193
|
+
navigator.locks
|
|
194
|
+
.request(name, { ifAvailable: true }, (lock) => {
|
|
195
|
+
if (lock === null) {
|
|
196
|
+
reject(new Error('it is open in another tab or worker'));
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
resolve();
|
|
200
|
+
// Hold the lock until unlock() resolves this promise.
|
|
201
|
+
return new Promise((release) => this.releases.set(name, release));
|
|
202
|
+
})
|
|
203
|
+
.catch(reject);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
async unlock(name) {
|
|
207
|
+
const release = this.releases.get(name);
|
|
208
|
+
this.releases.delete(name);
|
|
209
|
+
release?.();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
@@ -9,15 +9,65 @@ export class CereusDB {
|
|
|
9
9
|
private constructor();
|
|
10
10
|
free(): void;
|
|
11
11
|
[Symbol.dispose](): void;
|
|
12
|
+
/**
|
|
13
|
+
* Create (`create = true`) or attach a persistent database. Returns the
|
|
14
|
+
* database (catalog) name.
|
|
15
|
+
*/
|
|
16
|
+
attach_database(location: string, name: string | null | undefined, create: boolean, if_not_exists: boolean): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Describe all databases, schemas, tables and views as a JSON string.
|
|
19
|
+
*/
|
|
20
|
+
catalog_json(): Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Rewrite every table of a persistent database into a single segment.
|
|
23
|
+
*/
|
|
24
|
+
compact_database(name: string): Promise<void>;
|
|
12
25
|
/**
|
|
13
26
|
* Create a new CereusDB instance.
|
|
14
27
|
* Initializes DataFusion context and registers all spatial functions.
|
|
15
28
|
*/
|
|
16
29
|
static create(): CereusDB;
|
|
17
30
|
/**
|
|
18
|
-
*
|
|
31
|
+
* Detach a persistent database after writing pending changes.
|
|
32
|
+
*/
|
|
33
|
+
detach_database(name: string, if_exists: boolean): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Drop a database by name or location URL. Persistent databases are
|
|
36
|
+
* deleted from storage.
|
|
37
|
+
*/
|
|
38
|
+
drop_database(target: string, if_exists: boolean): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Drop a registered table. Call `flush()` to write the change when the
|
|
41
|
+
* table belongs to a persistent database.
|
|
19
42
|
*/
|
|
20
43
|
drop_table(table_name: string): void;
|
|
44
|
+
/**
|
|
45
|
+
* Run a query and encode the result as GeoParquet. `options` may set
|
|
46
|
+
* `compression` and `rowGroupSize`.
|
|
47
|
+
*/
|
|
48
|
+
export_geoparquet(query: string, options: any): Promise<Uint8Array>;
|
|
49
|
+
/**
|
|
50
|
+
* Write all pending changes of attached persistent databases.
|
|
51
|
+
*/
|
|
52
|
+
flush(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Insert Arrow IPC data (stream or file format) into a table, matching
|
|
55
|
+
* columns by name. Returns the number of inserted rows.
|
|
56
|
+
*/
|
|
57
|
+
insert_arrow(table_name: string, data: Uint8Array): Promise<number>;
|
|
58
|
+
/**
|
|
59
|
+
* Database locations stored in the backend for `scheme`, attached or not.
|
|
60
|
+
*/
|
|
61
|
+
list_database_locations(scheme: string): Promise<any>;
|
|
62
|
+
/**
|
|
63
|
+
* List all tables and views as `catalog.schema.table`.
|
|
64
|
+
*/
|
|
65
|
+
qualified_tables(): any;
|
|
66
|
+
/**
|
|
67
|
+
* Set the function `(filename, bytes, mimeType)` that receives files
|
|
68
|
+
* written by `COPY ... TO`. `null` removes it.
|
|
69
|
+
*/
|
|
70
|
+
register_export_handler(handler: any): void;
|
|
21
71
|
/**
|
|
22
72
|
* Register a GeoJSON string as a named table.
|
|
23
73
|
*/
|
|
@@ -51,6 +101,11 @@ export class CereusDB {
|
|
|
51
101
|
* The server must support CORS.
|
|
52
102
|
*/
|
|
53
103
|
register_remote_parquet(table_name: string, url: string): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Register the storage backend used for database locations with the given
|
|
106
|
+
* URL scheme (for example `opfs`).
|
|
107
|
+
*/
|
|
108
|
+
register_storage_backend(scheme: string, backend: any): void;
|
|
54
109
|
/**
|
|
55
110
|
* Execute a SQL query.
|
|
56
111
|
* Returns results as Arrow IPC bytes (Uint8Array).
|
|
@@ -88,8 +143,19 @@ export interface InitOutput {
|
|
|
88
143
|
readonly malloc: (a: number) => number;
|
|
89
144
|
readonly __wbg_cereusdb_free: (a: number, b: number) => void;
|
|
90
145
|
readonly _abort_js: () => void;
|
|
146
|
+
readonly cereusdb_attach_database: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => any;
|
|
147
|
+
readonly cereusdb_catalog_json: (a: number) => any;
|
|
148
|
+
readonly cereusdb_compact_database: (a: number, b: number, c: number) => any;
|
|
91
149
|
readonly cereusdb_create: () => [number, number, number];
|
|
150
|
+
readonly cereusdb_detach_database: (a: number, b: number, c: number, d: number) => any;
|
|
151
|
+
readonly cereusdb_drop_database: (a: number, b: number, c: number, d: number) => any;
|
|
92
152
|
readonly cereusdb_drop_table: (a: number, b: number, c: number) => [number, number];
|
|
153
|
+
readonly cereusdb_export_geoparquet: (a: number, b: number, c: number, d: any) => any;
|
|
154
|
+
readonly cereusdb_flush: (a: number) => any;
|
|
155
|
+
readonly cereusdb_insert_arrow: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
156
|
+
readonly cereusdb_list_database_locations: (a: number, b: number, c: number) => any;
|
|
157
|
+
readonly cereusdb_qualified_tables: (a: number) => [number, number, number];
|
|
158
|
+
readonly cereusdb_register_export_handler: (a: number, b: any) => [number, number];
|
|
93
159
|
readonly cereusdb_register_geojson: (a: number, b: number, c: number, d: number, e: number) => [number, number];
|
|
94
160
|
readonly cereusdb_register_geotiff_buffer: (a: number, b: number, c: number, d: number, e: number) => [number, number];
|
|
95
161
|
readonly cereusdb_register_object_stores: (a: number, b: any) => [number, number];
|
|
@@ -97,6 +163,7 @@ export interface InitOutput {
|
|
|
97
163
|
readonly cereusdb_register_parquet_table: (a: number, b: number, c: number, d: number, e: number, f: any) => any;
|
|
98
164
|
readonly cereusdb_register_raster_buffer: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number];
|
|
99
165
|
readonly cereusdb_register_remote_parquet: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
166
|
+
readonly cereusdb_register_storage_backend: (a: number, b: number, c: number, d: any) => [number, number];
|
|
100
167
|
readonly cereusdb_sql: (a: number, b: number, c: number) => any;
|
|
101
168
|
readonly cereusdb_sql_json: (a: number, b: number, c: number) => any;
|
|
102
169
|
readonly cereusdb_tables: (a: number) => [number, number, number];
|
|
@@ -2,7 +2,7 @@ import { createEnvImports, createWasiImports, setMemory } from "./env_shim.js?v=
|
|
|
2
2
|
const __env = createEnvImports();
|
|
3
3
|
const __wasi = createWasiImports();
|
|
4
4
|
/* @ts-self-types="./cereusdb.d.ts" */
|
|
5
|
-
import { cereusdbFetch, cereusdbSetFetchConcurrency } from './snippets/cereusdb-object-store-
|
|
5
|
+
import { cereusdbFetch, cereusdbSetFetchConcurrency } from './snippets/cereusdb-object-store-6ee0e8370430462c/inline0.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Main CereusDB instance for browser use.
|
|
@@ -32,6 +32,60 @@ export class CereusDB {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Create (`create = true`) or attach a persistent database. Returns the
|
|
37
|
+
* database (catalog) name.
|
|
38
|
+
* @param {string} location
|
|
39
|
+
* @param {string | null | undefined} name
|
|
40
|
+
* @param {boolean} create
|
|
41
|
+
* @param {boolean} if_not_exists
|
|
42
|
+
* @returns {Promise<string>}
|
|
43
|
+
*/
|
|
44
|
+
attach_database(location, name, create, if_not_exists) {
|
|
45
|
+
const ptr0 = passStringToWasm0(location, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
46
|
+
const len0 = WASM_VECTOR_LEN;
|
|
47
|
+
var ptr1 = isLikeNone(name) ? 0 : passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
48
|
+
var len1 = WASM_VECTOR_LEN;
|
|
49
|
+
let ret;
|
|
50
|
+
__wbg_termination_guard();
|
|
51
|
+
try {
|
|
52
|
+
ret = wasm.cereusdb_attach_database(this.__wbg_ptr, ptr0, len0, ptr1, len1, create, if_not_exists);;
|
|
53
|
+
} catch(e) {
|
|
54
|
+
__wbg_handle_catch(e);
|
|
55
|
+
}
|
|
56
|
+
return ret;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Describe all databases, schemas, tables and views as a JSON string.
|
|
60
|
+
* @returns {Promise<string>}
|
|
61
|
+
*/
|
|
62
|
+
catalog_json() {
|
|
63
|
+
let ret;
|
|
64
|
+
__wbg_termination_guard();
|
|
65
|
+
try {
|
|
66
|
+
ret = wasm.cereusdb_catalog_json(this.__wbg_ptr);;
|
|
67
|
+
} catch(e) {
|
|
68
|
+
__wbg_handle_catch(e);
|
|
69
|
+
}
|
|
70
|
+
return ret;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Rewrite every table of a persistent database into a single segment.
|
|
74
|
+
* @param {string} name
|
|
75
|
+
* @returns {Promise<void>}
|
|
76
|
+
*/
|
|
77
|
+
compact_database(name) {
|
|
78
|
+
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
79
|
+
const len0 = WASM_VECTOR_LEN;
|
|
80
|
+
let ret;
|
|
81
|
+
__wbg_termination_guard();
|
|
82
|
+
try {
|
|
83
|
+
ret = wasm.cereusdb_compact_database(this.__wbg_ptr, ptr0, len0);;
|
|
84
|
+
} catch(e) {
|
|
85
|
+
__wbg_handle_catch(e);
|
|
86
|
+
}
|
|
87
|
+
return ret;
|
|
88
|
+
}
|
|
35
89
|
/**
|
|
36
90
|
* Create a new CereusDB instance.
|
|
37
91
|
* Initializes DataFusion context and registers all spatial functions.
|
|
@@ -51,7 +105,45 @@ export class CereusDB {
|
|
|
51
105
|
return CereusDB.__wrap(ret[0]);
|
|
52
106
|
}
|
|
53
107
|
/**
|
|
54
|
-
*
|
|
108
|
+
* Detach a persistent database after writing pending changes.
|
|
109
|
+
* @param {string} name
|
|
110
|
+
* @param {boolean} if_exists
|
|
111
|
+
* @returns {Promise<void>}
|
|
112
|
+
*/
|
|
113
|
+
detach_database(name, if_exists) {
|
|
114
|
+
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
115
|
+
const len0 = WASM_VECTOR_LEN;
|
|
116
|
+
let ret;
|
|
117
|
+
__wbg_termination_guard();
|
|
118
|
+
try {
|
|
119
|
+
ret = wasm.cereusdb_detach_database(this.__wbg_ptr, ptr0, len0, if_exists);;
|
|
120
|
+
} catch(e) {
|
|
121
|
+
__wbg_handle_catch(e);
|
|
122
|
+
}
|
|
123
|
+
return ret;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Drop a database by name or location URL. Persistent databases are
|
|
127
|
+
* deleted from storage.
|
|
128
|
+
* @param {string} target
|
|
129
|
+
* @param {boolean} if_exists
|
|
130
|
+
* @returns {Promise<void>}
|
|
131
|
+
*/
|
|
132
|
+
drop_database(target, if_exists) {
|
|
133
|
+
const ptr0 = passStringToWasm0(target, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
134
|
+
const len0 = WASM_VECTOR_LEN;
|
|
135
|
+
let ret;
|
|
136
|
+
__wbg_termination_guard();
|
|
137
|
+
try {
|
|
138
|
+
ret = wasm.cereusdb_drop_database(this.__wbg_ptr, ptr0, len0, if_exists);;
|
|
139
|
+
} catch(e) {
|
|
140
|
+
__wbg_handle_catch(e);
|
|
141
|
+
}
|
|
142
|
+
return ret;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Drop a registered table. Call `flush()` to write the change when the
|
|
146
|
+
* table belongs to a persistent database.
|
|
55
147
|
* @param {string} table_name
|
|
56
148
|
*/
|
|
57
149
|
drop_table(table_name) {
|
|
@@ -68,6 +160,111 @@ export class CereusDB {
|
|
|
68
160
|
throw takeFromExternrefTable0(ret[0]);
|
|
69
161
|
}
|
|
70
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Run a query and encode the result as GeoParquet. `options` may set
|
|
165
|
+
* `compression` and `rowGroupSize`.
|
|
166
|
+
* @param {string} query
|
|
167
|
+
* @param {any} options
|
|
168
|
+
* @returns {Promise<Uint8Array>}
|
|
169
|
+
*/
|
|
170
|
+
export_geoparquet(query, options) {
|
|
171
|
+
const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
172
|
+
const len0 = WASM_VECTOR_LEN;
|
|
173
|
+
let ret;
|
|
174
|
+
__wbg_termination_guard();
|
|
175
|
+
try {
|
|
176
|
+
ret = wasm.cereusdb_export_geoparquet(this.__wbg_ptr, ptr0, len0, options);;
|
|
177
|
+
} catch(e) {
|
|
178
|
+
__wbg_handle_catch(e);
|
|
179
|
+
}
|
|
180
|
+
return ret;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Write all pending changes of attached persistent databases.
|
|
184
|
+
* @returns {Promise<void>}
|
|
185
|
+
*/
|
|
186
|
+
flush() {
|
|
187
|
+
let ret;
|
|
188
|
+
__wbg_termination_guard();
|
|
189
|
+
try {
|
|
190
|
+
ret = wasm.cereusdb_flush(this.__wbg_ptr);;
|
|
191
|
+
} catch(e) {
|
|
192
|
+
__wbg_handle_catch(e);
|
|
193
|
+
}
|
|
194
|
+
return ret;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Insert Arrow IPC data (stream or file format) into a table, matching
|
|
198
|
+
* columns by name. Returns the number of inserted rows.
|
|
199
|
+
* @param {string} table_name
|
|
200
|
+
* @param {Uint8Array} data
|
|
201
|
+
* @returns {Promise<number>}
|
|
202
|
+
*/
|
|
203
|
+
insert_arrow(table_name, data) {
|
|
204
|
+
const ptr0 = passStringToWasm0(table_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
205
|
+
const len0 = WASM_VECTOR_LEN;
|
|
206
|
+
const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
207
|
+
const len1 = WASM_VECTOR_LEN;
|
|
208
|
+
let ret;
|
|
209
|
+
__wbg_termination_guard();
|
|
210
|
+
try {
|
|
211
|
+
ret = wasm.cereusdb_insert_arrow(this.__wbg_ptr, ptr0, len0, ptr1, len1);;
|
|
212
|
+
} catch(e) {
|
|
213
|
+
__wbg_handle_catch(e);
|
|
214
|
+
}
|
|
215
|
+
return ret;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Database locations stored in the backend for `scheme`, attached or not.
|
|
219
|
+
* @param {string} scheme
|
|
220
|
+
* @returns {Promise<any>}
|
|
221
|
+
*/
|
|
222
|
+
list_database_locations(scheme) {
|
|
223
|
+
const ptr0 = passStringToWasm0(scheme, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
224
|
+
const len0 = WASM_VECTOR_LEN;
|
|
225
|
+
let ret;
|
|
226
|
+
__wbg_termination_guard();
|
|
227
|
+
try {
|
|
228
|
+
ret = wasm.cereusdb_list_database_locations(this.__wbg_ptr, ptr0, len0);;
|
|
229
|
+
} catch(e) {
|
|
230
|
+
__wbg_handle_catch(e);
|
|
231
|
+
}
|
|
232
|
+
return ret;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* List all tables and views as `catalog.schema.table`.
|
|
236
|
+
* @returns {any}
|
|
237
|
+
*/
|
|
238
|
+
qualified_tables() {
|
|
239
|
+
let ret;
|
|
240
|
+
__wbg_termination_guard();
|
|
241
|
+
try {
|
|
242
|
+
ret = wasm.cereusdb_qualified_tables(this.__wbg_ptr);;
|
|
243
|
+
} catch(e) {
|
|
244
|
+
__wbg_handle_catch(e);
|
|
245
|
+
}
|
|
246
|
+
if (ret[2]) {
|
|
247
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
248
|
+
}
|
|
249
|
+
return takeFromExternrefTable0(ret[0]);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Set the function `(filename, bytes, mimeType)` that receives files
|
|
253
|
+
* written by `COPY ... TO`. `null` removes it.
|
|
254
|
+
* @param {any} handler
|
|
255
|
+
*/
|
|
256
|
+
register_export_handler(handler) {
|
|
257
|
+
let ret;
|
|
258
|
+
__wbg_termination_guard();
|
|
259
|
+
try {
|
|
260
|
+
ret = wasm.cereusdb_register_export_handler(this.__wbg_ptr, handler);;
|
|
261
|
+
} catch(e) {
|
|
262
|
+
__wbg_handle_catch(e);
|
|
263
|
+
}
|
|
264
|
+
if (ret[1]) {
|
|
265
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
71
268
|
/**
|
|
72
269
|
* Register a GeoJSON string as a named table.
|
|
73
270
|
* @param {string} table_name
|
|
@@ -216,6 +413,26 @@ export class CereusDB {
|
|
|
216
413
|
}
|
|
217
414
|
return ret;
|
|
218
415
|
}
|
|
416
|
+
/**
|
|
417
|
+
* Register the storage backend used for database locations with the given
|
|
418
|
+
* URL scheme (for example `opfs`).
|
|
419
|
+
* @param {string} scheme
|
|
420
|
+
* @param {any} backend
|
|
421
|
+
*/
|
|
422
|
+
register_storage_backend(scheme, backend) {
|
|
423
|
+
const ptr0 = passStringToWasm0(scheme, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
424
|
+
const len0 = WASM_VECTOR_LEN;
|
|
425
|
+
let ret;
|
|
426
|
+
__wbg_termination_guard();
|
|
427
|
+
try {
|
|
428
|
+
ret = wasm.cereusdb_register_storage_backend(this.__wbg_ptr, ptr0, len0, backend);;
|
|
429
|
+
} catch(e) {
|
|
430
|
+
__wbg_handle_catch(e);
|
|
431
|
+
}
|
|
432
|
+
if (ret[1]) {
|
|
433
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
219
436
|
/**
|
|
220
437
|
* Execute a SQL query.
|
|
221
438
|
* Returns results as Arrow IPC bytes (Uint8Array).
|
|
@@ -439,6 +656,10 @@ function __wbg_get_imports() {
|
|
|
439
656
|
__wbg__wbg_cb_unref_6b5b6b8576d35cb1: function(arg0) {
|
|
440
657
|
arg0._wbg_cb_unref();
|
|
441
658
|
},
|
|
659
|
+
__wbg_apply_ac9afb97ca32f169: function(arg0, arg1, arg2) {
|
|
660
|
+
const ret = arg0.apply(arg1, arg2);
|
|
661
|
+
return ret;
|
|
662
|
+
},
|
|
442
663
|
__wbg_arrayBuffer_eb8e9ca620af2a19: function(arg0) {
|
|
443
664
|
const ret = arg0.arrayBuffer();
|
|
444
665
|
return ret;
|
|
@@ -451,11 +672,15 @@ function __wbg_get_imports() {
|
|
|
451
672
|
const ret = arg0.call(arg1);
|
|
452
673
|
return ret;
|
|
453
674
|
},
|
|
454
|
-
|
|
675
|
+
__wbg_call_f858478a02f9600f: function(arg0, arg1, arg2, arg3, arg4) {
|
|
676
|
+
const ret = arg0.call(arg1, arg2, arg3, arg4);
|
|
677
|
+
return ret;
|
|
678
|
+
},
|
|
679
|
+
__wbg_cereusdbFetch_34b005651b79ffa9: function(arg0) {
|
|
455
680
|
const ret = cereusdbFetch(arg0);
|
|
456
681
|
return ret;
|
|
457
682
|
},
|
|
458
|
-
|
|
683
|
+
__wbg_cereusdbSetFetchConcurrency_77cbd1646887d235: function(arg0) {
|
|
459
684
|
cereusdbSetFetchConcurrency(arg0 >>> 0);
|
|
460
685
|
},
|
|
461
686
|
__wbg_done_08ce71ee07e3bd17: function(arg0) {
|
|
@@ -490,6 +715,10 @@ function __wbg_get_imports() {
|
|
|
490
715
|
const ret = arg0.fetch(arg1);
|
|
491
716
|
return ret;
|
|
492
717
|
},
|
|
718
|
+
__wbg_from_4bdf88943703fd48: function(arg0) {
|
|
719
|
+
const ret = Array.from(arg0);
|
|
720
|
+
return ret;
|
|
721
|
+
},
|
|
493
722
|
__wbg_getRandomValues_3f44b700395062e5: function(arg0, arg1) {
|
|
494
723
|
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
495
724
|
},
|
|
@@ -504,6 +733,10 @@ function __wbg_get_imports() {
|
|
|
504
733
|
const ret = Reflect.get(arg0, arg1);
|
|
505
734
|
return ret;
|
|
506
735
|
},
|
|
736
|
+
__wbg_get_3ef1eba1850ade27: function(arg0, arg1) {
|
|
737
|
+
const ret = Reflect.get(arg0, arg1);
|
|
738
|
+
return ret;
|
|
739
|
+
},
|
|
507
740
|
__wbg_get_a8ee5c45dabc1b3b: function(arg0, arg1) {
|
|
508
741
|
const ret = arg0[arg1 >>> 0];
|
|
509
742
|
return ret;
|
|
@@ -609,6 +842,10 @@ function __wbg_get_imports() {
|
|
|
609
842
|
const ret = new Object();
|
|
610
843
|
return ret;
|
|
611
844
|
},
|
|
845
|
+
__wbg_new_from_slice_22da9388ac046e50: function(arg0, arg1) {
|
|
846
|
+
const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
|
|
847
|
+
return ret;
|
|
848
|
+
},
|
|
612
849
|
__wbg_new_typed_aaaeaf29cf802876: function(arg0, arg1) {
|
|
613
850
|
try {
|
|
614
851
|
var state0 = {a: arg0, b: arg1};
|
|
@@ -627,6 +864,10 @@ function __wbg_get_imports() {
|
|
|
627
864
|
state0.a = state0.b = 0;
|
|
628
865
|
}
|
|
629
866
|
},
|
|
867
|
+
__wbg_new_typed_bccac67128ed885a: function() {
|
|
868
|
+
const ret = new Array();
|
|
869
|
+
return ret;
|
|
870
|
+
},
|
|
630
871
|
__wbg_new_with_length_825018a1616e9e55: function(arg0) {
|
|
631
872
|
const ret = new Uint8Array(arg0 >>> 0);
|
|
632
873
|
return ret;
|
|
@@ -658,6 +899,10 @@ function __wbg_get_imports() {
|
|
|
658
899
|
__wbg_prototypesetcall_d62e5099504357e6: function(arg0, arg1, arg2) {
|
|
659
900
|
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
660
901
|
},
|
|
902
|
+
__wbg_push_e87b0e732085a946: function(arg0, arg1) {
|
|
903
|
+
const ret = arg0.push(arg1);
|
|
904
|
+
return ret;
|
|
905
|
+
},
|
|
661
906
|
__wbg_queueMicrotask_0c399741342fb10f: function(arg0) {
|
|
662
907
|
const ret = arg0.queueMicrotask;
|
|
663
908
|
return ret;
|
|
@@ -727,8 +972,11 @@ function __wbg_get_imports() {
|
|
|
727
972
|
const ret = arg0.value;
|
|
728
973
|
return ret;
|
|
729
974
|
},
|
|
975
|
+
__wbg_warn_69424c2d92a2fa73: function(arg0) {
|
|
976
|
+
console.warn(arg0);
|
|
977
|
+
},
|
|
730
978
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
731
|
-
// Cast intrinsic for `Closure(Closure { dtor_idx:
|
|
979
|
+
// Cast intrinsic for `Closure(Closure { dtor_idx: 7940, function: Function { arguments: [Externref], shim_idx: 25507, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
732
980
|
const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h8db467765ce434ac, wasm_bindgen__convert__closures_____invoke__h7573a8a64f443504);
|
|
733
981
|
return ret;
|
|
734
982
|
},
|