@elaraai/east-node-io 0.0.1-beta.8 → 1.0.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/CLA.md +1 -1
- package/CONTRIBUTING.md +3 -3
- package/LICENSE.md +31 -0
- package/README.md +56 -19
- package/dist/{compression → src/compression}/gzip.d.ts +1 -1
- package/dist/src/compression/gzip.d.ts.map +1 -0
- package/dist/{compression → src/compression}/gzip.js +3 -3
- package/dist/src/compression/gzip.js.map +1 -0
- package/dist/{compression → src/compression}/index.d.ts +16 -16
- package/dist/src/compression/index.d.ts.map +1 -0
- package/dist/src/compression/index.js.map +1 -0
- package/dist/{compression → src/compression}/tar.d.ts +2 -2
- package/dist/src/compression/tar.d.ts.map +1 -0
- package/dist/{compression → src/compression}/tar.js +7 -7
- package/dist/src/compression/tar.js.map +1 -0
- package/dist/{compression → src/compression}/types.d.ts +10 -10
- package/dist/src/compression/types.d.ts.map +1 -0
- package/dist/src/compression/types.js.map +1 -0
- package/dist/{compression → src/compression}/zip.d.ts +3 -3
- package/dist/src/compression/zip.d.ts.map +1 -0
- package/dist/{compression → src/compression}/zip.js +4 -4
- package/dist/src/compression/zip.js.map +1 -0
- package/dist/src/connection/index.d.ts.map +1 -0
- package/dist/{connection → src/connection}/index.js +2 -2
- package/dist/src/connection/index.js.map +1 -0
- package/dist/{format → src/format}/index.d.ts +77 -77
- package/dist/src/format/index.d.ts.map +1 -0
- package/dist/src/format/index.js.map +1 -0
- package/dist/{format → src/format}/types.d.ts +53 -53
- package/dist/src/format/types.d.ts.map +1 -0
- package/dist/src/format/types.js.map +1 -0
- package/dist/{format → src/format}/xlsx.d.ts +20 -20
- package/dist/src/format/xlsx.d.ts.map +1 -0
- package/dist/{format → src/format}/xlsx.js +6 -6
- package/dist/src/format/xlsx.js.map +1 -0
- package/dist/{format → src/format}/xml.d.ts +54 -54
- package/dist/src/format/xml.d.ts.map +1 -0
- package/dist/{format → src/format}/xml.js +14 -14
- package/dist/src/format/xml.js.map +1 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js.map +1 -0
- package/dist/{nosql → src/nosql}/index.d.ts +20 -20
- package/dist/src/nosql/index.d.ts.map +1 -0
- package/dist/src/nosql/index.js.map +1 -0
- package/dist/{nosql → src/nosql}/mongodb.d.ts +5 -5
- package/dist/src/nosql/mongodb.d.ts.map +1 -0
- package/dist/{nosql → src/nosql}/mongodb.js +8 -8
- package/dist/src/nosql/mongodb.js.map +1 -0
- package/dist/{nosql → src/nosql}/redis.d.ts +5 -5
- package/dist/src/nosql/redis.d.ts.map +1 -0
- package/dist/{nosql → src/nosql}/redis.js +6 -6
- package/dist/src/nosql/redis.js.map +1 -0
- package/dist/{nosql → src/nosql}/types.d.ts +10 -10
- package/dist/src/nosql/types.d.ts.map +1 -0
- package/dist/src/nosql/types.js.map +1 -0
- package/dist/src/platform.d.ts.map +1 -0
- package/dist/{platform.js → src/platform.js} +2 -0
- package/dist/src/platform.js.map +1 -0
- package/dist/src/sql/access.d.ts +243 -0
- package/dist/src/sql/access.d.ts.map +1 -0
- package/dist/src/sql/access.js +427 -0
- package/dist/src/sql/access.js.map +1 -0
- package/dist/src/sql/index.d.ts +1112 -0
- package/dist/src/sql/index.d.ts.map +1 -0
- package/dist/{sql → src/sql}/index.js +296 -4
- package/dist/src/sql/index.js.map +1 -0
- package/dist/{sql → src/sql}/mysql.d.ts +110 -32
- package/dist/src/sql/mysql.d.ts.map +1 -0
- package/dist/{sql → src/sql}/mysql.js +207 -6
- package/dist/src/sql/mysql.js.map +1 -0
- package/dist/{sql → src/sql}/postgres.d.ts +110 -32
- package/dist/src/sql/postgres.d.ts.map +1 -0
- package/dist/{sql → src/sql}/postgres.js +199 -6
- package/dist/src/sql/postgres.js.map +1 -0
- package/dist/{sql → src/sql}/sqlite.d.ts +108 -30
- package/dist/src/sql/sqlite.d.ts.map +1 -0
- package/dist/{sql → src/sql}/sqlite.js +209 -6
- package/dist/src/sql/sqlite.js.map +1 -0
- package/dist/src/sql/types.d.ts +269 -0
- package/dist/src/sql/types.d.ts.map +1 -0
- package/dist/{sql → src/sql}/types.js +65 -1
- package/dist/src/sql/types.js.map +1 -0
- package/dist/{storage → src/storage}/index.d.ts +63 -63
- package/dist/src/storage/index.d.ts.map +1 -0
- package/dist/{storage → src/storage}/index.js +1 -1
- package/dist/src/storage/index.js.map +1 -0
- package/dist/{storage → src/storage}/s3.d.ts +56 -49
- package/dist/src/storage/s3.d.ts.map +1 -0
- package/dist/{storage → src/storage}/s3.js +24 -15
- package/dist/src/storage/s3.js.map +1 -0
- package/dist/{storage → src/storage}/types.d.ts +18 -18
- package/dist/src/storage/types.d.ts.map +1 -0
- package/dist/src/storage/types.js.map +1 -0
- package/dist/{transfer → src/transfer}/ftp.d.ts +10 -10
- package/dist/src/transfer/ftp.d.ts.map +1 -0
- package/dist/{transfer → src/transfer}/ftp.js +6 -6
- package/dist/src/transfer/ftp.js.map +1 -0
- package/dist/{transfer → src/transfer}/index.d.ts +40 -40
- package/dist/src/transfer/index.d.ts.map +1 -0
- package/dist/src/transfer/index.js.map +1 -0
- package/dist/{transfer → src/transfer}/sftp.d.ts +10 -10
- package/dist/src/transfer/sftp.d.ts.map +1 -0
- package/dist/{transfer → src/transfer}/sftp.js +6 -6
- package/dist/src/transfer/sftp.js.map +1 -0
- package/dist/{transfer → src/transfer}/types.d.ts +15 -15
- package/dist/src/transfer/types.d.ts.map +1 -0
- package/dist/src/transfer/types.js.map +1 -0
- package/package.json +37 -53
- package/dist/compression/gzip.d.ts.map +0 -1
- package/dist/compression/gzip.js.map +0 -1
- package/dist/compression/index.d.ts.map +0 -1
- package/dist/compression/index.js.map +0 -1
- package/dist/compression/tar.d.ts.map +0 -1
- package/dist/compression/tar.js.map +0 -1
- package/dist/compression/types.d.ts.map +0 -1
- package/dist/compression/types.js.map +0 -1
- package/dist/compression/zip.d.ts.map +0 -1
- package/dist/compression/zip.js.map +0 -1
- package/dist/connection/index.d.ts.map +0 -1
- package/dist/connection/index.js.map +0 -1
- package/dist/format/index.d.ts.map +0 -1
- package/dist/format/index.js.map +0 -1
- package/dist/format/types.d.ts.map +0 -1
- package/dist/format/types.js.map +0 -1
- package/dist/format/xlsx.d.ts.map +0 -1
- package/dist/format/xlsx.js.map +0 -1
- package/dist/format/xml.d.ts.map +0 -1
- package/dist/format/xml.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/nosql/index.d.ts.map +0 -1
- package/dist/nosql/index.js.map +0 -1
- package/dist/nosql/mongodb.d.ts.map +0 -1
- package/dist/nosql/mongodb.js.map +0 -1
- package/dist/nosql/redis.d.ts.map +0 -1
- package/dist/nosql/redis.js.map +0 -1
- package/dist/nosql/types.d.ts.map +0 -1
- package/dist/nosql/types.js.map +0 -1
- package/dist/platform.d.ts.map +0 -1
- package/dist/platform.js.map +0 -1
- package/dist/sql/index.d.ts +0 -777
- package/dist/sql/index.d.ts.map +0 -1
- package/dist/sql/index.js.map +0 -1
- package/dist/sql/mysql.d.ts.map +0 -1
- package/dist/sql/mysql.js.map +0 -1
- package/dist/sql/postgres.d.ts.map +0 -1
- package/dist/sql/postgres.js.map +0 -1
- package/dist/sql/sqlite.d.ts.map +0 -1
- package/dist/sql/sqlite.js.map +0 -1
- package/dist/sql/types.d.ts +0 -205
- package/dist/sql/types.d.ts.map +0 -1
- package/dist/sql/types.js.map +0 -1
- package/dist/storage/index.d.ts.map +0 -1
- package/dist/storage/index.js.map +0 -1
- package/dist/storage/s3.d.ts.map +0 -1
- package/dist/storage/s3.js.map +0 -1
- package/dist/storage/types.d.ts.map +0 -1
- package/dist/storage/types.js.map +0 -1
- package/dist/transfer/ftp.d.ts.map +0 -1
- package/dist/transfer/ftp.js.map +0 -1
- package/dist/transfer/index.d.ts.map +0 -1
- package/dist/transfer/index.js.map +0 -1
- package/dist/transfer/sftp.d.ts.map +0 -1
- package/dist/transfer/sftp.js.map +0 -1
- package/dist/transfer/types.d.ts.map +0 -1
- package/dist/transfer/types.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- /package/dist/{compression → src/compression}/index.js +0 -0
- /package/dist/{compression → src/compression}/types.js +0 -0
- /package/dist/{connection → src/connection}/index.d.ts +0 -0
- /package/dist/{format → src/format}/index.js +0 -0
- /package/dist/{format → src/format}/types.js +0 -0
- /package/dist/{index.d.ts → src/index.d.ts} +0 -0
- /package/dist/{index.js → src/index.js} +0 -0
- /package/dist/{nosql → src/nosql}/index.js +0 -0
- /package/dist/{nosql → src/nosql}/types.js +0 -0
- /package/dist/{platform.d.ts → src/platform.d.ts} +0 -0
- /package/dist/{storage → src/storage}/types.js +0 -0
- /package/dist/{transfer → src/transfer}/index.js +0 -0
- /package/dist/{transfer → src/transfer}/types.js +0 -0
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @packageDocumentation
|
|
12
12
|
*/
|
|
13
|
-
import { BlobType, BooleanType, DateTimeType, East, FloatType, IntegerType, isValueOf, match, NullType, SortedMap, StringType as EastStringType, variant } from "@elaraai/east";
|
|
13
|
+
import { ArrayType, BlobType, BooleanType, DateTimeType, East, FloatType, IntegerType, isTypeValueEqual, isValueOf, match, NullType, OptionType, SortedMap, StringType as EastStringType, toEastTypeValue, variant } from "@elaraai/east";
|
|
14
14
|
import { EastError } from "@elaraai/east/internal";
|
|
15
15
|
import pg from 'pg';
|
|
16
16
|
import { createHandle, getConnection, closeHandle, closeAllHandles } from '../connection/index.js';
|
|
@@ -129,6 +129,76 @@ export const postgres_connect = East.asyncPlatform("postgres_connect", [Postgres
|
|
|
129
129
|
* - Parameters prevent SQL injection attacks
|
|
130
130
|
*/
|
|
131
131
|
export const postgres_query = East.asyncPlatform("postgres_query", [ConnectionHandleType, StringType, SqlParametersType], SqlResultType);
|
|
132
|
+
/**
|
|
133
|
+
* Executes a SELECT query with user-defined return type.
|
|
134
|
+
*
|
|
135
|
+
* Runs a SELECT query against a PostgreSQL database with parameter binding and
|
|
136
|
+
* returns results as an array of typed rows. The return type is generic,
|
|
137
|
+
* allowing users to specify the expected row structure for type-safe access.
|
|
138
|
+
*
|
|
139
|
+
* This is a generic platform function for the East language, enabling type-safe
|
|
140
|
+
* SELECT queries in East programs running on Node.js.
|
|
141
|
+
*
|
|
142
|
+
* @typeParam T - The expected row type for query results
|
|
143
|
+
* @param handle - Connection handle from postgres_connect()
|
|
144
|
+
* @param sql - SQL SELECT query string with $1, $2, etc. placeholders
|
|
145
|
+
* @param params - Query parameters as SqlParameterType array
|
|
146
|
+
* @returns Array of rows matching the specified type T
|
|
147
|
+
*
|
|
148
|
+
* @throws {EastError} When query fails due to:
|
|
149
|
+
* - Invalid connection handle (location: "postgres_select")
|
|
150
|
+
* - SQL syntax errors (location: "postgres_select")
|
|
151
|
+
* - Query is not a SELECT (location: "postgres_select")
|
|
152
|
+
* - Type coercion failure (location: "postgres_select")
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* import { East, NullType, StructType, StringType, IntegerType, variant } from "@elaraai/east";
|
|
157
|
+
* import { SQL } from "@elaraai/east-node-io";
|
|
158
|
+
*
|
|
159
|
+
* // Define the expected row type
|
|
160
|
+
* const UserRowType = StructType({
|
|
161
|
+
* id: IntegerType,
|
|
162
|
+
* name: StringType,
|
|
163
|
+
* email: StringType,
|
|
164
|
+
* });
|
|
165
|
+
*
|
|
166
|
+
* const queryUsers = East.function([], NullType, ($) => {
|
|
167
|
+
* const config = $.let({
|
|
168
|
+
* host: "localhost",
|
|
169
|
+
* port: 5432n,
|
|
170
|
+
* database: "myapp",
|
|
171
|
+
* user: "postgres",
|
|
172
|
+
* password: "secret",
|
|
173
|
+
* ssl: variant('none', null),
|
|
174
|
+
* maxConnections: variant('none', null),
|
|
175
|
+
* });
|
|
176
|
+
*
|
|
177
|
+
* const conn = $.let(SQL.Postgres.connect(config));
|
|
178
|
+
*
|
|
179
|
+
* // Query with typed results - returns Array<UserRowType>
|
|
180
|
+
* const users = $.let(SQL.Postgres.select([UserRowType], conn,
|
|
181
|
+
* "SELECT id, name, email FROM users WHERE active = $1",
|
|
182
|
+
* [variant('Boolean', true)]
|
|
183
|
+
* ));
|
|
184
|
+
* // users is typed as Array<{ id: bigint, name: string, email: string }>
|
|
185
|
+
*
|
|
186
|
+
* $(SQL.Postgres.close(conn));
|
|
187
|
+
* $.return(null);
|
|
188
|
+
* });
|
|
189
|
+
*
|
|
190
|
+
* const compiled = East.compileAsync(queryUsers.toIR(), SQL.Postgres.Implementation);
|
|
191
|
+
* await compiled();
|
|
192
|
+
* ```
|
|
193
|
+
*
|
|
194
|
+
* @remarks
|
|
195
|
+
* - Only SELECT queries are supported (use postgres_query for INSERT/UPDATE/DELETE)
|
|
196
|
+
* - Uses $1, $2, $3, etc. for parameter placeholders
|
|
197
|
+
* - Row type T should match the structure of selected columns
|
|
198
|
+
* - All PostgreSQL data types are mapped to appropriate East types
|
|
199
|
+
* - NULL values are preserved in the result
|
|
200
|
+
*/
|
|
201
|
+
export const postgres_select = East.asyncGenericPlatform("postgres_select", ["T"], [ConnectionHandleType, StringType, SqlParametersType], ArrayType("T"));
|
|
132
202
|
/**
|
|
133
203
|
* Closes a PostgreSQL connection pool.
|
|
134
204
|
*
|
|
@@ -286,7 +356,7 @@ export const PostgresImpl = [
|
|
|
286
356
|
}
|
|
287
357
|
catch (err) {
|
|
288
358
|
throw new EastError(`PostgreSQL connection failed: ${err.message}`, {
|
|
289
|
-
location: { filename: "postgres_connect", line: 0n, column: 0n },
|
|
359
|
+
location: [{ filename: "postgres_connect", line: 0n, column: 0n }],
|
|
290
360
|
cause: err
|
|
291
361
|
});
|
|
292
362
|
}
|
|
@@ -301,12 +371,12 @@ export const PostgresImpl = [
|
|
|
301
371
|
// Validate result structure
|
|
302
372
|
if (!result || typeof result !== 'object') {
|
|
303
373
|
throw new EastError('Invalid result from PostgreSQL query', {
|
|
304
|
-
location: { filename: "postgres_query", line: 0n, column: 0n }
|
|
374
|
+
location: [{ filename: "postgres_query", line: 0n, column: 0n }]
|
|
305
375
|
});
|
|
306
376
|
}
|
|
307
377
|
if (!Array.isArray(result.rows)) {
|
|
308
378
|
throw new EastError('PostgreSQL query result missing rows array', {
|
|
309
|
-
location: { filename: "postgres_query", line: 0n, column: 0n }
|
|
379
|
+
location: [{ filename: "postgres_query", line: 0n, column: 0n }]
|
|
310
380
|
});
|
|
311
381
|
}
|
|
312
382
|
// PostgreSQL provides a `command` field indicating query type
|
|
@@ -354,7 +424,130 @@ export const PostgresImpl = [
|
|
|
354
424
|
}
|
|
355
425
|
catch (err) {
|
|
356
426
|
throw new EastError(`PostgreSQL query failed: ${err.message}`, {
|
|
357
|
-
location: { filename: "postgres_query", line: 0n, column: 0n },
|
|
427
|
+
location: [{ filename: "postgres_query", line: 0n, column: 0n }],
|
|
428
|
+
cause: err
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
}),
|
|
432
|
+
postgres_select.implement((T) => async (...args) => {
|
|
433
|
+
const handle = args[0];
|
|
434
|
+
const sql = args[1];
|
|
435
|
+
const params = args[2];
|
|
436
|
+
const rowType = T;
|
|
437
|
+
try {
|
|
438
|
+
const pool = getConnection(handle);
|
|
439
|
+
// Validate row type is a Struct
|
|
440
|
+
if (rowType.type !== 'Struct') {
|
|
441
|
+
throw new EastError(`Expected row type must be a Struct, got ${rowType.type}`, { location: [{ filename: "postgres_select", line: 0n, column: 0n }] });
|
|
442
|
+
}
|
|
443
|
+
// Convert East parameters to native values
|
|
444
|
+
const nativeParams = params.map(convertParamToNative);
|
|
445
|
+
// Execute the query
|
|
446
|
+
const result = await pool.query(sql, nativeParams);
|
|
447
|
+
// Verify this is a SELECT query
|
|
448
|
+
const command = result.command?.toUpperCase();
|
|
449
|
+
if (command !== 'SELECT') {
|
|
450
|
+
throw new EastError('postgres_select only supports SELECT queries. Use postgres_query for INSERT/UPDATE/DELETE.', {
|
|
451
|
+
location: [{ filename: "postgres_select", line: 0n, column: 0n }]
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
if (!Array.isArray(result.rows)) {
|
|
455
|
+
throw new EastError('PostgreSQL query result missing rows array', {
|
|
456
|
+
location: [{ filename: "postgres_select", line: 0n, column: 0n }]
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
// Get column metadata
|
|
460
|
+
const columnMetaMap = new Map();
|
|
461
|
+
if (result.fields) {
|
|
462
|
+
for (const field of result.fields) {
|
|
463
|
+
columnMetaMap.set(field.name, { oid: field.dataTypeID });
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
// Validate field types and determine which are OptionTypes
|
|
467
|
+
// Note: T is EastTypeValue (IR format), not EastType (runtime format)
|
|
468
|
+
const structTypeValue = rowType;
|
|
469
|
+
const fieldInfo = new Map();
|
|
470
|
+
for (const field of structTypeValue.value) {
|
|
471
|
+
const fieldName = field.name;
|
|
472
|
+
const fieldType = field.type;
|
|
473
|
+
const colMeta = columnMetaMap.get(fieldName);
|
|
474
|
+
if (!colMeta) {
|
|
475
|
+
throw new EastError(`Column '${fieldName}' not found in query result`, { location: [{ filename: "postgres_select", line: 0n, column: 0n }] });
|
|
476
|
+
}
|
|
477
|
+
// Determine expected base type from PostgreSQL OID
|
|
478
|
+
let expectedBaseType;
|
|
479
|
+
const oid = colMeta.oid;
|
|
480
|
+
if (oid === 16) { // bool
|
|
481
|
+
expectedBaseType = BooleanType;
|
|
482
|
+
}
|
|
483
|
+
else if (oid === 20 || oid === 21 || oid === 23) { // int8, int2, int4
|
|
484
|
+
expectedBaseType = IntegerType;
|
|
485
|
+
}
|
|
486
|
+
else if (oid === 700 || oid === 701 || oid === 1700) { // float4, float8, numeric
|
|
487
|
+
expectedBaseType = FloatType;
|
|
488
|
+
}
|
|
489
|
+
else if (oid === 25 || oid === 1042 || oid === 1043) { // text, bpchar, varchar
|
|
490
|
+
expectedBaseType = EastStringType;
|
|
491
|
+
}
|
|
492
|
+
else if (oid === 1082 || oid === 1083 || oid === 1114 || oid === 1184) { // date, time, timestamp, timestamptz
|
|
493
|
+
expectedBaseType = DateTimeType;
|
|
494
|
+
}
|
|
495
|
+
else if (oid === 17) { // bytea
|
|
496
|
+
expectedBaseType = BlobType;
|
|
497
|
+
}
|
|
498
|
+
else {
|
|
499
|
+
// Unknown OID - skip type validation, rely on isValueOf later
|
|
500
|
+
fieldInfo.set(fieldName, { isOption: false, expectedBaseType: IntegerType });
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
// Check if field type matches base type or OptionType(base type)
|
|
504
|
+
const isBase = isTypeValueEqual(fieldType, toEastTypeValue(expectedBaseType));
|
|
505
|
+
const isOption = isTypeValueEqual(fieldType, toEastTypeValue(OptionType(expectedBaseType)));
|
|
506
|
+
if (!isBase && !isOption) {
|
|
507
|
+
throw new EastError(`Type mismatch for column '${fieldName}': PostgreSQL column OID ${oid}, got ${fieldType.type} but expected ${expectedBaseType.type} or OptionType(${expectedBaseType.type})`, { location: [{ filename: "postgres_select", line: 0n, column: 0n }] });
|
|
508
|
+
}
|
|
509
|
+
fieldInfo.set(fieldName, { isOption, expectedBaseType });
|
|
510
|
+
}
|
|
511
|
+
// Convert values based on column metadata and handle nulls
|
|
512
|
+
const rows = result.rows.map((row, rowIndex) => {
|
|
513
|
+
const converted = {};
|
|
514
|
+
for (const [key, value] of Object.entries(row)) {
|
|
515
|
+
const info = fieldInfo.get(key);
|
|
516
|
+
const colMeta = columnMetaMap.get(key);
|
|
517
|
+
const oid = colMeta?.oid;
|
|
518
|
+
if (value === null) {
|
|
519
|
+
if (info?.isOption) {
|
|
520
|
+
converted[key] = variant('none', null);
|
|
521
|
+
}
|
|
522
|
+
else {
|
|
523
|
+
throw new EastError(`null value at row[${rowIndex}] for required field '${key}' - use OptionType(${info?.expectedBaseType.type ?? 'T'}) for nullable columns`, { location: [{ filename: "postgres_select", line: 0n, column: 0n }] });
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
// Convert based on column OID
|
|
528
|
+
let convertedValue;
|
|
529
|
+
if (oid === 20 || oid === 21 || oid === 23) { // int8, int2, int4
|
|
530
|
+
convertedValue = BigInt(value);
|
|
531
|
+
}
|
|
532
|
+
else if (oid === 17 && Buffer.isBuffer(value)) { // bytea
|
|
533
|
+
convertedValue = new Uint8Array(value);
|
|
534
|
+
}
|
|
535
|
+
else {
|
|
536
|
+
convertedValue = value;
|
|
537
|
+
}
|
|
538
|
+
converted[key] = info?.isOption ? variant('some', convertedValue) : convertedValue;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return converted;
|
|
542
|
+
});
|
|
543
|
+
// Type validation is already done field-by-field above during column metadata validation
|
|
544
|
+
return rows;
|
|
545
|
+
}
|
|
546
|
+
catch (err) {
|
|
547
|
+
if (err instanceof EastError)
|
|
548
|
+
throw err;
|
|
549
|
+
throw new EastError(`PostgreSQL select failed: ${err.message}`, {
|
|
550
|
+
location: [{ filename: "postgres_select", line: 0n, column: 0n }],
|
|
358
551
|
cause: err
|
|
359
552
|
});
|
|
360
553
|
}
|
|
@@ -368,7 +561,7 @@ export const PostgresImpl = [
|
|
|
368
561
|
}
|
|
369
562
|
catch (err) {
|
|
370
563
|
throw new EastError(`PostgreSQL close failed: ${err.message}`, {
|
|
371
|
-
location: { filename: "postgres_close", line: 0n, column: 0n },
|
|
564
|
+
location: [{ filename: "postgres_close", line: 0n, column: 0n }],
|
|
372
565
|
cause: err
|
|
373
566
|
});
|
|
374
567
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres.js","sourceRoot":"","sources":["../../../src/sql/postgres.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,gBAAgB,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,IAAI,cAAc,EAAE,e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AAK,EAAE,GAAG;aACb,CAAC,CAAC;QACP,CAAC;IACL,CAAC,CAAC;IAEF,kBAAkB,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE;QACpC,MAAM,eAAe,EAAE,CAAC;QACxB,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC;CACL,CAAC"}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @packageDocumentation
|
|
12
12
|
*/
|
|
13
|
-
import { BlobType, BooleanType, DateTimeType, FloatType, IntegerType, NullType } from "@elaraai/east";
|
|
13
|
+
import { ArrayType, BlobType, BooleanType, DateTimeType, FloatType, IntegerType, NullType, OptionType, StringType as EastStringType } from "@elaraai/east";
|
|
14
14
|
import type { PlatformFunction } from "@elaraai/east/internal";
|
|
15
15
|
import { StringType } from './types.js';
|
|
16
16
|
/**
|
|
@@ -63,10 +63,10 @@ import { StringType } from './types.js';
|
|
|
63
63
|
* - All queries are synchronous but wrapped in async for consistency
|
|
64
64
|
*/
|
|
65
65
|
export declare const sqlite_connect: import("@elaraai/east").AsyncPlatformDefinition<[import("@elaraai/east").StructType<{
|
|
66
|
-
path:
|
|
67
|
-
readOnly:
|
|
68
|
-
memory:
|
|
69
|
-
}>],
|
|
66
|
+
readonly path: EastStringType;
|
|
67
|
+
readonly readOnly: OptionType<BooleanType>;
|
|
68
|
+
readonly memory: OptionType<BooleanType>;
|
|
69
|
+
}>], EastStringType>;
|
|
70
70
|
/**
|
|
71
71
|
* Executes a SQL query with parameterized values.
|
|
72
72
|
*
|
|
@@ -118,37 +118,115 @@ export declare const sqlite_connect: import("@elaraai/east").AsyncPlatformDefini
|
|
|
118
118
|
* - NULL values map to {tag: "null", value: {}}
|
|
119
119
|
* - All queries are synchronous but wrapped in async for consistency
|
|
120
120
|
*/
|
|
121
|
-
export declare const sqlite_query: import("@elaraai/east").AsyncPlatformDefinition<[
|
|
122
|
-
Null: NullType;
|
|
123
|
-
Boolean: BooleanType;
|
|
124
|
-
Integer: IntegerType;
|
|
125
|
-
Float: FloatType;
|
|
126
|
-
String: StringType;
|
|
127
|
-
DateTime: DateTimeType;
|
|
128
|
-
Blob: BlobType;
|
|
121
|
+
export declare const sqlite_query: import("@elaraai/east").AsyncPlatformDefinition<[EastStringType, EastStringType, ArrayType<import("@elaraai/east").VariantType<{
|
|
122
|
+
readonly Null: NullType;
|
|
123
|
+
readonly Boolean: BooleanType;
|
|
124
|
+
readonly Integer: IntegerType;
|
|
125
|
+
readonly Float: FloatType;
|
|
126
|
+
readonly String: StringType;
|
|
127
|
+
readonly DateTime: DateTimeType;
|
|
128
|
+
readonly Blob: BlobType;
|
|
129
129
|
}>>], import("@elaraai/east").VariantType<{
|
|
130
|
-
select: import("@elaraai/east").StructType<{
|
|
131
|
-
rows:
|
|
132
|
-
Null: NullType;
|
|
133
|
-
Boolean: BooleanType;
|
|
134
|
-
Integer: IntegerType;
|
|
135
|
-
Float: FloatType;
|
|
136
|
-
String: StringType;
|
|
137
|
-
DateTime: DateTimeType;
|
|
138
|
-
Blob: BlobType;
|
|
130
|
+
readonly select: import("@elaraai/east").StructType<{
|
|
131
|
+
readonly rows: ArrayType<import("@elaraai/east").DictType<EastStringType, import("@elaraai/east").VariantType<{
|
|
132
|
+
readonly Null: NullType;
|
|
133
|
+
readonly Boolean: BooleanType;
|
|
134
|
+
readonly Integer: IntegerType;
|
|
135
|
+
readonly Float: FloatType;
|
|
136
|
+
readonly String: StringType;
|
|
137
|
+
readonly DateTime: DateTimeType;
|
|
138
|
+
readonly Blob: BlobType;
|
|
139
139
|
}>>>;
|
|
140
140
|
}>;
|
|
141
|
-
insert: import("@elaraai/east").StructType<{
|
|
142
|
-
rowsAffected: IntegerType;
|
|
143
|
-
lastInsertId:
|
|
141
|
+
readonly insert: import("@elaraai/east").StructType<{
|
|
142
|
+
readonly rowsAffected: IntegerType;
|
|
143
|
+
readonly lastInsertId: OptionType<IntegerType>;
|
|
144
144
|
}>;
|
|
145
|
-
update: import("@elaraai/east").StructType<{
|
|
146
|
-
rowsAffected: IntegerType;
|
|
145
|
+
readonly update: import("@elaraai/east").StructType<{
|
|
146
|
+
readonly rowsAffected: IntegerType;
|
|
147
147
|
}>;
|
|
148
|
-
delete: import("@elaraai/east").StructType<{
|
|
149
|
-
rowsAffected: IntegerType;
|
|
148
|
+
readonly delete: import("@elaraai/east").StructType<{
|
|
149
|
+
readonly rowsAffected: IntegerType;
|
|
150
150
|
}>;
|
|
151
151
|
}>>;
|
|
152
|
+
/**
|
|
153
|
+
* Executes a SELECT query with user-defined return type.
|
|
154
|
+
*
|
|
155
|
+
* Runs a SELECT query against a SQLite database with parameter binding and
|
|
156
|
+
* returns results as an array of typed rows. The return type is generic,
|
|
157
|
+
* allowing users to specify the expected row structure for type-safe access.
|
|
158
|
+
*
|
|
159
|
+
* This is a generic platform function for the East language, enabling type-safe
|
|
160
|
+
* SELECT queries in East programs running on Node.js.
|
|
161
|
+
*
|
|
162
|
+
* @typeParam T - The expected row type for query results
|
|
163
|
+
* @param handle - Connection handle from sqlite_connect()
|
|
164
|
+
* @param sql - SQL SELECT query string with ? placeholders
|
|
165
|
+
* @param params - Query parameters as SqlParameterType array
|
|
166
|
+
* @returns Array of rows matching the specified type T
|
|
167
|
+
*
|
|
168
|
+
* @throws {EastError} When query fails due to:
|
|
169
|
+
* - Invalid connection handle (location: "sqlite_select")
|
|
170
|
+
* - SQL syntax errors (location: "sqlite_select")
|
|
171
|
+
* - Query is not a SELECT (location: "sqlite_select")
|
|
172
|
+
* - Type coercion failure (location: "sqlite_select")
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* import { East, NullType, StructType, StringType, IntegerType, variant } from "@elaraai/east";
|
|
177
|
+
* import { SQL } from "@elaraai/east-node-io";
|
|
178
|
+
*
|
|
179
|
+
* // Define the expected row type
|
|
180
|
+
* const UserRowType = StructType({
|
|
181
|
+
* id: IntegerType,
|
|
182
|
+
* name: StringType,
|
|
183
|
+
* email: StringType,
|
|
184
|
+
* });
|
|
185
|
+
*
|
|
186
|
+
* const queryUsers = East.function([], NullType, ($) => {
|
|
187
|
+
* const config = $.let({
|
|
188
|
+
* path: ":memory:",
|
|
189
|
+
* readOnly: variant('none', null),
|
|
190
|
+
* memory: variant('some', true),
|
|
191
|
+
* });
|
|
192
|
+
*
|
|
193
|
+
* const conn = $.let(SQL.SQLite.connect(config));
|
|
194
|
+
*
|
|
195
|
+
* // Create table and insert data
|
|
196
|
+
* $(SQL.SQLite.query(conn, "CREATE TABLE users (id INTEGER, name TEXT, email TEXT)", []));
|
|
197
|
+
* $(SQL.SQLite.query(conn, "INSERT INTO users VALUES (1, 'Alice', 'alice@example.com')", []));
|
|
198
|
+
*
|
|
199
|
+
* // Query with typed results - returns Array<UserRowType>
|
|
200
|
+
* const users = $.let(SQL.SQLite.select([UserRowType], conn,
|
|
201
|
+
* "SELECT id, name, email FROM users",
|
|
202
|
+
* []
|
|
203
|
+
* ));
|
|
204
|
+
* // users is typed as Array<{ id: bigint, name: string, email: string }>
|
|
205
|
+
*
|
|
206
|
+
* $(SQL.SQLite.close(conn));
|
|
207
|
+
* $.return(null);
|
|
208
|
+
* });
|
|
209
|
+
*
|
|
210
|
+
* const compiled = East.compileAsync(queryUsers.toIR(), SQL.SQLite.Implementation);
|
|
211
|
+
* await compiled();
|
|
212
|
+
* ```
|
|
213
|
+
*
|
|
214
|
+
* @remarks
|
|
215
|
+
* - Only SELECT queries are supported (use sqlite_query for INSERT/UPDATE/DELETE)
|
|
216
|
+
* - Uses `?` placeholders for parameters (not $1, $2 like PostgreSQL)
|
|
217
|
+
* - Row type T should match the structure of selected columns
|
|
218
|
+
* - All SQLite data types are mapped to appropriate East types
|
|
219
|
+
* - NULL values are preserved in the result
|
|
220
|
+
*/
|
|
221
|
+
export declare const sqlite_select: import("@elaraai/east").AsyncGenericPlatformDefinition<readonly ["T"], readonly [EastStringType, EastStringType, ArrayType<import("@elaraai/east").VariantType<{
|
|
222
|
+
readonly Null: NullType;
|
|
223
|
+
readonly Boolean: BooleanType;
|
|
224
|
+
readonly Integer: IntegerType;
|
|
225
|
+
readonly Float: FloatType;
|
|
226
|
+
readonly String: StringType;
|
|
227
|
+
readonly DateTime: DateTimeType;
|
|
228
|
+
readonly Blob: BlobType;
|
|
229
|
+
}>>], ArrayType<"T">>;
|
|
152
230
|
/**
|
|
153
231
|
* Closes a SQLite database connection.
|
|
154
232
|
*
|
|
@@ -180,7 +258,7 @@ export declare const sqlite_query: import("@elaraai/east").AsyncPlatformDefiniti
|
|
|
180
258
|
* await compiled();
|
|
181
259
|
* ```
|
|
182
260
|
*/
|
|
183
|
-
export declare const sqlite_close: import("@elaraai/east").AsyncPlatformDefinition<[
|
|
261
|
+
export declare const sqlite_close: import("@elaraai/east").AsyncPlatformDefinition<[EastStringType], NullType>;
|
|
184
262
|
/**
|
|
185
263
|
* Closes all SQLite connections.
|
|
186
264
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../../src/sql/sqlite.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAS,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAQ,SAAS,EAAE,WAAW,EAA+B,QAAQ,EAAE,UAAU,EAAa,UAAU,IAAI,cAAc,EAA4B,MAAM,eAAe,CAAC;AAE1O,OAAO,KAAK,EAAiB,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAI9E,OAAO,EAKH,UAAU,EAEb,MAAM,YAAY,CAAC;AAyBpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,eAAO,MAAM,cAAc;;;;oBAAiF,CAAC;AAE7G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAA2G,CAAC;AAErI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,eAAO,MAAM,aAAa;;;;;;;;qBAKzB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,YAAY,6EAAuE,CAAC;AAEjG;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,gBAAgB,+DAAuD,CAAC;AAmFrF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,EAAE,gBAAgB,EA4RxC,CAAC"}
|