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

x/cotton/src/querybuilder.ts>QueryBuilder

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

Allows to build complex SQL queries and execute those queries.

Constructors

new
QueryBuilder(tableName: string, adapter: Adapter)

Properties

private
description: QueryDescription

Methods

count(column: string | string[], as?: string): QueryBuilder

Count records with given conditions

countDistinct(column: string | string[], as?: string): QueryBuilder

Count records with unique values

Delete record from the database.

Force the query to return distinct (unique) results.

execute(adapter?: Adapter): Promise<DatabaseResult[]>

Execute query and get the result

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

fullJoin(
table: string,
a: string,
b: string,
): QueryBuilder

SQL FULL OUTER JOIN

groupBy(...columns: string[])

Group records by a column

having(column: string, value: DatabaseValues): QueryBuilder

Add SQL HAVING clause to query

having(column: string, expression: Q): QueryBuilder

Add SQL HAVING clause to query with custom query expression.

innerJoin(
table: string,
a: string,
b: string,
): QueryBuilder

SQL INNER JOIN

Insert a record to the table

leftJoin(
table: string,
a: string,
b: string,
): QueryBuilder

SQL LEFT OUTER JOIN

limit(limit: number): QueryBuilder

Set the "limit" value for the query.

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

Add WHERE NOT clause to query

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

Add WHERE NOT clause to query with custom query expression.

offset(offset: number): QueryBuilder

Set the "offset" value for the query.

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

Add WHERE ... OR clause to query

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

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

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

Add an "order by" clause to the query.

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.

rightJoin(
table: string,
a: string,
b: string,
): QueryBuilder

SQL RIGHT OUTER JOIN

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

Select table columns

Get the actual SQL query string. All the data are replaced by a placeholder. So, you need to also bind the values in order to execute the query.

Update record on the database

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

Add basic WHERE clause to query

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

Add basic WHERE clause to query with custom query expression.