metal-orm 1.0.27 → 1.0.30

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/dist/index.d.cts CHANGED
@@ -1338,5 +1338,42 @@ interface MssqlClientLike {
1338
1338
  rollback?(): Promise<void>;
1339
1339
  }
1340
1340
  declare function createMssqlExecutor(client: MssqlClientLike): DbExecutor;
1341
+ interface TediousColumn {
1342
+ metadata: {
1343
+ colName: string;
1344
+ };
1345
+ value: unknown;
1346
+ }
1347
+ interface TediousRequest {
1348
+ addParameter(name: string, type: unknown, value: unknown): void;
1349
+ on(event: 'row', listener: (columns: TediousColumn[]) => void): void;
1350
+ }
1351
+ interface TediousRequestCtor {
1352
+ new (sql: string, callback: (err?: Error | null) => void): TediousRequest;
1353
+ }
1354
+ interface TediousTypes {
1355
+ NVarChar: unknown;
1356
+ Int: unknown;
1357
+ Float: unknown;
1358
+ BigInt: unknown;
1359
+ Bit: unknown;
1360
+ DateTime: unknown;
1361
+ VarBinary: unknown;
1362
+ }
1363
+ interface TediousModule {
1364
+ Request: TediousRequestCtor;
1365
+ TYPES: TediousTypes;
1366
+ }
1367
+ interface TediousConnectionLike {
1368
+ execSql(request: TediousRequest): void;
1369
+ beginTransaction?(cb: (err?: Error | null) => void): void;
1370
+ commitTransaction?(cb: (err?: Error | null) => void): void;
1371
+ rollbackTransaction?(cb: (err?: Error | null) => void): void;
1372
+ }
1373
+ interface CreateTediousClientOptions {
1374
+ inferType?(value: unknown, TYPES: TediousTypes): unknown;
1375
+ }
1376
+ declare function createTediousMssqlClient(connection: TediousConnectionLike, { Request, TYPES }: TediousModule, options?: CreateTediousClientOptions): MssqlClientLike;
1377
+ declare function createTediousExecutor(connection: TediousConnectionLike, module: TediousModule, options?: CreateTediousClientOptions): DbExecutor;
1341
1378
 
