Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion packages/repository/src/repositories/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,37 @@ export interface Repository<T extends Model> {}

export interface ExecutableRepository<T extends Model> extends Repository<T> {
/**
* Execute a query with the given parameter object or an array of parameters
* Proxy method for the underlying connector's method to execute raw queries.
* Support and method signature are entirely dependent on the underlying
* connector's implementation. The result object is the connector's native
* result object, you will have to process it on your own.
*
* @remarks
*
* MySQL usage example:
*
* Although the whole command can be specified in the `command` argument. It
* is recommended to specify the parameters in the `parameters` argument,
* which is an array in case of MySQL.
*
*```ts
* myRepository.execute(
* 'SELECT * from User WHERE name=? && status=?',
* ['John', 'active']
*);
*```
*
* Using `parameters` argument helps to prevent SQL injection attacks.
*
* MongoDB usage example:
*
* In case of MongoDB, the first parameter is the collection name, the second
* parameter is the command name, and the third being the options.
*
* const res = await myRepository.execute(
* 'Pet', 'find', {type:'cat'}
* );
Copy link
Member

@bajtos bajtos Oct 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure the string 'find' is assignable to NamedParameters | PositionalParameters?

ATM, ExecutableRepository.execute provides SQL-like flavor only:

interface ExecutableRepository { 
  execute(
    command: Command,
    parameters: NamedParameters | PositionalParameters,
    options?: Options,
  ): Promise<AnyObject>;
}

To support other connectors, I had to add few more overloads in #6030:

interface ExecutableRepository { 
  // MongoDB
  execute(
     collectionName: string,
     command: string,
     ...parameters: PositionalParameters
   ): Promise<AnyObject>;

  // Other connectors
  execute(...args: PositionalParameters): Promise<AnyObject>;
}

*
* @param command - The query string or command object
* @param parameters - The object with name/value pairs or an array of parameter
* values
Expand Down