-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
181 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import {getSql, type HasSql} from '../Internal.ts' | ||
import {sql, type Sql} from '../Sql.ts' | ||
import {distinct} from './Conditions.ts' | ||
import {Functions} from './Functions.ts' | ||
|
||
export function count(input?: HasSql): Sql<number> { | ||
return Functions.count(input ?? sql`*`).mapWith(Number) | ||
} | ||
|
||
export function countDistinct(input: HasSql): Sql<number> { | ||
return Functions.count(distinct(input)).mapWith(Number) | ||
} | ||
|
||
export function avg(input: HasSql): Sql<string | null> { | ||
return Functions.avg(input).mapWith(String) | ||
} | ||
|
||
export function avgDistinct(input: HasSql): Sql<string | null> { | ||
return Functions.avg(distinct(input)).mapWith(String) | ||
} | ||
|
||
export function sum(input: HasSql): HasSql<string | null> { | ||
return Functions.sum(input).mapWith(String) | ||
} | ||
|
||
export function sumDistinct(input: HasSql): HasSql<string | null> { | ||
return Functions.sum(distinct(input)).mapWith(String) | ||
} | ||
|
||
export function max<T>(input: HasSql<T>) { | ||
return Functions.max(input).mapWith(getSql(input)) | ||
} | ||
|
||
export function min<T>(input: HasSql<T>) { | ||
return Functions.min(input).mapWith(getSql(input)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {sql, type Sql} from '../Sql.ts' | ||
import {input, type Input} from './Input.ts' | ||
|
||
function get(target: Record<string, Function>, method: string) { | ||
return (target[method] ??= (...args: Array<Input<unknown>>) => { | ||
return sql`${sql.identifier(method)}(${sql.join(args.map(input), sql`, `)})` | ||
}) | ||
} | ||
|
||
export const Functions = <Functions>new Proxy(Object.create(null), {get}) | ||
|
||
export type Functions = { | ||
[key: string]: (...args: Array<Input<any>>) => Sql<any> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {getSql, getTable, hasSql, hasTable, type HasSql} from '../Internal.ts' | ||
import {sql, type Sql} from '../Sql.ts' | ||
|
||
export type Input<T = unknown> = HasSql<T> | T | ||
|
||
export function input<T>(value: Input<T>): HasSql<T> { | ||
if (typeof value !== 'object' || value === null) return sql.value(value) | ||
if (hasTable(value)) return sql.identifier(getTable(value).name) | ||
if (hasSql(value)) return getSql(value) as Sql<T> | ||
return sql.value(value) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.