1342
- export { AsyncLocalStorage, BelongsToManyRelation, BelongsToReference, BelongsToRelation, BetweenExpressionNode, BinaryExpressionNode, CaseExpressionNode, ColumnDef, type ColumnDiff, ColumnNode, ColumnRef, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, DbExecutor, DefaultBelongsToReference, DefaultHasManyCollection, DefaultManyToManyCollection, DeleteQueryBuilder, type DialectName, Entity, EntityContext, ExecutionContext, ExistsExpressionNode, ExpressionNode, type ExpressionVisitor, ForeignKeyReference, FunctionNode, type GroupConcatOptions, HasManyCollection, HasManyRelation, HasOneRelation, HydrationContext, HydrationPlan, InExpressionNode, IndexColumn, IndexDef, InsertQueryBuilder, type IntrospectOptions, JsonPathNode, LiteralNode, type LiteralValue, LogicalExpressionNode, ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, NullExpressionNode, OperandNode, type OperandVisitor, OrmSession, type PostgresClientLike, PostgresDialect, RelationMap, type RenderColumnOptions, ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaGenerateResult, type SchemaIntrospector, type SchemaPlan, SelectQueryBuilder, SqlServerDialect, type SqliteClientLike, SqliteDialect, type SynchronizeOptions, TableDef, TableRef, TypeScriptGenerator, UpdateQueryBuilder, type ValueOperandInput, WindowFunctionNode, abs, acos, and, ascii, asin, atan, atan2, avg, between, caseWhen, ceil, ceiling, char, charLength, clearExpressionDispatchers, clearOperandDispatchers, columnOperand, concat, concatWs, correlateBy, cos, cot, count, createEntityFromRow, createEntityProxy, createMssqlExecutor, createMysqlExecutor, createPostgresExecutor, createSqliteExecutor, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, degrees, denseRank, diffSchema, endOfMonth, eq, esel, executeHydrated, executeHydratedWithContexts, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, getSchemaIntrospector, groupConcat, gt, gte, hydrateRows, inList, instr, introspectSchema, isNotNull, isNull, isValueOperandInput, jsonPath, lag, lastValue, lead, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, locate, log, log10, logBase, lower, lpad, lt, lte, ltrim, max, min, mod, month, neq, notBetween, notExists, notInList, notLike, now, ntile, or, outerRef, pi, position, pow, power, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, renderColumnDefinition, repeat, replace, right, round, rowNumber, rpad, rtrim, sel, sign, sin, space, sqrt, substr, sum, synchronizeSchema, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, upper, utcNow, valueToOperand, visitExpression, visitOperand, weekOfYear, windowFunction, year };
1379
+ export { AsyncLocalStorage, BelongsToManyRelation, BelongsToReference, BelongsToRelation, BetweenExpressionNode, BinaryExpressionNode, CaseExpressionNode, ColumnDef, type ColumnDiff, ColumnNode, ColumnRef, type CreateTediousClientOptions, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, DbExecutor, DefaultBelongsToReference, DefaultHasManyCollection, DefaultManyToManyCollection, DeleteQueryBuilder, type DialectName, Entity, EntityContext, ExecutionContext, ExistsExpressionNode, ExpressionNode, type ExpressionVisitor, ForeignKeyReference, FunctionNode, type GroupConcatOptions, HasManyCollection, HasManyRelation, HasOneRelation, HydrationContext, HydrationPlan, InExpressionNode, IndexColumn, IndexDef, InsertQueryBuilder, type IntrospectOptions, JsonPathNode, LiteralNode, type LiteralValue, LogicalExpressionNode, ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, NullExpressionNode, OperandNode, type OperandVisitor, OrmSession, type PostgresClientLike, PostgresDialect, RelationMap, type RenderColumnOptions, ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaGenerateResult, type SchemaIntrospector, type SchemaPlan, SelectQueryBuilder, SqlServerDialect, type SqliteClientLike, SqliteDialect, type SynchronizeOptions, TableDef, TableRef, type TediousColumn, type TediousConnectionLike, type TediousModule, type TediousRequest, type TediousRequestCtor, type TediousTypes, TypeScriptGenerator, UpdateQueryBuilder, type ValueOperandInput, WindowFunctionNode, abs, acos, and, ascii, asin, atan, atan2, avg, between, caseWhen, ceil, ceiling, char, charLength, clearExpressionDispatchers, clearOperandDispatchers, columnOperand, concat, concatWs, correlateBy, cos, cot, count, createEntityFromRow, createEntityProxy, createMssqlExecutor, createMysqlExecutor, createPostgresExecutor, createSqliteExecutor, createTediousExecutor, createTediousMssqlClient, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, degrees, denseRank, diffSchema, endOfMonth, eq, esel, executeHydrated, executeHydratedWithContexts, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, getSchemaIntrospector, groupConcat, gt, gte, hydrateRows, inList, instr, introspectSchema, isNotNull, isNull, isValueOperandInput, jsonPath, lag, lastValue, lead, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, locate, log, log10, logBase, lower, lpad, lt, lte, ltrim, max, min, mod, month, neq, notBetween, notExists, notInList, notLike, now, ntile, or, outerRef, pi, position, pow, power, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, renderColumnDefinition, repeat, replace, right, round, rowNumber, rpad, rtrim, sel, sign, sin, space, sqrt, substr, sum, synchronizeSchema, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, upper, utcNow, valueToOperand, visitExpression, visitOperand, weekOfYear, windowFunction, year };
package/dist/index.d.ts CHANGED
@@ -1338,5 +1338,42 @@ interface MssqlClientLike {
1338
1338
  rollback?(): Promise<void>;
1339
1339
  }
1340
1340
  declare function createMssqlExecutor(client: MssqlClientLike): DbExecutor;
1341
+ interface TediousColumn {
1342
+ metadata: {
1343
+ colName: string;
1344
+ };
1345
+ value: unknown;
1346
+ }
1347
+ interface TediousRequest {
1348
+ addParameter(name: string, type: unknown, value: unknown): void;
1349
+ on(event: 'row', listener: (columns: TediousColumn[]) => void): void;
1350
+ }
1351
+ interface TediousRequestCtor {
1352
+ new (sql: string, callback: (err?: Error | null) => void): TediousRequest;
1353
+ }
1354
+ interface TediousTypes {
1355
+ NVarChar: unknown;
1356
+ Int: unknown;
1357
+ Float: unknown;
1358
+ BigInt: unknown;
1359
+ Bit: unknown;
1360
+ DateTime: unknown;
1361
+ VarBinary: unknown;
1362
+ }
1363
+ interface TediousModule {
1364
+ Request: TediousRequestCtor;
1365
+ TYPES: TediousTypes;
1366
+ }
1367
+ interface TediousConnectionLike {
1368
+ execSql(request: TediousRequest): void;
1369
+ beginTransaction?(cb: (err?: Error | null) => void): void;
1370
+ commitTransaction?(cb: (err?: Error | null) => void): void;
1371
+ rollbackTransaction?(cb: (err?: Error | null) => void): void;
1372
+ }
1373
+ interface CreateTediousClientOptions {
1374
+ inferType?(value: unknown, TYPES: TediousTypes): unknown;
1375
+ }
1376
+ declare function createTediousMssqlClient(connection: TediousConnectionLike, { Request, TYPES }: TediousModule, options?: CreateTediousClientOptions): MssqlClientLike;
1377
+ declare function createTediousExecutor(connection: TediousConnectionLike, module: TediousModule, options?: CreateTediousClientOptions): DbExecutor;
1341
1378
 
