@duckdb/node-api 1.3.2-alpha.25 → 1.3.2-alpha.26
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 +27 -8
- package/lib/DuckDBConnection.d.ts +2 -0
- package/lib/DuckDBConnection.js +3 -0
- package/lib/DuckDBFunctionInfo.d.ts +7 -0
- package/lib/DuckDBFunctionInfo.js +20 -0
- package/lib/DuckDBPreparedStatementWeakRefCollection.d.ts +1 -0
- package/lib/DuckDBPreparedStatementWeakRefCollection.js +6 -1
- package/lib/DuckDBScalarFunction.d.ts +29 -0
- package/lib/DuckDBScalarFunction.js +73 -0
- package/lib/duckdb.d.ts +4 -0
- package/lib/duckdb.js +4 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -17,14 +17,7 @@ available separately as [@duckdb/node-bindings](https://www.npmjs.com/package/@d
|
|
|
17
17
|
|
|
18
18
|
### Roadmap
|
|
19
19
|
|
|
20
|
-
Some features are not yet complete
|
|
21
|
-
* Appending default values row-by-row
|
|
22
|
-
* User-defined types & functions
|
|
23
|
-
* Profiling info
|
|
24
|
-
* Table description
|
|
25
|
-
* APIs for Arrow
|
|
26
|
-
|
|
27
|
-
See the [issues list on GitHub](https://github.com/duckdb/duckdb-node-neo/issues)
|
|
20
|
+
Some features are not yet complete. See the [issues list on GitHub](https://github.com/duckdb/duckdb-node-neo/issues)
|
|
28
21
|
for the most up-to-date roadmap.
|
|
29
22
|
|
|
30
23
|
### Supported Platforms
|
|
@@ -883,6 +876,32 @@ appender.flushSync();
|
|
|
883
876
|
|
|
884
877
|
See "Specifying Values" above for how to supply values to the appender.
|
|
885
878
|
|
|
879
|
+
### Scalar Functions
|
|
880
|
+
|
|
881
|
+
```ts
|
|
882
|
+
connection.registerScalarFunction(
|
|
883
|
+
DuckDBScalarFunction.create({
|
|
884
|
+
name: 'my_add',
|
|
885
|
+
mainFunction: (info, input, output) => {
|
|
886
|
+
const v0 = input.getColumnVector(0);
|
|
887
|
+
const v1 = input.getColumnVector(1);
|
|
888
|
+
for (let rowIndex = 0; rowIndex < input.rowCount; rowIndex++) {
|
|
889
|
+
output.setItem(
|
|
890
|
+
rowIndex,
|
|
891
|
+
v0.getItem(rowIndex) + v1.getItem(rowIndex)
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
output.flush();
|
|
895
|
+
},
|
|
896
|
+
returnType: INTEGER,
|
|
897
|
+
parameterTypes: [INTEGER, INTEGER],
|
|
898
|
+
})
|
|
899
|
+
);
|
|
900
|
+
const reader = await connection.runAndReadAll('select my_add(2, 3)');
|
|
901
|
+
const rows = reader.getRows();
|
|
902
|
+
// [ [ 5 ] ]
|
|
903
|
+
```
|
|
904
|
+
|
|
886
905
|
### Extract Statements
|
|
887
906
|
|
|
888
907
|
```ts
|
|
@@ -7,6 +7,7 @@ import { DuckDBPendingResult } from './DuckDBPendingResult';
|
|
|
7
7
|
import { DuckDBPreparedStatement } from './DuckDBPreparedStatement';
|
|
8
8
|
import { DuckDBResult } from './DuckDBResult';
|
|
9
9
|
import { DuckDBResultReader } from './DuckDBResultReader';
|
|
10
|
+
import { DuckDBScalarFunction } from './DuckDBScalarFunction';
|
|
10
11
|
import { DuckDBType } from './DuckDBType';
|
|
11
12
|
import { DuckDBValue } from './values';
|
|
12
13
|
export declare class DuckDBConnection {
|
|
@@ -34,4 +35,5 @@ export declare class DuckDBConnection {
|
|
|
34
35
|
extractStatements(sql: string): Promise<DuckDBExtractedStatements>;
|
|
35
36
|
private runUntilLast;
|
|
36
37
|
createAppender(table: string, schema?: string | null, catalog?: string | null): Promise<DuckDBAppender>;
|
|
38
|
+
registerScalarFunction(scalarFunction: DuckDBScalarFunction): void;
|
|
37
39
|
}
|
package/lib/DuckDBConnection.js
CHANGED
|
@@ -152,5 +152,8 @@ class DuckDBConnection {
|
|
|
152
152
|
async createAppender(table, schema, catalog) {
|
|
153
153
|
return new DuckDBAppender_1.DuckDBAppender(node_bindings_1.default.appender_create_ext(this.connection, catalog ?? null, schema ?? null, table));
|
|
154
154
|
}
|
|
155
|
+
registerScalarFunction(scalarFunction) {
|
|
156
|
+
node_bindings_1.default.register_scalar_function(this.connection, scalarFunction.scalar_function);
|
|
157
|
+
}
|
|
155
158
|
}
|
|
156
159
|
exports.DuckDBConnection = DuckDBConnection;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DuckDBFunctionInfo = void 0;
|
|
7
|
+
const node_bindings_1 = __importDefault(require("@duckdb/node-bindings"));
|
|
8
|
+
class DuckDBFunctionInfo {
|
|
9
|
+
function_info;
|
|
10
|
+
constructor(function_info) {
|
|
11
|
+
this.function_info = function_info;
|
|
12
|
+
}
|
|
13
|
+
getExtraInfo() {
|
|
14
|
+
return node_bindings_1.default.scalar_function_get_extra_info(this.function_info);
|
|
15
|
+
}
|
|
16
|
+
setError(error) {
|
|
17
|
+
node_bindings_1.default.scalar_function_set_error(this.function_info, error);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.DuckDBFunctionInfo = DuckDBFunctionInfo;
|
|
@@ -2,6 +2,7 @@ import { DuckDBPreparedStatement } from './DuckDBPreparedStatement';
|
|
|
2
2
|
import { DuckDBPreparedStatementCollection } from './DuckDBPreparedStatementCollection';
|
|
3
3
|
export declare class DuckDBPreparedStatementWeakRefCollection implements DuckDBPreparedStatementCollection {
|
|
4
4
|
preparedStatements: WeakRef<DuckDBPreparedStatement>[];
|
|
5
|
+
lastPruneTime: number;
|
|
5
6
|
add(prepared: DuckDBPreparedStatement): void;
|
|
6
7
|
destroySync(): void;
|
|
7
8
|
private prune;
|
|
@@ -3,8 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DuckDBPreparedStatementWeakRefCollection = void 0;
|
|
4
4
|
class DuckDBPreparedStatementWeakRefCollection {
|
|
5
5
|
preparedStatements = [];
|
|
6
|
+
lastPruneTime = 0;
|
|
6
7
|
add(prepared) {
|
|
7
|
-
|
|
8
|
+
const now = performance.now();
|
|
9
|
+
if (now - this.lastPruneTime > 1000) {
|
|
10
|
+
this.lastPruneTime = now;
|
|
11
|
+
this.prune();
|
|
12
|
+
}
|
|
8
13
|
this.preparedStatements.push(new WeakRef(prepared));
|
|
9
14
|
}
|
|
10
15
|
destroySync() {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import duckdb from '@duckdb/node-bindings';
|
|
2
|
+
import { DuckDBDataChunk } from './DuckDBDataChunk';
|
|
3
|
+
import { DuckDBFunctionInfo } from './DuckDBFunctionInfo';
|
|
4
|
+
import { DuckDBType } from './DuckDBType';
|
|
5
|
+
import { DuckDBVector } from './DuckDBVector';
|
|
6
|
+
export type DuckDBScalarMainFunction = (functionInfo: DuckDBFunctionInfo, inputDataChunk: DuckDBDataChunk, outputVector: DuckDBVector) => void;
|
|
7
|
+
export declare class DuckDBScalarFunction {
|
|
8
|
+
readonly scalar_function: duckdb.ScalarFunction;
|
|
9
|
+
constructor();
|
|
10
|
+
static create({ name, mainFunction, returnType, parameterTypes, varArgsType, specialHandling, volatile, extraInfo, }: {
|
|
11
|
+
name: string;
|
|
12
|
+
mainFunction: DuckDBScalarMainFunction;
|
|
13
|
+
returnType: DuckDBType;
|
|
14
|
+
parameterTypes?: readonly DuckDBType[];
|
|
15
|
+
varArgsType?: DuckDBType;
|
|
16
|
+
specialHandling?: boolean;
|
|
17
|
+
volatile?: boolean;
|
|
18
|
+
extraInfo?: object;
|
|
19
|
+
}): DuckDBScalarFunction;
|
|
20
|
+
destroySync(): void;
|
|
21
|
+
setName(name: string): void;
|
|
22
|
+
setMainFunction(mainFunction: DuckDBScalarMainFunction): void;
|
|
23
|
+
setReturnType(returnType: DuckDBType): void;
|
|
24
|
+
addParameter(parameterType: DuckDBType): void;
|
|
25
|
+
setVarArgs(varArgsType: DuckDBType): void;
|
|
26
|
+
setSpecialHandling(): void;
|
|
27
|
+
setVolatile(): void;
|
|
28
|
+
setExtraInfo(extraInfo: object): void;
|
|
29
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DuckDBScalarFunction = void 0;
|
|
7
|
+
const node_bindings_1 = __importDefault(require("@duckdb/node-bindings"));
|
|
8
|
+
const DuckDBDataChunk_1 = require("./DuckDBDataChunk");
|
|
9
|
+
const DuckDBFunctionInfo_1 = require("./DuckDBFunctionInfo");
|
|
10
|
+
const DuckDBVector_1 = require("./DuckDBVector");
|
|
11
|
+
class DuckDBScalarFunction {
|
|
12
|
+
scalar_function;
|
|
13
|
+
constructor() {
|
|
14
|
+
this.scalar_function = node_bindings_1.default.create_scalar_function();
|
|
15
|
+
}
|
|
16
|
+
static create({ name, mainFunction, returnType, parameterTypes, varArgsType, specialHandling, volatile, extraInfo, }) {
|
|
17
|
+
const scalarFunction = new DuckDBScalarFunction();
|
|
18
|
+
scalarFunction.setName(name);
|
|
19
|
+
scalarFunction.setMainFunction(mainFunction);
|
|
20
|
+
scalarFunction.setReturnType(returnType);
|
|
21
|
+
if (parameterTypes) {
|
|
22
|
+
for (const parameterType of parameterTypes) {
|
|
23
|
+
scalarFunction.addParameter(parameterType);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (varArgsType) {
|
|
27
|
+
scalarFunction.setVarArgs(varArgsType);
|
|
28
|
+
}
|
|
29
|
+
if (specialHandling) {
|
|
30
|
+
scalarFunction.setSpecialHandling();
|
|
31
|
+
}
|
|
32
|
+
if (volatile) {
|
|
33
|
+
scalarFunction.setVolatile();
|
|
34
|
+
}
|
|
35
|
+
if (extraInfo) {
|
|
36
|
+
scalarFunction.setExtraInfo(extraInfo);
|
|
37
|
+
}
|
|
38
|
+
return scalarFunction;
|
|
39
|
+
}
|
|
40
|
+
destroySync() {
|
|
41
|
+
node_bindings_1.default.destroy_scalar_function_sync(this.scalar_function);
|
|
42
|
+
}
|
|
43
|
+
setName(name) {
|
|
44
|
+
node_bindings_1.default.scalar_function_set_name(this.scalar_function, name);
|
|
45
|
+
}
|
|
46
|
+
setMainFunction(mainFunction) {
|
|
47
|
+
node_bindings_1.default.scalar_function_set_function(this.scalar_function, (info, input, output) => {
|
|
48
|
+
const functionInfo = new DuckDBFunctionInfo_1.DuckDBFunctionInfo(info);
|
|
49
|
+
const inputDataChunk = new DuckDBDataChunk_1.DuckDBDataChunk(input);
|
|
50
|
+
const outputVector = DuckDBVector_1.DuckDBVector.create(output, inputDataChunk.rowCount);
|
|
51
|
+
mainFunction(functionInfo, inputDataChunk, outputVector);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
setReturnType(returnType) {
|
|
55
|
+
node_bindings_1.default.scalar_function_set_return_type(this.scalar_function, returnType.toLogicalType().logical_type);
|
|
56
|
+
}
|
|
57
|
+
addParameter(parameterType) {
|
|
58
|
+
node_bindings_1.default.scalar_function_add_parameter(this.scalar_function, parameterType.toLogicalType().logical_type);
|
|
59
|
+
}
|
|
60
|
+
setVarArgs(varArgsType) {
|
|
61
|
+
node_bindings_1.default.scalar_function_set_varargs(this.scalar_function, varArgsType.toLogicalType().logical_type);
|
|
62
|
+
}
|
|
63
|
+
setSpecialHandling() {
|
|
64
|
+
node_bindings_1.default.scalar_function_set_special_handling(this.scalar_function);
|
|
65
|
+
}
|
|
66
|
+
setVolatile() {
|
|
67
|
+
node_bindings_1.default.scalar_function_set_volatile(this.scalar_function);
|
|
68
|
+
}
|
|
69
|
+
setExtraInfo(extraInfo) {
|
|
70
|
+
node_bindings_1.default.scalar_function_set_extra_info(this.scalar_function, extraInfo);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.DuckDBScalarFunction = DuckDBScalarFunction;
|
package/lib/duckdb.d.ts
CHANGED
|
@@ -5,13 +5,17 @@ export * from './DuckDBAppender';
|
|
|
5
5
|
export * from './DuckDBConnection';
|
|
6
6
|
export * from './DuckDBDataChunk';
|
|
7
7
|
export * from './DuckDBExtractedStatements';
|
|
8
|
+
export * from './DuckDBFunctionInfo';
|
|
8
9
|
export * from './DuckDBInstance';
|
|
10
|
+
export * from './DuckDBInstanceCache';
|
|
9
11
|
export * from './DuckDBLogicalType';
|
|
10
12
|
export * from './DuckDBMaterializedResult';
|
|
11
13
|
export * from './DuckDBPendingResult';
|
|
12
14
|
export * from './DuckDBPreparedStatement';
|
|
13
15
|
export * from './DuckDBPreparedStatementCollection';
|
|
14
16
|
export * from './DuckDBResult';
|
|
17
|
+
export * from './DuckDBResultReader';
|
|
18
|
+
export * from './DuckDBScalarFunction';
|
|
15
19
|
export * from './DuckDBType';
|
|
16
20
|
export * from './DuckDBTypeId';
|
|
17
21
|
export * from './DuckDBValueConverter';
|
package/lib/duckdb.js
CHANGED
|
@@ -26,13 +26,17 @@ __exportStar(require("./DuckDBAppender"), exports);
|
|
|
26
26
|
__exportStar(require("./DuckDBConnection"), exports);
|
|
27
27
|
__exportStar(require("./DuckDBDataChunk"), exports);
|
|
28
28
|
__exportStar(require("./DuckDBExtractedStatements"), exports);
|
|
29
|
+
__exportStar(require("./DuckDBFunctionInfo"), exports);
|
|
29
30
|
__exportStar(require("./DuckDBInstance"), exports);
|
|
31
|
+
__exportStar(require("./DuckDBInstanceCache"), exports);
|
|
30
32
|
__exportStar(require("./DuckDBLogicalType"), exports);
|
|
31
33
|
__exportStar(require("./DuckDBMaterializedResult"), exports);
|
|
32
34
|
__exportStar(require("./DuckDBPendingResult"), exports);
|
|
33
35
|
__exportStar(require("./DuckDBPreparedStatement"), exports);
|
|
34
36
|
__exportStar(require("./DuckDBPreparedStatementCollection"), exports);
|
|
35
37
|
__exportStar(require("./DuckDBResult"), exports);
|
|
38
|
+
__exportStar(require("./DuckDBResultReader"), exports);
|
|
39
|
+
__exportStar(require("./DuckDBScalarFunction"), exports);
|
|
36
40
|
__exportStar(require("./DuckDBType"), exports);
|
|
37
41
|
__exportStar(require("./DuckDBTypeId"), exports);
|
|
38
42
|
__exportStar(require("./DuckDBValueConverter"), exports);
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@duckdb/node-api",
|
|
3
|
-
"version": "1.3.2-alpha.
|
|
3
|
+
"version": "1.3.2-alpha.26",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@duckdb/node-bindings": "1.3.2-alpha.
|
|
8
|
+
"@duckdb/node-bindings": "1.3.2-alpha.26"
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|