Skip to content

Commit

Permalink
refactor: cleanup for making relationships and their types more consi…
Browse files Browse the repository at this point in the history
…stent

The commit has some unfinished work
  • Loading branch information
thetutlage committed Jan 12, 2020
1 parent 83cffd3 commit e3aaaee
Show file tree
Hide file tree
Showing 39 changed files with 12,192 additions and 10,515 deletions.
577 changes: 187 additions & 390 deletions adonis-typings/model.ts

Large diffs are not rendered by default.

90 changes: 90 additions & 0 deletions adonis-typings/model.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* Save the related model.
*/
save (model: T, wrapInTransaction?: boolean): Promise<void>

/**
* Save the related model.
*/
saveMany (model: T[], wrapInTransaction?: boolean): Promise<void>

/**
* Create the related model instance
*/
create (values: ModelObject, wrapInTransaction?: boolean): Promise<T>

/**
* Create many of the related model instance
*/
createMany (values: ModelObject[], wrapInTransaction?: boolean): Promise<T[]>

/**
* Update the relationship or create a new one
*/
updateOrCreate (
search: ModelObject,
updatePayload: ModelObject,
wrapInTransaction?: boolean,
): Promise<T>




/**
* Associate related model.
*/
associate (model: T, wrapInTransaction?: boolean): Promise<void>

/**
* Dissociate all relationships.
*/
dissociate (): Promise<void>








/**
* Save related model
*/
save (model: T, wrapInTransaction?: boolean, checkExisting?: boolean): Promise<void>

/**
* Save related many
*/
saveMany (model: T[], wrapInTransaction?: boolean, checkExisting?: boolean): Promise<void>

/**
* Create the related model instance
*/
create (values: ModelObject, wrapInTransaction?: boolean, checkExisting?: boolean): Promise<T>

/**
* Create many of the related model instance
*/
createMany (values: ModelObject, wrapInTransaction?: boolean, checkExisting?: boolean): Promise<T[]>

/**
* Attach related
*/
attach (
ids: (string | number)[] | { [key: string]: ModelObject },
checkExisting?: boolean,
): Promise<void>

/**
* Detach from pivot table
*/
detach (ids: (string | number)[]): Promise<void>

/**
* Sync related ids
*/
sync (
ids: (string | number)[] | { [key: string]: ModelObject },
wrapInTransaction?: boolean,
checkExisting?: boolean,
): Promise<void>
45 changes: 24 additions & 21 deletions adonis-typings/orm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,33 @@

declare module '@ioc:Adonis/Lucid/Orm' {
import {
ColumnFn,
HasOneFn,
HasManyFn,
ComputedFn,
BelongsToFn,
ManyToManyFn,
HasManyThroughFn,
ColumnDecorator,
ComputedDecorator,
ModelConstructorContract,
} from '@ioc:Adonis/Lucid/Model'

/**
* Generate key/value pair of model properties and
* adapter keys
*/
export type Refs<T extends any, K extends keyof T> = {
[P in K]: string
}
import {
HasOneDecorator,
HasManyDecorator,
BelongsToDecorator,
ManyToManyDecorator,
HasManyThroughDecorator,
} from '@ioc:Adonis/Lucid/Relations'

export {
HasOne,
HasMany,
BelongsTo,
ManyToMany,
HasManyThrough,
} from '@ioc:Adonis/Lucid/Relations'

export const BaseModel: ModelConstructorContract
export const column: ColumnFn
export const computed: ComputedFn
export const hasOne: HasOneFn
export const belongsTo: BelongsToFn
export const hasMany: HasManyFn
export const manyToMany: ManyToManyFn
export const hasManyThrough: HasManyThroughFn
export const column: ColumnDecorator
export const computed: ComputedDecorator
export const hasOne: HasOneDecorator
export const belongsTo: BelongsToDecorator
export const hasMany: HasManyDecorator
export const manyToMany: ManyToManyDecorator
export const hasManyThrough: HasManyThroughDecorator
}
Loading

0 comments on commit e3aaaee

Please sign in to comment.