Skip to main content
Module

x/cotton/mod.ts>QueryBuilder

SQL Database Toolkit for Deno
Go to Latest
class QueryBuilder
import { QueryBuilder } from "https://deno.land/x/cotton@v0.4.9/mod.ts";

Allows to build complex SQL queries and execute those queries.

Constructors

new
QueryBuilder(tableName: string, adapter: Adapter)

Properties

private
description: QueryDescription

Methods

private
addWhereClause(options: { column: string; operator?: WhereOperator | "BETWEEN" | "IN"; value: any; type?: WhereType; })

Add new where clause to query

Delete record from the database.

execute<T extends { }>(adapter?: Adapter): Promise<T[]>

Execute query and get the result

Get the first record of the query, shortcut for limit(1)

insert(data: QueryValues | QueryValues[]): QueryBuilder

Insert a record to the table

limit(limit: number): QueryBuilder

Set the "limit" value for the query.

notWhere(column: string, value: any): QueryBuilder

Add WHERE NOT clause to query

notWhere(
column: string,
operator: WhereOperator,
value: any,
): QueryBuilder
offset(offset: number): QueryBuilder

Set the "offset" value for the query.

orderBy(column: string, direction?: OrderDirection): QueryBuilder

Add an "order by" clause to the query.

orWhere(column: string, value: any): QueryBuilder

Add WHERE ... OR clause to query

orWhere(
column: string,
operator: WhereOperator,
value: any,
): QueryBuilder
replace(data: QueryValues): QueryBuilder

Perform REPLACE query to the table.

It will look for PRIMARY and UNIQUE constraints. If something matched, it gets removed from the table and creates a new row with the given values.

returning(...columns: string[]): QueryBuilder

Sets the returning value for the query.

select(...columns: string[]): QueryBuilder

Select table columns

update(data: QueryValues): QueryBuilder

Update record on the database

where(column: string, value: any): QueryBuilder

Add basic WHERE clause to query

where(
column: string,
operator: WhereOperator,
value: any,
): QueryBuilder
whereIn(column: string, values: any[]): QueryBuilder

Add a WHERE columnName IN (...) clause

whereNotIn(column: string, values: any[]): QueryBuilder

Add a WHERE columnName IN (...) clause