1342
- export { AsyncLocalStorage, BelongsToManyRelation, BelongsToReference, BelongsToRelation, BetweenExpressionNode, BinaryExpressionNode, CaseExpressionNode, ColumnDef, type ColumnDiff, ColumnNode, ColumnRef, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, DbExecutor, DefaultBelongsToReference, DefaultHasManyCollection, DefaultManyToManyCollection, DeleteQueryBuilder, type DialectName, Entity, EntityContext, ExecutionContext, ExistsExpressionNode, ExpressionNode, type ExpressionVisitor, ForeignKeyReference, FunctionNode, type GroupConcatOptions, HasManyCollection, HasManyRelation, HasOneRelation, HydrationContext, HydrationPlan, InExpressionNode, IndexColumn, IndexDef, InsertQueryBuilder, type IntrospectOptions, JsonPathNode, LiteralNode, type LiteralValue, LogicalExpressionNode, ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, NullExpressionNode, OperandNode, type OperandVisitor, OrmSession, type PostgresClientLike, PostgresDialect, RelationMap, type RenderColumnOptions, ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaGenerateResult, type SchemaIntrospector, type SchemaPlan, SelectQueryBuilder, SqlServerDialect, type SqliteClientLike, SqliteDialect, type SynchronizeOptions, TableDef, TableRef, TypeScriptGenerator, UpdateQueryBuilder, type ValueOperandInput, WindowFunctionNode, abs, acos, and, ascii, asin, atan, atan2, avg, between, caseWhen, ceil, ceiling, char, charLength, clearExpressionDispatchers, clearOperandDispatchers, columnOperand, concat, concatWs, correlateBy, cos, cot, count, createEntityFromRow, createEntityProxy, createMssqlExecutor, createMysqlExecutor, createPostgresExecutor, createSqliteExecutor, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, degrees, denseRank, diffSchema, endOfMonth, eq, esel, executeHydrated, executeHydratedWithContexts, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, getSchemaIntrospector, groupConcat, gt, gte, hydrateRows, inList, instr, introspectSchema, isNotNull, isNull, isValueOperandInput, jsonPath, lag, lastValue, lead, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, locate, log, log10, logBase, lower, lpad, lt, lte, ltrim, max, min, mod, month, neq, notBetween, notExists, notInList, notLike, now, ntile, or, outerRef, pi, position, pow, power, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, renderColumnDefinition, repeat, replace, right, round, rowNumber, rpad, rtrim, sel, sign, sin, space, sqrt, substr, sum, synchronizeSchema, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, upper, utcNow, valueToOperand, visitExpression, visitOperand, weekOfYear, windowFunction, year };
1379
+ export { AsyncLocalStorage, BelongsToManyRelation, BelongsToReference, BelongsToRelation, BetweenExpressionNode, BinaryExpressionNode, CaseExpressionNode, ColumnDef, type ColumnDiff, ColumnNode, ColumnRef, type CreateTediousClientOptions, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, DbExecutor, DefaultBelongsToReference, DefaultHasManyCollection, DefaultManyToManyCollection, DeleteQueryBuilder, type DialectName, Entity, EntityContext, ExecutionContext, ExistsExpressionNode, ExpressionNode, type ExpressionVisitor, ForeignKeyReference, FunctionNode, type GroupConcatOptions, HasManyCollection, HasManyRelation, HasOneRelation, HydrationContext, HydrationPlan, InExpressionNode, IndexColumn, IndexDef, InsertQueryBuilder, type IntrospectOptions, JsonPathNode, LiteralNode, type LiteralValue, LogicalExpressionNode, ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, NullExpressionNode, OperandNode, type OperandVisitor, OrmSession, type PostgresClientLike, PostgresDialect, RelationMap, type RenderColumnOptions, ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaGenerateResult, type SchemaIntrospector, type SchemaPlan, SelectQueryBuilder, SqlServerDialect, type SqliteClientLike, SqliteDialect, type SynchronizeOptions, TableDef, TableRef, type TediousColumn, type TediousConnectionLike, type TediousModule, type TediousRequest, type TediousRequestCtor, type TediousTypes, TypeScriptGenerator, UpdateQueryBuilder, type ValueOperandInput, WindowFunctionNode, abs, acos, and, ascii, asin, atan, atan2, avg, between, caseWhen, ceil, ceiling, char, charLength, clearExpressionDispatchers, clearOperandDispatchers, columnOperand, concat, concatWs, correlateBy, cos, cot, count, createEntityFromRow, createEntityProxy, createMssqlExecutor, createMysqlExecutor, createPostgresExecutor, createSqliteExecutor, createTediousExecutor, createTediousMssqlClient, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, degrees, denseRank, diffSchema, endOfMonth, eq, esel, executeHydrated, executeHydratedWithContexts, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, getSchemaIntrospector, groupConcat, gt, gte, hydrateRows, inList, instr, introspectSchema, isNotNull, isNull, isValueOperandInput, jsonPath, lag, lastValue, lead, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, locate, log, log10, logBase, lower, lpad, lt, lte, ltrim, max, min, mod, month, neq, notBetween, notExists, notInList, notLike, now, ntile, or, outerRef, pi, position, pow, power, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, renderColumnDefinition, repeat, replace, right, round, rowNumber, rpad, rtrim, sel, sign, sin, space, sqrt, substr, sum, synchronizeSchema, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, upper, utcNow, valueToOperand, visitExpression, visitOperand, weekOfYear, windowFunction, year };
package/dist/index.js CHANGED
@@ -7469,6 +7469,71 @@ function createMssqlExecutor(client) {
7469
7469
  }
