Skip to content

Commit

Permalink
fix(types): update bulkInsert & insert method typings
Browse files Browse the repository at this point in the history
  • Loading branch information
lohart13 committed Jan 29, 2024
1 parent e40270c commit c254281
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
33 changes: 18 additions & 15 deletions packages/core/src/dialects/abstract/query-interface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import type { AllowLowercase, Nullish } from '../../utils/types.js';
import type { DataType } from './data-types.js';
import type { RemoveIndexQueryOptions, TableNameOrModel } from './query-generator-typescript';
import type { AbstractQueryGenerator, AddColumnQueryOptions } from './query-generator.js';
import type { AddLimitOffsetOptions, InsertQueryOptions } from './query-generator.types.js';
import type { AddLimitOffsetOptions } from './query-generator.types.js';
import { AbstractQueryInterfaceTypeScript } from './query-interface-typescript';
import type { ColumnsDescription } from './query-interface.types.js';
import type { ColumnsDescription, QiBulkInsertOptions, QiInsertOptions } from './query-interface.types.js';
import type { WhereOptions } from './where-sql-builder-types.js';

interface Replaceable {
Expand All @@ -31,8 +31,6 @@ interface Replaceable {

interface QiOptionsWithReplacements extends QueryRawOptions, Replaceable { }

export interface QiInsertOptions extends QueryRawOptions, InsertQueryOptions { }

export interface QiSelectOptions extends QueryRawOptions, Filterable<any>, AddLimitOffsetOptions {
minifyAliases?: boolean;
}
Expand Down Expand Up @@ -333,10 +331,25 @@ export class AbstractQueryInterface extends AbstractQueryInterfaceTypeScript {
*/
nameIndexes(indexes: string[], rawTablename: string): Promise<void>;

/**
* Inserts multiple records at once
*/
bulkInsert(
tableName: TableNameOrModel,
values: Array<Record<string, unknown>>,
options?: QiBulkInsertOptions,
attributeHash?: Record<string, AttributeOptions>,
): Promise<object[]>;

/**
* Inserts a new record
*/
insert(instance: Model | null, tableName: TableName, values: object, options?: QiInsertOptions): Promise<object>;
insert(
instance: Model | null,
tableName: TableNameOrModel,
values: Record<string, unknown>,
options?: QiInsertOptions,
): Promise<object>;

/**
* Inserts or Updates a record in the database
Expand All @@ -349,16 +362,6 @@ export class AbstractQueryInterface extends AbstractQueryInterfaceTypeScript {
options?: QiUpsertOptions<M>,
): Promise<object>;

/**
* Inserts multiple records at once
*/
bulkInsert(
tableName: TableName,
records: object[],
options?: QiOptionsWithReplacements,
attributes?: Record<string, AttributeOptions>
): Promise<object | number>;

/**
* Updates a row
*/
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/dialects/abstract/query-interface.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import type { Deferrable } from '../../deferrable';
import type { QueryRawOptions } from '../../sequelize';
import type {
AddConstraintQueryOptions,
BulkInsertQueryOptions,
CreateDatabaseQueryOptions,
CreateSchemaQueryOptions,
DropSchemaQueryOptions,
DropTableQueryOptions,
InsertQueryOptions,
ListDatabasesQueryOptions,
ListSchemasQueryOptions,
ListTablesQueryOptions,
Expand Down Expand Up @@ -134,3 +136,9 @@ export interface RemoveConstraintOptions extends RemoveConstraintQueryOptions, Q

/** Options accepted by {@link AbstractQueryInterface#showConstraints} */
export interface ShowConstraintsOptions extends ShowConstraintsQueryOptions, QueryRawOptions { }

/** Options accepted by {@link AbstractQueryInterface#bulkInsert} */
export interface QiBulkInsertOptions extends BulkInsertQueryOptions, QueryRawOptions { }

/** Options accepted by {@link AbstractQueryInterface#insert} */
export interface QiInsertOptions extends InsertQueryOptions, QueryRawOptions { }

0 comments on commit c254281

Please sign in to comment.