Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/cotton/src/modelquery.ts>ModelQuery

SQL Database Toolkit for Deno
Latest
class ModelQuery
import { ModelQuery } from "https://deno.land/x/cotton@v0.7.5/src/modelquery.ts";

Perform query to a model.

Constructors

new
ModelQuery(modelClass: { new (): T; }, adapter: Adapter)

Create a new model query.

Properties

private
builder: QueryBuilder

The query builder to construct the query

private
includes: string[]

Included relationships

private
tableName: string

The table to fetch

Methods

private
getColumnName(propertyKey: string): string

Get column name on the database from a column property key.

private
selectModelColumns(modelClass: Function)

Select all columns of a model class.

all(): Promise<T[]>

Find records that match given conditions.

count(): Promise<number>

Count models with given conditions.

delete(): Promise<void>

Delete models with given conditions.

first(): Promise<T | null>

Find a single record that match given conditions. If multiple found, it will return the first one.

include(...columns: Extract<keyof T, string>[]): this

Fetch relationships to the query.

limit(limit: number): this

Set the "limit" value for the query.

not(column: string, value: DatabaseValues): this

Add WHERE NOT clause to query.

not(column: string, expression: Q): this

Add WHERE NOT clause to query with custom query expression.

offset(offset: number): this

Set the "offset" value for the query.

or(column: string, value: DatabaseValues): this

Add WHERE ... OR clause to query.

or(column: string, expression: Q): this

Add WHERE ... OR clause to query with custom query expression.

order(column: Extract<keyof T, string>, direction?: OrderDirection): this

Add an "order by" clause to the query.

update(data: DeepPartial<T>): Promise<void>

Update models with given conditions.

where(column: string, value: DatabaseValues): this

Add basic WHERE clause to query.

where(column: string, expression: Q): this

Add basic WHERE clause to query with custom query expression.