Skip to content

Commit

Permalink
fix: typings to use generics for returning concrete types
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jan 12, 2020
1 parent e9cb112 commit e06c5c5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
36 changes: 32 additions & 4 deletions adonis-typings/orm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,41 @@ declare module '@ioc:Adonis/Lucid/Orm' {
Instance extends ModelContract,
> (this: new () => Instance): OrmQueryBuilder<Model, Instance>

$createFromAdapterResult (result?: any, sideloadAttributes?: string[]): null | ModelContract
$createMultipleFromAdapterResult (results: any[], sideloadAttributes?: string[]): ModelContract[]
}
/**
* Creates model instance from the adapter result
*/
$createFromAdapterResult<T extends ModelContract> (
this: new () => T,
result?: any,
sideloadAttributes?: string[],
): null | T

/**
* Creates multiple model instances from the adapter result
*/
$createMultipleFromAdapterResult<T extends ModelContract> (
this: new () => T,
results: any[],
sideloadAttributes?: string[],
): T[]

/**
* Fetch row for a key/value pair
*/
findBy<T extends ModelContract> (
this: new () => T,
key: string,
value: any,
): Promise<null | T>

/**
* Fetch all rows
*/
findAll<T extends ModelContract> (this: new () => T): Promise<T[]>

export const BaseModel: ModelConstructorContract & {
new (): ModelContract,
}

export const BaseModel: ModelConstructorContract
export const column: typeof baseColumn
}
2 changes: 1 addition & 1 deletion src/Orm/BaseModel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { QueryClientContract } from '@ioc:Adonis/Lucid/Database'
import { ModelConstructorContract, ModelContract } from '@ioc:Adonis/Lucid/Orm'

@StaticImplements<ModelConstructorContract>()
export abstract class BaseModel extends BaseDataModel implements ModelContract {
export class BaseModel extends BaseDataModel implements ModelContract {
/**
* Whether or not to rely on database to return the primaryKey
* value. If this is set to false, then the user must provide
Expand Down

0 comments on commit e06c5c5

Please sign in to comment.