import type { Collection as ValueCollection } from '@h3ravel/collect.js' import type { Knex } from 'knex' import type Collection from 'src/collection' import type Paginator from 'src/paginator' import type Model from 'src/model' import type { IBuilder } from './builder' import type { ModelColumn, ModelColumnValue, ModelInput, ModelKey, ModelRelationPath, QualifiedModelColumn, } from './schema' export type QueryOperator = | '=' | '!=' | '<>' | '<' | '<=' | '>' | '>=' | 'like' | 'ilike' | 'in' | 'not in' | (string & {}) export type QueryValue = Value | Knex.Raw | ModelBuilder export interface ModelBuilder { query: IBuilder [method: string]: any where>( column: Column, value: QueryValue>, ): this where>( column: Column, operator: QueryOperator, value: QueryValue>, ): this where(attributes: ModelInput): this where(callback: (query: ModelBuilder) => unknown): this orWhere>( column: Column, value: QueryValue>, ): this orWhere>( column: Column, operator: QueryOperator, value: QueryValue>, ): this orWhere(callback: (query: ModelBuilder) => unknown): this whereIn>( column: Column, values: ModelColumnValue[], ): this whereNotIn>( column: Column, values: ModelColumnValue[], ): this whereNull(column: ModelColumn): this whereNotNull(column: ModelColumn): this whereBetween>( column: Column, values: [ModelColumnValue, ModelColumnValue], ): this whereColumn( first: QualifiedModelColumn, operator: QueryOperator, second: QualifiedModelColumn, ): this select( ...columns: ( | ModelColumn | '*' | readonly (ModelColumn | '*')[] )[] ): this orderBy(column: ModelColumn, direction?: 'asc' | 'desc' | 'ASC' | 'DESC'): this latest(column?: ModelColumn): this oldest(column?: ModelColumn): this limit(count: number): this take(count: number): this offset(count: number): this skip(count: number): this with( ...relations: ( | ModelRelationPath | readonly ModelRelationPath[] | Partial< Record< ModelRelationPath, (query: ModelBuilder) => unknown > > )[] ): this withCount( ...relations: (ModelRelationPath | readonly ModelRelationPath[])[] ): this first(columns?: ModelColumn[]): Promise firstOrFail(columns?: ModelColumn[]): Promise find(key: ModelKey, columns?: ModelColumn[]): Promise findOrFail(key: ModelKey, columns?: ModelColumn[]): Promise findMany(keys: ModelKey[], columns?: ModelColumn[]): Promise> get(columns?: ModelColumn[]): Promise> all(columns?: ModelColumn[]): Promise> create(attributes?: ModelInput): Promise firstOrNew(attributes?: ModelInput, values?: ModelInput): Promise firstOrCreate(attributes?: ModelInput, values?: ModelInput): Promise updateOrCreate(attributes: ModelInput, values?: ModelInput): Promise update(attributes: ModelInput): Promise increment(column: ModelColumn, amount?: number, extra?: ModelInput): Promise decrement(column: ModelColumn, amount?: number, extra?: ModelInput): Promise delete(): Promise forceDelete(): Promise count(column?: ModelColumn | '*'): Promise min(column: ModelColumn): Promise max(column: ModelColumn): Promise sum(column: ModelColumn): Promise avg(column: ModelColumn): Promise pluck>( column: Column, ): Promise>> paginate(page?: number, perPage?: number): Promise> clone(): ModelBuilder getModel(): M toSql(): object }