7470
7470
  };
7471
7471
  }
7472
+ var defaultInferType = (value, TYPES) => {
7473
+ if (value === null || value === void 0) return TYPES.NVarChar;
7474
+ if (typeof value === "number") {
7475
+ return Number.isInteger(value) ? TYPES.Int : TYPES.Float;
7476
+ }
7477
+ if (typeof value === "bigint") return TYPES.BigInt;
7478
+ if (typeof value === "boolean") return TYPES.Bit;
7479
+ if (value instanceof Date) return TYPES.DateTime;
7480
+ if (typeof Buffer !== "undefined" && Buffer.isBuffer(value)) {
7481
+ return TYPES.VarBinary;
7482
+ }
7483
+ return TYPES.NVarChar;
7484
+ };
7485
+ function createTediousMssqlClient(connection, { Request, TYPES }, options) {
7486
+ const inferType = options?.inferType ?? defaultInferType;
7487
+ return {
7488
+ async query(sql, params = []) {
7489
+ const rows = await new Promise(
7490
+ (resolve, reject) => {
7491
+ const collected = [];
7492
+ const request = new Request(sql, (err) => {
7493
+ if (err) return reject(err);
7494
+ resolve(collected);
7495
+ });
7496
+ params.forEach((value, idx) => {
7497
+ const sqlType = inferType(value, TYPES);
7498
+ request.addParameter(
7499
+ `p${idx + 1}`,
7500
+ sqlType,
7501
+ value
7502
+ );
7503
+ });
7504
+ request.on("row", (cols) => {
7505
+ const row = {};
7506
+ for (const col2 of cols) {
7507
+ row[col2.metadata.colName] = col2.value;
7508
+ }
7509
+ collected.push(row);
7510
+ });
7511
+ connection.execSql(request);
7512
+ }
7513
+ );
7514
+ return { recordset: rows };
7515
+ },
7516
+ beginTransaction: connection.beginTransaction ? () => new Promise((resolve, reject) => {
7517
+ connection.beginTransaction(
7518
+ (err) => err ? reject(err) : resolve()
7519
+ );
7520
+ }) : void 0,
7521
+ commit: connection.commitTransaction ? () => new Promise((resolve, reject) => {
7522
+ connection.commitTransaction(
7523
+ (err) => err ? reject(err) : resolve()
7524
+ );
7525
+ }) : void 0,
7526
+ rollback: connection.rollbackTransaction ? () => new Promise((resolve, reject) => {
7527
+ connection.rollbackTransaction(
7528
+ (err) => err ? reject(err) : resolve()
7529
+ );
7530
+ }) : void 0
7531
+ };
7532
+ }
7533
+ function createTediousExecutor(connection, module, options) {
7534
+ const client = createTediousMssqlClient(connection, module, options);
7535
+ return createMssqlExecutor(client);
7536
+ }
7472
7537
  export {
7473
7538
  AsyncLocalStorage,
7474
7539
  DefaultBelongsToReference,
@@ -7525,6 +7590,8 @@ export {
7525
7590
  createPostgresExecutor,
7526
7591
  createQueryLoggingExecutor,
7527
7592
  createSqliteExecutor,
7593
+ createTediousExecutor,
7594
+ createTediousMssqlClient,
7528
7595
  currentDate,
7529
7596
  currentTime,
7530
7597
  dateAdd,