Initial commit

This commit is contained in:
Ammaar Reshi
2025-01-04 14:06:53 +00:00
parent 7082408604
commit d6025af146
23760 changed files with 3299690 additions and 0 deletions

223
node_modules/drizzle-orm/sql/expressions/conditions.cjs generated vendored Normal file
View File

@ -0,0 +1,223 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var conditions_exports = {};
__export(conditions_exports, {
and: () => and,
arrayContained: () => arrayContained,
arrayContains: () => arrayContains,
arrayOverlaps: () => arrayOverlaps,
between: () => between,
bindIfParam: () => bindIfParam,
eq: () => eq,
exists: () => exists,
gt: () => gt,
gte: () => gte,
ilike: () => ilike,
inArray: () => inArray,
isNotNull: () => isNotNull,
isNull: () => isNull,
like: () => like,
lt: () => lt,
lte: () => lte,
ne: () => ne,
not: () => not,
notBetween: () => notBetween,
notExists: () => notExists,
notIlike: () => notIlike,
notInArray: () => notInArray,
notLike: () => notLike,
or: () => or
});
module.exports = __toCommonJS(conditions_exports);
var import_column = require("../../column.cjs");
var import_entity = require("../../entity.cjs");
var import_table = require("../../table.cjs");
var import_sql = require("../sql.cjs");
function bindIfParam(value, column) {
if ((0, import_sql.isDriverValueEncoder)(column) && !(0, import_sql.isSQLWrapper)(value) && !(0, import_entity.is)(value, import_sql.Param) && !(0, import_entity.is)(value, import_sql.Placeholder) && !(0, import_entity.is)(value, import_column.Column) && !(0, import_entity.is)(value, import_table.Table) && !(0, import_entity.is)(value, import_sql.View)) {
return new import_sql.Param(value, column);
}
return value;
}
const eq = (left, right) => {
return import_sql.sql`${left} = ${bindIfParam(right, left)}`;
};
const ne = (left, right) => {
return import_sql.sql`${left} <> ${bindIfParam(right, left)}`;
};
function and(...unfilteredConditions) {
const conditions = unfilteredConditions.filter(
(c) => c !== void 0
);
if (conditions.length === 0) {
return void 0;
}
if (conditions.length === 1) {
return new import_sql.SQL(conditions);
}
return new import_sql.SQL([
new import_sql.StringChunk("("),
import_sql.sql.join(conditions, new import_sql.StringChunk(" and ")),
new import_sql.StringChunk(")")
]);
}
function or(...unfilteredConditions) {
const conditions = unfilteredConditions.filter(
(c) => c !== void 0
);
if (conditions.length === 0) {
return void 0;
}
if (conditions.length === 1) {
return new import_sql.SQL(conditions);
}
return new import_sql.SQL([
new import_sql.StringChunk("("),
import_sql.sql.join(conditions, new import_sql.StringChunk(" or ")),
new import_sql.StringChunk(")")
]);
}
function not(condition) {
return import_sql.sql`not ${condition}`;
}
const gt = (left, right) => {
return import_sql.sql`${left} > ${bindIfParam(right, left)}`;
};
const gte = (left, right) => {
return import_sql.sql`${left} >= ${bindIfParam(right, left)}`;
};
const lt = (left, right) => {
return import_sql.sql`${left} < ${bindIfParam(right, left)}`;
};
const lte = (left, right) => {
return import_sql.sql`${left} <= ${bindIfParam(right, left)}`;
};
function inArray(column, values) {
if (Array.isArray(values)) {
if (values.length === 0) {
return import_sql.sql`false`;
}
return import_sql.sql`${column} in ${values.map((v) => bindIfParam(v, column))}`;
}
return import_sql.sql`${column} in ${bindIfParam(values, column)}`;
}
function notInArray(column, values) {
if (Array.isArray(values)) {
if (values.length === 0) {
return import_sql.sql`true`;
}
return import_sql.sql`${column} not in ${values.map((v) => bindIfParam(v, column))}`;
}
return import_sql.sql`${column} not in ${bindIfParam(values, column)}`;
}
function isNull(value) {
return import_sql.sql`${value} is null`;
}
function isNotNull(value) {
return import_sql.sql`${value} is not null`;
}
function exists(subquery) {
return import_sql.sql`exists ${subquery}`;
}
function notExists(subquery) {
return import_sql.sql`not exists ${subquery}`;
}
function between(column, min, max) {
return import_sql.sql`${column} between ${bindIfParam(min, column)} and ${bindIfParam(
max,
column
)}`;
}
function notBetween(column, min, max) {
return import_sql.sql`${column} not between ${bindIfParam(
min,
column
)} and ${bindIfParam(max, column)}`;
}
function like(column, value) {
return import_sql.sql`${column} like ${value}`;
}
function notLike(column, value) {
return import_sql.sql`${column} not like ${value}`;
}
function ilike(column, value) {
return import_sql.sql`${column} ilike ${value}`;
}
function notIlike(column, value) {
return import_sql.sql`${column} not ilike ${value}`;
}
function arrayContains(column, values) {
if (Array.isArray(values)) {
if (values.length === 0) {
throw new Error("arrayContains requires at least one value");
}
const array = import_sql.sql`${bindIfParam(values, column)}`;
return import_sql.sql`${column} @> ${array}`;
}
return import_sql.sql`${column} @> ${bindIfParam(values, column)}`;
}
function arrayContained(column, values) {
if (Array.isArray(values)) {
if (values.length === 0) {
throw new Error("arrayContained requires at least one value");
}
const array = import_sql.sql`${bindIfParam(values, column)}`;
return import_sql.sql`${column} <@ ${array}`;
}
return import_sql.sql`${column} <@ ${bindIfParam(values, column)}`;
}
function arrayOverlaps(column, values) {
if (Array.isArray(values)) {
if (values.length === 0) {
throw new Error("arrayOverlaps requires at least one value");
}
const array = import_sql.sql`${bindIfParam(values, column)}`;
return import_sql.sql`${column} && ${array}`;
}
return import_sql.sql`${column} && ${bindIfParam(values, column)}`;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
and,
arrayContained,
arrayContains,
arrayOverlaps,
between,
bindIfParam,
eq,
exists,
gt,
gte,
ilike,
inArray,
isNotNull,
isNull,
like,
lt,
lte,
ne,
not,
notBetween,
notExists,
notIlike,
notInArray,
notLike,
or
});
//# sourceMappingURL=conditions.cjs.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,453 @@
import { type AnyColumn, Column, type GetColumnData } from "../../column.cjs";
import { Placeholder, SQL, type SQLChunk, type SQLWrapper } from "../sql.cjs";
export declare function bindIfParam(value: unknown, column: SQLWrapper): SQLChunk;
export interface BinaryOperator {
<TColumn extends Column>(left: TColumn, right: GetColumnData<TColumn, 'raw'> | SQLWrapper): SQL;
<T>(left: SQL.Aliased<T>, right: T | SQLWrapper): SQL;
<T extends SQLWrapper>(left: Exclude<T, SQL.Aliased | Column>, right: unknown): SQL;
}
/**
* Test that two values are equal.
*
* Remember that the SQL standard dictates that
* two NULL values are not equal, so if you want to test
* whether a value is null, you may want to use
* `isNull` instead.
*
* ## Examples
*
* ```ts
* // Select cars made by Ford
* db.select().from(cars)
* .where(eq(cars.make, 'Ford'))
* ```
*
* @see isNull for a way to test equality to NULL.
*/
export declare const eq: BinaryOperator;
/**
* Test that two values are not equal.
*
* Remember that the SQL standard dictates that
* two NULL values are not equal, so if you want to test
* whether a value is not null, you may want to use
* `isNotNull` instead.
*
* ## Examples
*
* ```ts
* // Select cars not made by Ford
* db.select().from(cars)
* .where(ne(cars.make, 'Ford'))
* ```
*
* @see isNotNull for a way to test whether a value is not null.
*/
export declare const ne: BinaryOperator;
/**
* Combine a list of conditions with the `and` operator. Conditions
* that are equal `undefined` are automatically ignored.
*
* ## Examples
*
* ```ts
* db.select().from(cars)
* .where(
* and(
* eq(cars.make, 'Volvo'),
* eq(cars.year, 1950),
* )
* )
* ```
*/
export declare function and(...conditions: (SQLWrapper | undefined)[]): SQL | undefined;
/**
* Combine a list of conditions with the `or` operator. Conditions
* that are equal `undefined` are automatically ignored.
*
* ## Examples
*
* ```ts
* db.select().from(cars)
* .where(
* or(
* eq(cars.make, 'GM'),
* eq(cars.make, 'Ford'),
* )
* )
* ```
*/
export declare function or(...conditions: (SQLWrapper | undefined)[]): SQL | undefined;
/**
* Negate the meaning of an expression using the `not` keyword.
*
* ## Examples
*
* ```ts
* // Select cars _not_ made by GM or Ford.
* db.select().from(cars)
* .where(not(inArray(cars.make, ['GM', 'Ford'])))
* ```
*/
export declare function not(condition: SQLWrapper): SQL;
/**
* Test that the first expression passed is greater than
* the second expression.
*
* ## Examples
*
* ```ts
* // Select cars made after 2000.
* db.select().from(cars)
* .where(gt(cars.year, 2000))
* ```
*
* @see gte for greater-than-or-equal
*/
export declare const gt: BinaryOperator;
/**
* Test that the first expression passed is greater than
* or equal to the second expression. Use `gt` to
* test whether an expression is strictly greater
* than another.
*
* ## Examples
*
* ```ts
* // Select cars made on or after 2000.
* db.select().from(cars)
* .where(gte(cars.year, 2000))
* ```
*
* @see gt for a strictly greater-than condition
*/
export declare const gte: BinaryOperator;
/**
* Test that the first expression passed is less than
* the second expression.
*
* ## Examples
*
* ```ts
* // Select cars made before 2000.
* db.select().from(cars)
* .where(lt(cars.year, 2000))
* ```
*
* @see lte for less-than-or-equal
*/
export declare const lt: BinaryOperator;
/**
* Test that the first expression passed is less than
* or equal to the second expression.
*
* ## Examples
*
* ```ts
* // Select cars made before 2000.
* db.select().from(cars)
* .where(lte(cars.year, 2000))
* ```
*
* @see lt for a strictly less-than condition
*/
export declare const lte: BinaryOperator;
/**
* Test whether the first parameter, a column or expression,
* has a value from a list passed as the second argument.
*
* ## Examples
*
* ```ts
* // Select cars made by Ford or GM.
* db.select().from(cars)
* .where(inArray(cars.make, ['Ford', 'GM']))
* ```
*
* @see notInArray for the inverse of this test
*/
export declare function inArray<T>(column: SQL.Aliased<T>, values: (T | Placeholder)[] | SQLWrapper): SQL;
export declare function inArray<TColumn extends Column>(column: TColumn, values: (GetColumnData<TColumn, 'raw'> | Placeholder)[] | SQLWrapper): SQL;
export declare function inArray<T extends SQLWrapper>(column: Exclude<T, SQL.Aliased | Column>, values: (unknown | Placeholder)[] | SQLWrapper): SQL;
/**
* Test whether the first parameter, a column or expression,
* has a value that is not present in a list passed as the
* second argument.
*
* ## Examples
*
* ```ts
* // Select cars made by any company except Ford or GM.
* db.select().from(cars)
* .where(notInArray(cars.make, ['Ford', 'GM']))
* ```
*
* @see inArray for the inverse of this test
*/
export declare function notInArray<T>(column: SQL.Aliased<T>, values: (T | Placeholder)[] | SQLWrapper): SQL;
export declare function notInArray<TColumn extends Column>(column: TColumn, values: (GetColumnData<TColumn, 'raw'> | Placeholder)[] | SQLWrapper): SQL;
export declare function notInArray<T extends SQLWrapper>(column: Exclude<T, SQL.Aliased | Column>, values: (unknown | Placeholder)[] | SQLWrapper): SQL;
/**
* Test whether an expression is NULL. By the SQL standard,
* NULL is neither equal nor not equal to itself, so
* it's recommended to use `isNull` and `notIsNull` for
* comparisons to NULL.
*
* ## Examples
*
* ```ts
* // Select cars that have no discontinuedAt date.
* db.select().from(cars)
* .where(isNull(cars.discontinuedAt))
* ```
*
* @see isNotNull for the inverse of this test
*/
export declare function isNull(value: SQLWrapper): SQL;
/**
* Test whether an expression is not NULL. By the SQL standard,
* NULL is neither equal nor not equal to itself, so
* it's recommended to use `isNull` and `notIsNull` for
* comparisons to NULL.
*
* ## Examples
*
* ```ts
* // Select cars that have been discontinued.
* db.select().from(cars)
* .where(isNotNull(cars.discontinuedAt))
* ```
*
* @see isNull for the inverse of this test
*/
export declare function isNotNull(value: SQLWrapper): SQL;
/**
* Test whether a subquery evaluates to have any rows.
*
* ## Examples
*
* ```ts
* // Users whose `homeCity` column has a match in a cities
* // table.
* db
* .select()
* .from(users)
* .where(
* exists(db.select()
* .from(cities)
* .where(eq(users.homeCity, cities.id))),
* );
* ```
*
* @see notExists for the inverse of this test
*/
export declare function exists(subquery: SQLWrapper): SQL;
/**
* Test whether a subquery doesn't include any result
* rows.
*
* ## Examples
*
* ```ts
* // Users whose `homeCity` column doesn't match
* // a row in the cities table.
* db
* .select()
* .from(users)
* .where(
* notExists(db.select()
* .from(cities)
* .where(eq(users.homeCity, cities.id))),
* );
* ```
*
* @see exists for the inverse of this test
*/
export declare function notExists(subquery: SQLWrapper): SQL;
/**
* Test whether an expression is between two values. This
* is an easier way to express range tests, which would be
* expressed mathematically as `x <= a <= y` but in SQL
* would have to be like `a >= x AND a <= y`.
*
* Between is inclusive of the endpoints: if `column`
* is equal to `min` or `max`, it will be TRUE.
*
* ## Examples
*
* ```ts
* // Select cars made between 1990 and 2000
* db.select().from(cars)
* .where(between(cars.year, 1990, 2000))
* ```
*
* @see notBetween for the inverse of this test
*/
export declare function between<T>(column: SQL.Aliased, min: T | SQLWrapper, max: T | SQLWrapper): SQL;
export declare function between<TColumn extends AnyColumn>(column: TColumn, min: GetColumnData<TColumn, 'raw'> | SQLWrapper, max: GetColumnData<TColumn, 'raw'> | SQLWrapper): SQL;
export declare function between<T extends SQLWrapper>(column: Exclude<T, SQL.Aliased | Column>, min: unknown, max: unknown): SQL;
/**
* Test whether an expression is not between two values.
*
* This, like `between`, includes its endpoints, so if
* the `column` is equal to `min` or `max`, in this case
* it will evaluate to FALSE.
*
* ## Examples
*
* ```ts
* // Exclude cars made in the 1970s
* db.select().from(cars)
* .where(notBetween(cars.year, 1970, 1979))
* ```
*
* @see between for the inverse of this test
*/
export declare function notBetween<T>(column: SQL.Aliased, min: T | SQLWrapper, max: T | SQLWrapper): SQL;
export declare function notBetween<TColumn extends AnyColumn>(column: TColumn, min: GetColumnData<TColumn, 'raw'> | SQLWrapper, max: GetColumnData<TColumn, 'raw'> | SQLWrapper): SQL;
export declare function notBetween<T extends SQLWrapper>(column: Exclude<T, SQL.Aliased | Column>, min: unknown, max: unknown): SQL;
/**
* Compare a column to a pattern, which can include `%` and `_`
* characters to match multiple variations. Including `%`
* in the pattern matches zero or more characters, and including
* `_` will match a single character.
*
* ## Examples
*
* ```ts
* // Select all cars with 'Turbo' in their names.
* db.select().from(cars)
* .where(like(cars.name, '%Turbo%'))
* ```
*
* @see ilike for a case-insensitive version of this condition
*/
export declare function like(column: Column | SQL.Aliased | SQL, value: string | SQLWrapper): SQL;
/**
* The inverse of like - this tests that a given column
* does not match a pattern, which can include `%` and `_`
* characters to match multiple variations. Including `%`
* in the pattern matches zero or more characters, and including
* `_` will match a single character.
*
* ## Examples
*
* ```ts
* // Select all cars that don't have "ROver" in their name.
* db.select().from(cars)
* .where(notLike(cars.name, '%Rover%'))
* ```
*
* @see like for the inverse condition
* @see notIlike for a case-insensitive version of this condition
*/
export declare function notLike(column: Column | SQL.Aliased | SQL, value: string | SQLWrapper): SQL;
/**
* Case-insensitively compare a column to a pattern,
* which can include `%` and `_`
* characters to match multiple variations. Including `%`
* in the pattern matches zero or more characters, and including
* `_` will match a single character.
*
* Unlike like, this performs a case-insensitive comparison.
*
* ## Examples
*
* ```ts
* // Select all cars with 'Turbo' in their names.
* db.select().from(cars)
* .where(ilike(cars.name, '%Turbo%'))
* ```
*
* @see like for a case-sensitive version of this condition
*/
export declare function ilike(column: Column | SQL.Aliased | SQL, value: string | SQLWrapper): SQL;
/**
* The inverse of ilike - this case-insensitively tests that a given column
* does not match a pattern, which can include `%` and `_`
* characters to match multiple variations. Including `%`
* in the pattern matches zero or more characters, and including
* `_` will match a single character.
*
* ## Examples
*
* ```ts
* // Select all cars that don't have "Rover" in their name.
* db.select().from(cars)
* .where(notLike(cars.name, '%Rover%'))
* ```
*
* @see ilike for the inverse condition
* @see notLike for a case-sensitive version of this condition
*/
export declare function notIlike(column: Column | SQL.Aliased | SQL, value: string | SQLWrapper): SQL;
/**
* Test that a column or expression contains all elements of
* the list passed as the second argument.
*
* ## Throws
*
* The argument passed in the second array can't be empty:
* if an empty is provided, this method will throw.
*
* ## Examples
*
* ```ts
* // Select posts where its tags contain "Typescript" and "ORM".
* db.select().from(posts)
* .where(arrayContains(posts.tags, ['Typescript', 'ORM']))
* ```
*
* @see arrayContained to find if an array contains all elements of a column or expression
* @see arrayOverlaps to find if a column or expression contains any elements of an array
*/
export declare function arrayContains<T>(column: SQL.Aliased<T>, values: (T | Placeholder) | SQLWrapper): SQL;
export declare function arrayContains<TColumn extends Column>(column: TColumn, values: (GetColumnData<TColumn, 'raw'> | Placeholder) | SQLWrapper): SQL;
export declare function arrayContains<T extends SQLWrapper>(column: Exclude<T, SQL.Aliased | Column>, values: (unknown | Placeholder)[] | SQLWrapper): SQL;
/**
* Test that the list passed as the second argument contains
* all elements of a column or expression.
*
* ## Throws
*
* The argument passed in the second array can't be empty:
* if an empty is provided, this method will throw.
*
* ## Examples
*
* ```ts
* // Select posts where its tags contain "Typescript", "ORM" or both,
* // but filtering posts that have additional tags.
* db.select().from(posts)
* .where(arrayContained(posts.tags, ['Typescript', 'ORM']))
* ```
*
* @see arrayContains to find if a column or expression contains all elements of an array
* @see arrayOverlaps to find if a column or expression contains any elements of an array
*/
export declare function arrayContained<T>(column: SQL.Aliased<T>, values: (T | Placeholder) | SQLWrapper): SQL;
export declare function arrayContained<TColumn extends Column>(column: TColumn, values: (GetColumnData<TColumn, 'raw'> | Placeholder) | SQLWrapper): SQL;
export declare function arrayContained<T extends SQLWrapper>(column: Exclude<T, SQL.Aliased | Column>, values: (unknown | Placeholder)[] | SQLWrapper): SQL;
/**
* Test that a column or expression contains any elements of
* the list passed as the second argument.
*
* ## Throws
*
* The argument passed in the second array can't be empty:
* if an empty is provided, this method will throw.
*
* ## Examples
*
* ```ts
* // Select posts where its tags contain "Typescript", "ORM" or both.
* db.select().from(posts)
* .where(arrayOverlaps(posts.tags, ['Typescript', 'ORM']))
* ```
*
* @see arrayContains to find if a column or expression contains all elements of an array
* @see arrayContained to find if an array contains all elements of a column or expression
*/
export declare function arrayOverlaps<T>(column: SQL.Aliased<T>, values: (T | Placeholder) | SQLWrapper): SQL;
export declare function arrayOverlaps<TColumn extends Column>(column: TColumn, values: (GetColumnData<TColumn, 'raw'> | Placeholder) | SQLWrapper): SQL;
export declare function arrayOverlaps<T extends SQLWrapper>(column: Exclude<T, SQL.Aliased | Column>, values: (unknown | Placeholder)[] | SQLWrapper): SQL;

View File

@ -0,0 +1,453 @@
import { type AnyColumn, Column, type GetColumnData } from "../../column.js";
import { Placeholder, SQL, type SQLChunk, type SQLWrapper } from "../sql.js";
export declare function bindIfParam(value: unknown, column: SQLWrapper): SQLChunk;
export interface BinaryOperator {
<TColumn extends Column>(left: TColumn, right: GetColumnData<TColumn, 'raw'> | SQLWrapper): SQL;
<T>(left: SQL.Aliased<T>, right: T | SQLWrapper): SQL;
<T extends SQLWrapper>(left: Exclude<T, SQL.Aliased | Column>, right: unknown): SQL;
}
/**
* Test that two values are equal.
*
* Remember that the SQL standard dictates that
* two NULL values are not equal, so if you want to test
* whether a value is null, you may want to use
* `isNull` instead.
*
* ## Examples
*
* ```ts
* // Select cars made by Ford
* db.select().from(cars)
* .where(eq(cars.make, 'Ford'))
* ```
*
* @see isNull for a way to test equality to NULL.
*/
export declare const eq: BinaryOperator;
/**
* Test that two values are not equal.
*
* Remember that the SQL standard dictates that
* two NULL values are not equal, so if you want to test
* whether a value is not null, you may want to use
* `isNotNull` instead.
*
* ## Examples
*
* ```ts
* // Select cars not made by Ford
* db.select().from(cars)
* .where(ne(cars.make, 'Ford'))
* ```
*
* @see isNotNull for a way to test whether a value is not null.
*/
export declare const ne: BinaryOperator;
/**
* Combine a list of conditions with the `and` operator. Conditions
* that are equal `undefined` are automatically ignored.
*
* ## Examples
*
* ```ts
* db.select().from(cars)
* .where(
* and(
* eq(cars.make, 'Volvo'),
* eq(cars.year, 1950),
* )
* )
* ```
*/
export declare function and(...conditions: (SQLWrapper | undefined)[]): SQL | undefined;
/**
* Combine a list of conditions with the `or` operator. Conditions
* that are equal `undefined` are automatically ignored.
*
* ## Examples
*
* ```ts
* db.select().from(cars)
* .where(
* or(
* eq(cars.make, 'GM'),
* eq(cars.make, 'Ford'),
* )
* )
* ```
*/
export declare function or(...conditions: (SQLWrapper | undefined)[]): SQL | undefined;
/**
* Negate the meaning of an expression using the `not` keyword.
*
* ## Examples
*
* ```ts
* // Select cars _not_ made by GM or Ford.
* db.select().from(cars)
* .where(not(inArray(cars.make, ['GM', 'Ford'])))
* ```
*/
export declare function not(condition: SQLWrapper): SQL;
/**
* Test that the first expression passed is greater than
* the second expression.
*
* ## Examples
*
* ```ts
* // Select cars made after 2000.
* db.select().from(cars)
* .where(gt(cars.year, 2000))
* ```
*
* @see gte for greater-than-or-equal
*/
export declare const gt: BinaryOperator;
/**
* Test that the first expression passed is greater than
* or equal to the second expression. Use `gt` to
* test whether an expression is strictly greater
* than another.
*
* ## Examples
*
* ```ts
* // Select cars made on or after 2000.
* db.select().from(cars)
* .where(gte(cars.year, 2000))
* ```
*
* @see gt for a strictly greater-than condition
*/
export declare const gte: BinaryOperator;
/**
* Test that the first expression passed is less than
* the second expression.
*
* ## Examples
*
* ```ts
* // Select cars made before 2000.
* db.select().from(cars)
* .where(lt(cars.year, 2000))
* ```
*
* @see lte for less-than-or-equal
*/
export declare const lt: BinaryOperator;
/**
* Test that the first expression passed is less than
* or equal to the second expression.
*
* ## Examples
*
* ```ts
* // Select cars made before 2000.
* db.select().from(cars)
* .where(lte(cars.year, 2000))
* ```
*
* @see lt for a strictly less-than condition
*/
export declare const lte: BinaryOperator;
/**
* Test whether the first parameter, a column or expression,
* has a value from a list passed as the second argument.
*
* ## Examples
*
* ```ts
* // Select cars made by Ford or GM.
* db.select().from(cars)
* .where(inArray(cars.make, ['Ford', 'GM']))
* ```
*
* @see notInArray for the inverse of this test
*/
export declare function inArray<T>(column: SQL.Aliased<T>, values: (T | Placeholder)[] | SQLWrapper): SQL;
export declare function inArray<TColumn extends Column>(column: TColumn, values: (GetColumnData<TColumn, 'raw'> | Placeholder)[] | SQLWrapper): SQL;
export declare function inArray<T extends SQLWrapper>(column: Exclude<T, SQL.Aliased | Column>, values: (unknown | Placeholder)[] | SQLWrapper): SQL;
/**
* Test whether the first parameter, a column or expression,
* has a value that is not present in a list passed as the
* second argument.
*
* ## Examples
*
* ```ts
* // Select cars made by any company except Ford or GM.
* db.select().from(cars)
* .where(notInArray(cars.make, ['Ford', 'GM']))
* ```
*
* @see inArray for the inverse of this test
*/
export declare function notInArray<T>(column: SQL.Aliased<T>, values: (T | Placeholder)[] | SQLWrapper): SQL;
export declare function notInArray<TColumn extends Column>(column: TColumn, values: (GetColumnData<TColumn, 'raw'> | Placeholder)[] | SQLWrapper): SQL;
export declare function notInArray<T extends SQLWrapper>(column: Exclude<T, SQL.Aliased | Column>, values: (unknown | Placeholder)[] | SQLWrapper): SQL;
/**
* Test whether an expression is NULL. By the SQL standard,
* NULL is neither equal nor not equal to itself, so
* it's recommended to use `isNull` and `notIsNull` for
* comparisons to NULL.
*
* ## Examples
*
* ```ts
* // Select cars that have no discontinuedAt date.
* db.select().from(cars)
* .where(isNull(cars.discontinuedAt))
* ```
*
* @see isNotNull for the inverse of this test
*/
export declare function isNull(value: SQLWrapper): SQL;
/**
* Test whether an expression is not NULL. By the SQL standard,
* NULL is neither equal nor not equal to itself, so
* it's recommended to use `isNull` and `notIsNull` for
* comparisons to NULL.
*
* ## Examples
*
* ```ts
* // Select cars that have been discontinued.
* db.select().from(cars)
* .where(isNotNull(cars.discontinuedAt))
* ```
*
* @see isNull for the inverse of this test
*/
export declare function isNotNull(value: SQLWrapper): SQL;
/**
* Test whether a subquery evaluates to have any rows.
*
* ## Examples
*
* ```ts
* // Users whose `homeCity` column has a match in a cities
* // table.
* db
* .select()
* .from(users)
* .where(
* exists(db.select()
* .from(cities)
* .where(eq(users.homeCity, cities.id))),
* );
* ```
*
* @see notExists for the inverse of this test
*/
export declare function exists(subquery: SQLWrapper): SQL;
/**
* Test whether a subquery doesn't include any result
* rows.
*
* ## Examples
*
* ```ts
* // Users whose `homeCity` column doesn't match
* // a row in the cities table.
* db
* .select()
* .from(users)
* .where(
* notExists(db.select()
* .from(cities)
* .where(eq(users.homeCity, cities.id))),
* );
* ```
*
* @see exists for the inverse of this test
*/
export declare function notExists(subquery: SQLWrapper): SQL;
/**
* Test whether an expression is between two values. This
* is an easier way to express range tests, which would be
* expressed mathematically as `x <= a <= y` but in SQL
* would have to be like `a >= x AND a <= y`.
*
* Between is inclusive of the endpoints: if `column`
* is equal to `min` or `max`, it will be TRUE.
*
* ## Examples
*
* ```ts
* // Select cars made between 1990 and 2000
* db.select().from(cars)
* .where(between(cars.year, 1990, 2000))
* ```
*
* @see notBetween for the inverse of this test
*/
export declare function between<T>(column: SQL.Aliased, min: T | SQLWrapper, max: T | SQLWrapper): SQL;
export declare function between<TColumn extends AnyColumn>(column: TColumn, min: GetColumnData<TColumn, 'raw'> | SQLWrapper, max: GetColumnData<TColumn, 'raw'> | SQLWrapper): SQL;
export declare function between<T extends SQLWrapper>(column: Exclude<T, SQL.Aliased | Column>, min: unknown, max: unknown): SQL;
/**
* Test whether an expression is not between two values.
*
* This, like `between`, includes its endpoints, so if
* the `column` is equal to `min` or `max`, in this case
* it will evaluate to FALSE.
*
* ## Examples
*
* ```ts
* // Exclude cars made in the 1970s
* db.select().from(cars)
* .where(notBetween(cars.year, 1970, 1979))
* ```
*
* @see between for the inverse of this test
*/
export declare function notBetween<T>(column: SQL.Aliased, min: T | SQLWrapper, max: T | SQLWrapper): SQL;
export declare function notBetween<TColumn extends AnyColumn>(column: TColumn, min: GetColumnData<TColumn, 'raw'> | SQLWrapper, max: GetColumnData<TColumn, 'raw'> | SQLWrapper): SQL;
export declare function notBetween<T extends SQLWrapper>(column: Exclude<T, SQL.Aliased | Column>, min: unknown, max: unknown): SQL;
/**
* Compare a column to a pattern, which can include `%` and `_`
* characters to match multiple variations. Including `%`
* in the pattern matches zero or more characters, and including
* `_` will match a single character.
*
* ## Examples
*
* ```ts
* // Select all cars with 'Turbo' in their names.
* db.select().from(cars)
* .where(like(cars.name, '%Turbo%'))
* ```
*
* @see ilike for a case-insensitive version of this condition
*/
export declare function like(column: Column | SQL.Aliased | SQL, value: string | SQLWrapper): SQL;
/**
* The inverse of like - this tests that a given column
* does not match a pattern, which can include `%` and `_`
* characters to match multiple variations. Including `%`
* in the pattern matches zero or more characters, and including
* `_` will match a single character.
*
* ## Examples
*
* ```ts
* // Select all cars that don't have "ROver" in their name.
* db.select().from(cars)
* .where(notLike(cars.name, '%Rover%'))
* ```
*
* @see like for the inverse condition
* @see notIlike for a case-insensitive version of this condition
*/
export declare function notLike(column: Column | SQL.Aliased | SQL, value: string | SQLWrapper): SQL;
/**
* Case-insensitively compare a column to a pattern,
* which can include `%` and `_`
* characters to match multiple variations. Including `%`
* in the pattern matches zero or more characters, and including
* `_` will match a single character.
*
* Unlike like, this performs a case-insensitive comparison.
*
* ## Examples
*
* ```ts
* // Select all cars with 'Turbo' in their names.
* db.select().from(cars)
* .where(ilike(cars.name, '%Turbo%'))
* ```
*
* @see like for a case-sensitive version of this condition
*/
export declare function ilike(column: Column | SQL.Aliased | SQL, value: string | SQLWrapper): SQL;
/**
* The inverse of ilike - this case-insensitively tests that a given column
* does not match a pattern, which can include `%` and `_`
* characters to match multiple variations. Including `%`
* in the pattern matches zero or more characters, and including
* `_` will match a single character.
*
* ## Examples
*
* ```ts
* // Select all cars that don't have "Rover" in their name.
* db.select().from(cars)
* .where(notLike(cars.name, '%Rover%'))
* ```
*
* @see ilike for the inverse condition
* @see notLike for a case-sensitive version of this condition
*/
export declare function notIlike(column: Column | SQL.Aliased | SQL, value: string | SQLWrapper): SQL;
/**
* Test that a column or expression contains all elements of
* the list passed as the second argument.
*
* ## Throws
*
* The argument passed in the second array can't be empty:
* if an empty is provided, this method will throw.
*
* ## Examples
*
* ```ts
* // Select posts where its tags contain "Typescript" and "ORM".
* db.select().from(posts)
* .where(arrayContains(posts.tags, ['Typescript', 'ORM']))
* ```
*
* @see arrayContained to find if an array contains all elements of a column or expression
* @see arrayOverlaps to find if a column or expression contains any elements of an array
*/
export declare function arrayContains<T>(column: SQL.Aliased<T>, values: (T | Placeholder) | SQLWrapper): SQL;
export declare function arrayContains<TColumn extends Column>(column: TColumn, values: (GetColumnData<TColumn, 'raw'> | Placeholder) | SQLWrapper): SQL;
export declare function arrayContains<T extends SQLWrapper>(column: Exclude<T, SQL.Aliased | Column>, values: (unknown | Placeholder)[] | SQLWrapper): SQL;
/**
* Test that the list passed as the second argument contains
* all elements of a column or expression.
*
* ## Throws
*
* The argument passed in the second array can't be empty:
* if an empty is provided, this method will throw.
*
* ## Examples
*
* ```ts
* // Select posts where its tags contain "Typescript", "ORM" or both,
* // but filtering posts that have additional tags.
* db.select().from(posts)
* .where(arrayContained(posts.tags, ['Typescript', 'ORM']))
* ```
*
* @see arrayContains to find if a column or expression contains all elements of an array
* @see arrayOverlaps to find if a column or expression contains any elements of an array
*/
export declare function arrayContained<T>(column: SQL.Aliased<T>, values: (T | Placeholder) | SQLWrapper): SQL;
export declare function arrayContained<TColumn extends Column>(column: TColumn, values: (GetColumnData<TColumn, 'raw'> | Placeholder) | SQLWrapper): SQL;
export declare function arrayContained<T extends SQLWrapper>(column: Exclude<T, SQL.Aliased | Column>, values: (unknown | Placeholder)[] | SQLWrapper): SQL;
/**
* Test that a column or expression contains any elements of
* the list passed as the second argument.
*
* ## Throws
*
* The argument passed in the second array can't be empty:
* if an empty is provided, this method will throw.
*
* ## Examples
*
* ```ts
* // Select posts where its tags contain "Typescript", "ORM" or both.
* db.select().from(posts)
* .where(arrayOverlaps(posts.tags, ['Typescript', 'ORM']))
* ```
*
* @see arrayContains to find if a column or expression contains all elements of an array
* @see arrayContained to find if an array contains all elements of a column or expression
*/
export declare function arrayOverlaps<T>(column: SQL.Aliased<T>, values: (T | Placeholder) | SQLWrapper): SQL;
export declare function arrayOverlaps<TColumn extends Column>(column: TColumn, values: (GetColumnData<TColumn, 'raw'> | Placeholder) | SQLWrapper): SQL;
export declare function arrayOverlaps<T extends SQLWrapper>(column: Exclude<T, SQL.Aliased | Column>, values: (unknown | Placeholder)[] | SQLWrapper): SQL;

184
node_modules/drizzle-orm/sql/expressions/conditions.js generated vendored Normal file
View File

@ -0,0 +1,184 @@
import { Column } from "../../column.js";
import { is } from "../../entity.js";
import { Table } from "../../table.js";
import {
isDriverValueEncoder,
isSQLWrapper,
Param,
Placeholder,
SQL,
sql,
StringChunk,
View
} from "../sql.js";
function bindIfParam(value, column) {
if (isDriverValueEncoder(column) && !isSQLWrapper(value) && !is(value, Param) && !is(value, Placeholder) && !is(value, Column) && !is(value, Table) && !is(value, View)) {
return new Param(value, column);
}
return value;
}
const eq = (left, right) => {
return sql`${left} = ${bindIfParam(right, left)}`;
};
const ne = (left, right) => {
return sql`${left} <> ${bindIfParam(right, left)}`;
};
function and(...unfilteredConditions) {
const conditions = unfilteredConditions.filter(
(c) => c !== void 0
);
if (conditions.length === 0) {
return void 0;
}
if (conditions.length === 1) {
return new SQL(conditions);
}
return new SQL([
new StringChunk("("),
sql.join(conditions, new StringChunk(" and ")),
new StringChunk(")")
]);
}
function or(...unfilteredConditions) {
const conditions = unfilteredConditions.filter(
(c) => c !== void 0
);
if (conditions.length === 0) {
return void 0;
}
if (conditions.length === 1) {
return new SQL(conditions);
}
return new SQL([
new StringChunk("("),
sql.join(conditions, new StringChunk(" or ")),
new StringChunk(")")
]);
}
function not(condition) {
return sql`not ${condition}`;
}
const gt = (left, right) => {
return sql`${left} > ${bindIfParam(right, left)}`;
};
const gte = (left, right) => {
return sql`${left} >= ${bindIfParam(right, left)}`;
};
const lt = (left, right) => {
return sql`${left} < ${bindIfParam(right, left)}`;
};
const lte = (left, right) => {
return sql`${left} <= ${bindIfParam(right, left)}`;
};
function inArray(column, values) {
if (Array.isArray(values)) {
if (values.length === 0) {
return sql`false`;
}
return sql`${column} in ${values.map((v) => bindIfParam(v, column))}`;
}
return sql`${column} in ${bindIfParam(values, column)}`;
}
function notInArray(column, values) {
if (Array.isArray(values)) {
if (values.length === 0) {
return sql`true`;
}
return sql`${column} not in ${values.map((v) => bindIfParam(v, column))}`;
}
return sql`${column} not in ${bindIfParam(values, column)}`;
}
function isNull(value) {
return sql`${value} is null`;
}
function isNotNull(value) {
return sql`${value} is not null`;
}
function exists(subquery) {
return sql`exists ${subquery}`;
}
function notExists(subquery) {
return sql`not exists ${subquery}`;
}
function between(column, min, max) {
return sql`${column} between ${bindIfParam(min, column)} and ${bindIfParam(
max,
column
)}`;
}
function notBetween(column, min, max) {
return sql`${column} not between ${bindIfParam(
min,
column
)} and ${bindIfParam(max, column)}`;
}
function like(column, value) {
return sql`${column} like ${value}`;
}
function notLike(column, value) {
return sql`${column} not like ${value}`;
}
function ilike(column, value) {
return sql`${column} ilike ${value}`;
}
function notIlike(column, value) {
return sql`${column} not ilike ${value}`;
}
function arrayContains(column, values) {
if (Array.isArray(values)) {
if (values.length === 0) {
throw new Error("arrayContains requires at least one value");
}
const array = sql`${bindIfParam(values, column)}`;
return sql`${column} @> ${array}`;
}
return sql`${column} @> ${bindIfParam(values, column)}`;
}
function arrayContained(column, values) {
if (Array.isArray(values)) {
if (values.length === 0) {
throw new Error("arrayContained requires at least one value");
}
const array = sql`${bindIfParam(values, column)}`;
return sql`${column} <@ ${array}`;
}
return sql`${column} <@ ${bindIfParam(values, column)}`;
}
function arrayOverlaps(column, values) {
if (Array.isArray(values)) {
if (values.length === 0) {
throw new Error("arrayOverlaps requires at least one value");
}
const array = sql`${bindIfParam(values, column)}`;
return sql`${column} && ${array}`;
}
return sql`${column} && ${bindIfParam(values, column)}`;
}
export {
and,
arrayContained,
arrayContains,
arrayOverlaps,
between,
bindIfParam,
eq,
exists,
gt,
gte,
ilike,
inArray,
isNotNull,
isNull,
like,
lt,
lte,
ne,
not,
notBetween,
notExists,
notIlike,
notInArray,
notLike,
or
};
//# sourceMappingURL=conditions.js.map

File diff suppressed because one or more lines are too long

25
node_modules/drizzle-orm/sql/expressions/index.cjs generated vendored Normal file
View File

@ -0,0 +1,25 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var expressions_exports = {};
module.exports = __toCommonJS(expressions_exports);
__reExport(expressions_exports, require("./conditions.cjs"), module.exports);
__reExport(expressions_exports, require("./select.cjs"), module.exports);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
...require("./conditions.cjs"),
...require("./select.cjs")
});
//# sourceMappingURL=index.cjs.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../src/sql/expressions/index.ts"],"sourcesContent":["export * from './conditions.ts';\nexport * from './select.ts';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,gCAAc,4BAAd;AACA,gCAAc,wBADd;","names":[]}

2
node_modules/drizzle-orm/sql/expressions/index.d.cts generated vendored Normal file
View File

@ -0,0 +1,2 @@
export * from "./conditions.cjs";
export * from "./select.cjs";

2
node_modules/drizzle-orm/sql/expressions/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,2 @@
export * from "./conditions.js";
export * from "./select.js";

3
node_modules/drizzle-orm/sql/expressions/index.js generated vendored Normal file
View File

@ -0,0 +1,3 @@
export * from "./conditions.js";
export * from "./select.js";
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../src/sql/expressions/index.ts"],"sourcesContent":["export * from './conditions.ts';\nexport * from './select.ts';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}

37
node_modules/drizzle-orm/sql/expressions/select.cjs generated vendored Normal file
View File

@ -0,0 +1,37 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc2) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc2 = __getOwnPropDesc(from, key)) || desc2.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var select_exports = {};
__export(select_exports, {
asc: () => asc,
desc: () => desc
});
module.exports = __toCommonJS(select_exports);
var import_sql = require("../sql.cjs");
function asc(column) {
return import_sql.sql`${column} asc`;
}
function desc(column) {
return import_sql.sql`${column} desc`;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
asc,
desc
});
//# sourceMappingURL=select.cjs.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../src/sql/expressions/select.ts"],"sourcesContent":["import type { AnyColumn } from '../../column.ts';\nimport type { SQL, SQLWrapper } from '../sql.ts';\nimport { sql } from '../sql.ts';\n\n/**\n * Used in sorting, this specifies that the given\n * column or expression should be sorted in ascending\n * order. By the SQL standard, ascending order is the\n * default, so it is not usually necessary to specify\n * ascending sort order.\n *\n * ## Examples\n *\n * ```ts\n * // Return cars, starting with the oldest models\n * // and going in ascending order to the newest.\n * db.select().from(cars)\n * .orderBy(asc(cars.year));\n * ```\n *\n * @see desc to sort in descending order\n */\nexport function asc(column: AnyColumn | SQLWrapper): SQL {\n\treturn sql`${column} asc`;\n}\n\n/**\n * Used in sorting, this specifies that the given\n * column or expression should be sorted in descending\n * order.\n *\n * ## Examples\n *\n * ```ts\n * // Select users, with the most recently created\n * // records coming first.\n * db.select().from(users)\n * .orderBy(desc(users.createdAt));\n * ```\n *\n * @see asc to sort in ascending order\n */\nexport function desc(column: AnyColumn | SQLWrapper): SQL {\n\treturn sql`${column} desc`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,iBAAoB;AAoBb,SAAS,IAAI,QAAqC;AACxD,SAAO,iBAAM,MAAM;AACpB;AAkBO,SAAS,KAAK,QAAqC;AACzD,SAAO,iBAAM,MAAM;AACpB;","names":[]}

38
node_modules/drizzle-orm/sql/expressions/select.d.cts generated vendored Normal file
View File

@ -0,0 +1,38 @@
import type { AnyColumn } from "../../column.cjs";
import type { SQL, SQLWrapper } from "../sql.cjs";
/**
* Used in sorting, this specifies that the given
* column or expression should be sorted in ascending
* order. By the SQL standard, ascending order is the
* default, so it is not usually necessary to specify
* ascending sort order.
*
* ## Examples
*
* ```ts
* // Return cars, starting with the oldest models
* // and going in ascending order to the newest.
* db.select().from(cars)
* .orderBy(asc(cars.year));
* ```
*
* @see desc to sort in descending order
*/
export declare function asc(column: AnyColumn | SQLWrapper): SQL;
/**
* Used in sorting, this specifies that the given
* column or expression should be sorted in descending
* order.
*
* ## Examples
*
* ```ts
* // Select users, with the most recently created
* // records coming first.
* db.select().from(users)
* .orderBy(desc(users.createdAt));
* ```
*
* @see asc to sort in ascending order
*/
export declare function desc(column: AnyColumn | SQLWrapper): SQL;

38
node_modules/drizzle-orm/sql/expressions/select.d.ts generated vendored Normal file
View File

@ -0,0 +1,38 @@
import type { AnyColumn } from "../../column.js";
import type { SQL, SQLWrapper } from "../sql.js";
/**
* Used in sorting, this specifies that the given
* column or expression should be sorted in ascending
* order. By the SQL standard, ascending order is the
* default, so it is not usually necessary to specify
* ascending sort order.
*
* ## Examples
*
* ```ts
* // Return cars, starting with the oldest models
* // and going in ascending order to the newest.
* db.select().from(cars)
* .orderBy(asc(cars.year));
* ```
*
* @see desc to sort in descending order
*/
export declare function asc(column: AnyColumn | SQLWrapper): SQL;
/**
* Used in sorting, this specifies that the given
* column or expression should be sorted in descending
* order.
*
* ## Examples
*
* ```ts
* // Select users, with the most recently created
* // records coming first.
* db.select().from(users)
* .orderBy(desc(users.createdAt));
* ```
*
* @see asc to sort in ascending order
*/
export declare function desc(column: AnyColumn | SQLWrapper): SQL;

12
node_modules/drizzle-orm/sql/expressions/select.js generated vendored Normal file
View File

@ -0,0 +1,12 @@
import { sql } from "../sql.js";
function asc(column) {
return sql`${column} asc`;
}
function desc(column) {
return sql`${column} desc`;
}
export {
asc,
desc
};
//# sourceMappingURL=select.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../src/sql/expressions/select.ts"],"sourcesContent":["import type { AnyColumn } from '../../column.ts';\nimport type { SQL, SQLWrapper } from '../sql.ts';\nimport { sql } from '../sql.ts';\n\n/**\n * Used in sorting, this specifies that the given\n * column or expression should be sorted in ascending\n * order. By the SQL standard, ascending order is the\n * default, so it is not usually necessary to specify\n * ascending sort order.\n *\n * ## Examples\n *\n * ```ts\n * // Return cars, starting with the oldest models\n * // and going in ascending order to the newest.\n * db.select().from(cars)\n * .orderBy(asc(cars.year));\n * ```\n *\n * @see desc to sort in descending order\n */\nexport function asc(column: AnyColumn | SQLWrapper): SQL {\n\treturn sql`${column} asc`;\n}\n\n/**\n * Used in sorting, this specifies that the given\n * column or expression should be sorted in descending\n * order.\n *\n * ## Examples\n *\n * ```ts\n * // Select users, with the most recently created\n * // records coming first.\n * db.select().from(users)\n * .orderBy(desc(users.createdAt));\n * ```\n *\n * @see asc to sort in ascending order\n */\nexport function desc(column: AnyColumn | SQLWrapper): SQL {\n\treturn sql`${column} desc`;\n}\n"],"mappings":"AAEA,SAAS,WAAW;AAoBb,SAAS,IAAI,QAAqC;AACxD,SAAO,MAAM,MAAM;AACpB;AAkBO,SAAS,KAAK,QAAqC;AACzD,SAAO,MAAM,MAAM;AACpB;","names":[]}

69
node_modules/drizzle-orm/sql/functions/aggregate.cjs generated vendored Normal file
View File

@ -0,0 +1,69 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var aggregate_exports = {};
__export(aggregate_exports, {
avg: () => avg,
avgDistinct: () => avgDistinct,
count: () => count,
countDistinct: () => countDistinct,
max: () => max,
min: () => min,
sum: () => sum,
sumDistinct: () => sumDistinct
});
module.exports = __toCommonJS(aggregate_exports);
var import_column = require("../../column.cjs");
var import_entity = require("../../entity.cjs");
var import_sql = require("../sql.cjs");
function count(expression) {
return import_sql.sql`count(${expression || import_sql.sql.raw("*")})`.mapWith(Number);
}
function countDistinct(expression) {
return import_sql.sql`count(distinct ${expression})`.mapWith(Number);
}
function avg(expression) {
return import_sql.sql`avg(${expression})`.mapWith(String);
}
function avgDistinct(expression) {
return import_sql.sql`avg(distinct ${expression})`.mapWith(String);
}
function sum(expression) {
return import_sql.sql`sum(${expression})`.mapWith(String);
}
function sumDistinct(expression) {
return import_sql.sql`sum(distinct ${expression})`.mapWith(String);
}
function max(expression) {
return import_sql.sql`max(${expression})`.mapWith((0, import_entity.is)(expression, import_column.Column) ? expression : String);
}
function min(expression) {
return import_sql.sql`min(${expression})`.mapWith((0, import_entity.is)(expression, import_column.Column) ? expression : String);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
avg,
avgDistinct,
count,
countDistinct,
max,
min,
sum,
sumDistinct
});
//# sourceMappingURL=aggregate.cjs.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../src/sql/functions/aggregate.ts"],"sourcesContent":["import { type AnyColumn, Column } from '~/column.ts';\nimport { is } from '~/entity.ts';\nimport { type SQL, sql, type SQLWrapper } from '../sql.ts';\n\n/**\n * Returns the number of values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Number employees with null values\n * db.select({ value: count() }).from(employees)\n * // Number of employees where `name` is not null\n * db.select({ value: count(employees.name) }).from(employees)\n * ```\n *\n * @see countDistinct to get the number of non-duplicate values in `expression`\n */\nexport function count(expression?: SQLWrapper): SQL<number> {\n\treturn sql`count(${expression || sql.raw('*')})`.mapWith(Number);\n}\n\n/**\n * Returns the number of non-duplicate values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Number of employees where `name` is distinct\n * db.select({ value: countDistinct(employees.name) }).from(employees)\n * ```\n *\n * @see count to get the number of values in `expression`, including duplicates\n */\nexport function countDistinct(expression: SQLWrapper): SQL<number> {\n\treturn sql`count(distinct ${expression})`.mapWith(Number);\n}\n\n/**\n * Returns the average (arithmetic mean) of all non-null values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Average salary of an employee\n * db.select({ value: avg(employees.salary) }).from(employees)\n * ```\n *\n * @see avgDistinct to get the average of all non-null and non-duplicate values in `expression`\n */\nexport function avg(expression: SQLWrapper): SQL<string | null> {\n\treturn sql`avg(${expression})`.mapWith(String);\n}\n\n/**\n * Returns the average (arithmetic mean) of all non-null and non-duplicate values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Average salary of an employee where `salary` is distinct\n * db.select({ value: avgDistinct(employees.salary) }).from(employees)\n * ```\n *\n * @see avg to get the average of all non-null values in `expression`, including duplicates\n */\nexport function avgDistinct(expression: SQLWrapper): SQL<string | null> {\n\treturn sql`avg(distinct ${expression})`.mapWith(String);\n}\n\n/**\n * Returns the sum of all non-null values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Sum of every employee's salary\n * db.select({ value: sum(employees.salary) }).from(employees)\n * ```\n *\n * @see sumDistinct to get the sum of all non-null and non-duplicate values in `expression`\n */\nexport function sum(expression: SQLWrapper): SQL<string | null> {\n\treturn sql`sum(${expression})`.mapWith(String);\n}\n\n/**\n * Returns the sum of all non-null and non-duplicate values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Sum of every employee's salary where `salary` is distinct (no duplicates)\n * db.select({ value: sumDistinct(employees.salary) }).from(employees)\n * ```\n *\n * @see sum to get the sum of all non-null values in `expression`, including duplicates\n */\nexport function sumDistinct(expression: SQLWrapper): SQL<string | null> {\n\treturn sql`sum(distinct ${expression})`.mapWith(String);\n}\n\n/**\n * Returns the maximum value in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // The employee with the highest salary\n * db.select({ value: max(employees.salary) }).from(employees)\n * ```\n */\nexport function max<T extends SQLWrapper>(expression: T): SQL<(T extends AnyColumn ? T['_']['data'] : string) | null> {\n\treturn sql`max(${expression})`.mapWith(is(expression, Column) ? expression : String) as any;\n}\n\n/**\n * Returns the minimum value in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // The employee with the lowest salary\n * db.select({ value: min(employees.salary) }).from(employees)\n * ```\n */\nexport function min<T extends SQLWrapper>(expression: T): SQL<(T extends AnyColumn ? T['_']['data'] : string) | null> {\n\treturn sql`min(${expression})`.mapWith(is(expression, Column) ? expression : String) as any;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAuC;AACvC,oBAAmB;AACnB,iBAA+C;AAgBxC,SAAS,MAAM,YAAsC;AAC3D,SAAO,uBAAY,cAAc,eAAI,IAAI,GAAG,CAAC,IAAI,QAAQ,MAAM;AAChE;AAcO,SAAS,cAAc,YAAqC;AAClE,SAAO,gCAAqB,UAAU,IAAI,QAAQ,MAAM;AACzD;AAcO,SAAS,IAAI,YAA4C;AAC/D,SAAO,qBAAU,UAAU,IAAI,QAAQ,MAAM;AAC9C;AAcO,SAAS,YAAY,YAA4C;AACvE,SAAO,8BAAmB,UAAU,IAAI,QAAQ,MAAM;AACvD;AAcO,SAAS,IAAI,YAA4C;AAC/D,SAAO,qBAAU,UAAU,IAAI,QAAQ,MAAM;AAC9C;AAcO,SAAS,YAAY,YAA4C;AACvE,SAAO,8BAAmB,UAAU,IAAI,QAAQ,MAAM;AACvD;AAYO,SAAS,IAA0B,YAA4E;AACrH,SAAO,qBAAU,UAAU,IAAI,YAAQ,kBAAG,YAAY,oBAAM,IAAI,aAAa,MAAM;AACpF;AAYO,SAAS,IAA0B,YAA4E;AACrH,SAAO,qBAAU,UAAU,IAAI,YAAQ,kBAAG,YAAY,oBAAM,IAAI,aAAa,MAAM;AACpF;","names":[]}

104
node_modules/drizzle-orm/sql/functions/aggregate.d.cts generated vendored Normal file
View File

@ -0,0 +1,104 @@
import { type AnyColumn } from "../../column.cjs";
import { type SQL, type SQLWrapper } from "../sql.cjs";
/**
* Returns the number of values in `expression`.
*
* ## Examples
*
* ```ts
* // Number employees with null values
* db.select({ value: count() }).from(employees)
* // Number of employees where `name` is not null
* db.select({ value: count(employees.name) }).from(employees)
* ```
*
* @see countDistinct to get the number of non-duplicate values in `expression`
*/
export declare function count(expression?: SQLWrapper): SQL<number>;
/**
* Returns the number of non-duplicate values in `expression`.
*
* ## Examples
*
* ```ts
* // Number of employees where `name` is distinct
* db.select({ value: countDistinct(employees.name) }).from(employees)
* ```
*
* @see count to get the number of values in `expression`, including duplicates
*/
export declare function countDistinct(expression: SQLWrapper): SQL<number>;
/**
* Returns the average (arithmetic mean) of all non-null values in `expression`.
*
* ## Examples
*
* ```ts
* // Average salary of an employee
* db.select({ value: avg(employees.salary) }).from(employees)
* ```
*
* @see avgDistinct to get the average of all non-null and non-duplicate values in `expression`
*/
export declare function avg(expression: SQLWrapper): SQL<string | null>;
/**
* Returns the average (arithmetic mean) of all non-null and non-duplicate values in `expression`.
*
* ## Examples
*
* ```ts
* // Average salary of an employee where `salary` is distinct
* db.select({ value: avgDistinct(employees.salary) }).from(employees)
* ```
*
* @see avg to get the average of all non-null values in `expression`, including duplicates
*/
export declare function avgDistinct(expression: SQLWrapper): SQL<string | null>;
/**
* Returns the sum of all non-null values in `expression`.
*
* ## Examples
*
* ```ts
* // Sum of every employee's salary
* db.select({ value: sum(employees.salary) }).from(employees)
* ```
*
* @see sumDistinct to get the sum of all non-null and non-duplicate values in `expression`
*/
export declare function sum(expression: SQLWrapper): SQL<string | null>;
/**
* Returns the sum of all non-null and non-duplicate values in `expression`.
*
* ## Examples
*
* ```ts
* // Sum of every employee's salary where `salary` is distinct (no duplicates)
* db.select({ value: sumDistinct(employees.salary) }).from(employees)
* ```
*
* @see sum to get the sum of all non-null values in `expression`, including duplicates
*/
export declare function sumDistinct(expression: SQLWrapper): SQL<string | null>;
/**
* Returns the maximum value in `expression`.
*
* ## Examples
*
* ```ts
* // The employee with the highest salary
* db.select({ value: max(employees.salary) }).from(employees)
* ```
*/
export declare function max<T extends SQLWrapper>(expression: T): SQL<(T extends AnyColumn ? T['_']['data'] : string) | null>;
/**
* Returns the minimum value in `expression`.
*
* ## Examples
*
* ```ts
* // The employee with the lowest salary
* db.select({ value: min(employees.salary) }).from(employees)
* ```
*/
export declare function min<T extends SQLWrapper>(expression: T): SQL<(T extends AnyColumn ? T['_']['data'] : string) | null>;

104
node_modules/drizzle-orm/sql/functions/aggregate.d.ts generated vendored Normal file
View File

@ -0,0 +1,104 @@
import { type AnyColumn } from "../../column.js";
import { type SQL, type SQLWrapper } from "../sql.js";
/**
* Returns the number of values in `expression`.
*
* ## Examples
*
* ```ts
* // Number employees with null values
* db.select({ value: count() }).from(employees)
* // Number of employees where `name` is not null
* db.select({ value: count(employees.name) }).from(employees)
* ```
*
* @see countDistinct to get the number of non-duplicate values in `expression`
*/
export declare function count(expression?: SQLWrapper): SQL<number>;
/**
* Returns the number of non-duplicate values in `expression`.
*
* ## Examples
*
* ```ts
* // Number of employees where `name` is distinct
* db.select({ value: countDistinct(employees.name) }).from(employees)
* ```
*
* @see count to get the number of values in `expression`, including duplicates
*/
export declare function countDistinct(expression: SQLWrapper): SQL<number>;
/**
* Returns the average (arithmetic mean) of all non-null values in `expression`.
*
* ## Examples
*
* ```ts
* // Average salary of an employee
* db.select({ value: avg(employees.salary) }).from(employees)
* ```
*
* @see avgDistinct to get the average of all non-null and non-duplicate values in `expression`
*/
export declare function avg(expression: SQLWrapper): SQL<string | null>;
/**
* Returns the average (arithmetic mean) of all non-null and non-duplicate values in `expression`.
*
* ## Examples
*
* ```ts
* // Average salary of an employee where `salary` is distinct
* db.select({ value: avgDistinct(employees.salary) }).from(employees)
* ```
*
* @see avg to get the average of all non-null values in `expression`, including duplicates
*/
export declare function avgDistinct(expression: SQLWrapper): SQL<string | null>;
/**
* Returns the sum of all non-null values in `expression`.
*
* ## Examples
*
* ```ts
* // Sum of every employee's salary
* db.select({ value: sum(employees.salary) }).from(employees)
* ```
*
* @see sumDistinct to get the sum of all non-null and non-duplicate values in `expression`
*/
export declare function sum(expression: SQLWrapper): SQL<string | null>;
/**
* Returns the sum of all non-null and non-duplicate values in `expression`.
*
* ## Examples
*
* ```ts
* // Sum of every employee's salary where `salary` is distinct (no duplicates)
* db.select({ value: sumDistinct(employees.salary) }).from(employees)
* ```
*
* @see sum to get the sum of all non-null values in `expression`, including duplicates
*/
export declare function sumDistinct(expression: SQLWrapper): SQL<string | null>;
/**
* Returns the maximum value in `expression`.
*
* ## Examples
*
* ```ts
* // The employee with the highest salary
* db.select({ value: max(employees.salary) }).from(employees)
* ```
*/
export declare function max<T extends SQLWrapper>(expression: T): SQL<(T extends AnyColumn ? T['_']['data'] : string) | null>;
/**
* Returns the minimum value in `expression`.
*
* ## Examples
*
* ```ts
* // The employee with the lowest salary
* db.select({ value: min(employees.salary) }).from(employees)
* ```
*/
export declare function min<T extends SQLWrapper>(expression: T): SQL<(T extends AnyColumn ? T['_']['data'] : string) | null>;

38
node_modules/drizzle-orm/sql/functions/aggregate.js generated vendored Normal file
View File

@ -0,0 +1,38 @@
import { Column } from "../../column.js";
import { is } from "../../entity.js";
import { sql } from "../sql.js";
function count(expression) {
return sql`count(${expression || sql.raw("*")})`.mapWith(Number);
}
function countDistinct(expression) {
return sql`count(distinct ${expression})`.mapWith(Number);
}
function avg(expression) {
return sql`avg(${expression})`.mapWith(String);
}
function avgDistinct(expression) {
return sql`avg(distinct ${expression})`.mapWith(String);
}
function sum(expression) {
return sql`sum(${expression})`.mapWith(String);
}
function sumDistinct(expression) {
return sql`sum(distinct ${expression})`.mapWith(String);
}
function max(expression) {
return sql`max(${expression})`.mapWith(is(expression, Column) ? expression : String);
}
function min(expression) {
return sql`min(${expression})`.mapWith(is(expression, Column) ? expression : String);
}
export {
avg,
avgDistinct,
count,
countDistinct,
max,
min,
sum,
sumDistinct
};
//# sourceMappingURL=aggregate.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../src/sql/functions/aggregate.ts"],"sourcesContent":["import { type AnyColumn, Column } from '~/column.ts';\nimport { is } from '~/entity.ts';\nimport { type SQL, sql, type SQLWrapper } from '../sql.ts';\n\n/**\n * Returns the number of values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Number employees with null values\n * db.select({ value: count() }).from(employees)\n * // Number of employees where `name` is not null\n * db.select({ value: count(employees.name) }).from(employees)\n * ```\n *\n * @see countDistinct to get the number of non-duplicate values in `expression`\n */\nexport function count(expression?: SQLWrapper): SQL<number> {\n\treturn sql`count(${expression || sql.raw('*')})`.mapWith(Number);\n}\n\n/**\n * Returns the number of non-duplicate values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Number of employees where `name` is distinct\n * db.select({ value: countDistinct(employees.name) }).from(employees)\n * ```\n *\n * @see count to get the number of values in `expression`, including duplicates\n */\nexport function countDistinct(expression: SQLWrapper): SQL<number> {\n\treturn sql`count(distinct ${expression})`.mapWith(Number);\n}\n\n/**\n * Returns the average (arithmetic mean) of all non-null values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Average salary of an employee\n * db.select({ value: avg(employees.salary) }).from(employees)\n * ```\n *\n * @see avgDistinct to get the average of all non-null and non-duplicate values in `expression`\n */\nexport function avg(expression: SQLWrapper): SQL<string | null> {\n\treturn sql`avg(${expression})`.mapWith(String);\n}\n\n/**\n * Returns the average (arithmetic mean) of all non-null and non-duplicate values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Average salary of an employee where `salary` is distinct\n * db.select({ value: avgDistinct(employees.salary) }).from(employees)\n * ```\n *\n * @see avg to get the average of all non-null values in `expression`, including duplicates\n */\nexport function avgDistinct(expression: SQLWrapper): SQL<string | null> {\n\treturn sql`avg(distinct ${expression})`.mapWith(String);\n}\n\n/**\n * Returns the sum of all non-null values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Sum of every employee's salary\n * db.select({ value: sum(employees.salary) }).from(employees)\n * ```\n *\n * @see sumDistinct to get the sum of all non-null and non-duplicate values in `expression`\n */\nexport function sum(expression: SQLWrapper): SQL<string | null> {\n\treturn sql`sum(${expression})`.mapWith(String);\n}\n\n/**\n * Returns the sum of all non-null and non-duplicate values in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // Sum of every employee's salary where `salary` is distinct (no duplicates)\n * db.select({ value: sumDistinct(employees.salary) }).from(employees)\n * ```\n *\n * @see sum to get the sum of all non-null values in `expression`, including duplicates\n */\nexport function sumDistinct(expression: SQLWrapper): SQL<string | null> {\n\treturn sql`sum(distinct ${expression})`.mapWith(String);\n}\n\n/**\n * Returns the maximum value in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // The employee with the highest salary\n * db.select({ value: max(employees.salary) }).from(employees)\n * ```\n */\nexport function max<T extends SQLWrapper>(expression: T): SQL<(T extends AnyColumn ? T['_']['data'] : string) | null> {\n\treturn sql`max(${expression})`.mapWith(is(expression, Column) ? expression : String) as any;\n}\n\n/**\n * Returns the minimum value in `expression`.\n *\n * ## Examples\n *\n * ```ts\n * // The employee with the lowest salary\n * db.select({ value: min(employees.salary) }).from(employees)\n * ```\n */\nexport function min<T extends SQLWrapper>(expression: T): SQL<(T extends AnyColumn ? T['_']['data'] : string) | null> {\n\treturn sql`min(${expression})`.mapWith(is(expression, Column) ? expression : String) as any;\n}\n"],"mappings":"AAAA,SAAyB,cAAc;AACvC,SAAS,UAAU;AACnB,SAAmB,WAA4B;AAgBxC,SAAS,MAAM,YAAsC;AAC3D,SAAO,YAAY,cAAc,IAAI,IAAI,GAAG,CAAC,IAAI,QAAQ,MAAM;AAChE;AAcO,SAAS,cAAc,YAAqC;AAClE,SAAO,qBAAqB,UAAU,IAAI,QAAQ,MAAM;AACzD;AAcO,SAAS,IAAI,YAA4C;AAC/D,SAAO,UAAU,UAAU,IAAI,QAAQ,MAAM;AAC9C;AAcO,SAAS,YAAY,YAA4C;AACvE,SAAO,mBAAmB,UAAU,IAAI,QAAQ,MAAM;AACvD;AAcO,SAAS,IAAI,YAA4C;AAC/D,SAAO,UAAU,UAAU,IAAI,QAAQ,MAAM;AAC9C;AAcO,SAAS,YAAY,YAA4C;AACvE,SAAO,mBAAmB,UAAU,IAAI,QAAQ,MAAM;AACvD;AAYO,SAAS,IAA0B,YAA4E;AACrH,SAAO,UAAU,UAAU,IAAI,QAAQ,GAAG,YAAY,MAAM,IAAI,aAAa,MAAM;AACpF;AAYO,SAAS,IAA0B,YAA4E;AACrH,SAAO,UAAU,UAAU,IAAI,QAAQ,GAAG,YAAY,MAAM,IAAI,aAAa,MAAM;AACpF;","names":[]}

25
node_modules/drizzle-orm/sql/functions/index.cjs generated vendored Normal file
View File

@ -0,0 +1,25 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var functions_exports = {};
module.exports = __toCommonJS(functions_exports);
__reExport(functions_exports, require("./aggregate.cjs"), module.exports);
__reExport(functions_exports, require("./vector.cjs"), module.exports);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
...require("./aggregate.cjs"),
...require("./vector.cjs")
});
//# sourceMappingURL=index.cjs.map

1
node_modules/drizzle-orm/sql/functions/index.cjs.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../src/sql/functions/index.ts"],"sourcesContent":["export * from './aggregate.ts';\nexport * from './vector.ts';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,8BAAc,2BAAd;AACA,8BAAc,wBADd;","names":[]}

2
node_modules/drizzle-orm/sql/functions/index.d.cts generated vendored Normal file
View File

@ -0,0 +1,2 @@
export * from "./aggregate.cjs";
export * from "./vector.cjs";

2
node_modules/drizzle-orm/sql/functions/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,2 @@
export * from "./aggregate.js";
export * from "./vector.js";

3
node_modules/drizzle-orm/sql/functions/index.js generated vendored Normal file
View File

@ -0,0 +1,3 @@
export * from "./aggregate.js";
export * from "./vector.js";
//# sourceMappingURL=index.js.map

1
node_modules/drizzle-orm/sql/functions/index.js.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../src/sql/functions/index.ts"],"sourcesContent":["export * from './aggregate.ts';\nexport * from './vector.ts';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}

78
node_modules/drizzle-orm/sql/functions/vector.cjs generated vendored Normal file
View File

@ -0,0 +1,78 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var vector_exports = {};
__export(vector_exports, {
cosineDistance: () => cosineDistance,
hammingDistance: () => hammingDistance,
innerProduct: () => innerProduct,
jaccardDistance: () => jaccardDistance,
l1Distance: () => l1Distance,
l2Distance: () => l2Distance
});
module.exports = __toCommonJS(vector_exports);
var import_sql = require("../sql.cjs");
function toSql(value) {
return JSON.stringify(value);
}
function l2Distance(column, value) {
if (Array.isArray(value)) {
return import_sql.sql`${column} <-> ${toSql(value)}`;
}
return import_sql.sql`${column} <-> ${value}`;
}
function l1Distance(column, value) {
if (Array.isArray(value)) {
return import_sql.sql`${column} <+> ${toSql(value)}`;
}
return import_sql.sql`${column} <+> ${value}`;
}
function innerProduct(column, value) {
if (Array.isArray(value)) {
return import_sql.sql`${column} <#> ${toSql(value)}`;
}
return import_sql.sql`${column} <#> ${value}`;
}
function cosineDistance(column, value) {
if (Array.isArray(value)) {
return import_sql.sql`${column} <=> ${toSql(value)}`;
}
return import_sql.sql`${column} <=> ${value}`;
}
function hammingDistance(column, value) {
if (Array.isArray(value)) {
return import_sql.sql`${column} <~> ${toSql(value)}`;
}
return import_sql.sql`${column} <~> ${value}`;
}
function jaccardDistance(column, value) {
if (Array.isArray(value)) {
return import_sql.sql`${column} <%> ${toSql(value)}`;
}
return import_sql.sql`${column} <%> ${value}`;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
cosineDistance,
hammingDistance,
innerProduct,
jaccardDistance,
l1Distance,
l2Distance
});
//# sourceMappingURL=vector.cjs.map

File diff suppressed because one or more lines are too long

120
node_modules/drizzle-orm/sql/functions/vector.d.cts generated vendored Normal file
View File

@ -0,0 +1,120 @@
import type { AnyColumn } from "../../column.cjs";
import type { TypedQueryBuilder } from "../../query-builders/query-builder.cjs";
import { type SQL, type SQLWrapper } from "../sql.cjs";
/**
* Used in sorting and in querying, if used in sorting,
* this specifies that the given column or expression should be sorted in an order
* that minimizes the L2 distance to the given value.
* If used in querying, this specifies that it should return the L2 distance
* between the given column or expression and the given value.
*
* ## Examples
*
* ```ts
* // Sort cars by embedding similarity
* // to the given embedding
* db.select().from(cars)
* .orderBy(l2Distance(cars.embedding, embedding));
* ```
*
* ```ts
* // Select distance of cars and embedding
* // to the given embedding
* db.select({distance: l2Distance(cars.embedding, embedding)}).from(cars)
* ```
*/
export declare function l2Distance(column: SQLWrapper | AnyColumn, value: number[] | string[] | TypedQueryBuilder<any> | string): SQL;
/**
* L1 distance is one of the possible distance measures between two probability distribution vectors and it is
* calculated as the sum of the absolute differences.
* The smaller the distance between the observed probability vectors, the higher the accuracy of the synthetic data
*
* ## Examples
*
* ```ts
* // Sort cars by embedding similarity
* // to the given embedding
* db.select().from(cars)
* .orderBy(l1Distance(cars.embedding, embedding));
* ```
*
* ```ts
* // Select distance of cars and embedding
* // to the given embedding
* db.select({distance: l1Distance(cars.embedding, embedding)}).from(cars)
* ```
*/
export declare function l1Distance(column: SQLWrapper | AnyColumn, value: number[] | string[] | TypedQueryBuilder<any> | string): SQL;
/**
* Used in sorting and in querying, if used in sorting,
* this specifies that the given column or expression should be sorted in an order
* that minimizes the inner product distance to the given value.
* If used in querying, this specifies that it should return the inner product distance
* between the given column or expression and the given value.
*
* ## Examples
*
* ```ts
* // Sort cars by embedding similarity
* // to the given embedding
* db.select().from(cars)
* .orderBy(innerProduct(cars.embedding, embedding));
* ```
*
* ```ts
* // Select distance of cars and embedding
* // to the given embedding
* db.select({ distance: innerProduct(cars.embedding, embedding) }).from(cars)
* ```
*/
export declare function innerProduct(column: SQLWrapper | AnyColumn, value: number[] | string[] | TypedQueryBuilder<any> | string): SQL;
/**
* Used in sorting and in querying, if used in sorting,
* this specifies that the given column or expression should be sorted in an order
* that minimizes the cosine distance to the given value.
* If used in querying, this specifies that it should return the cosine distance
* between the given column or expression and the given value.
*
* ## Examples
*
* ```ts
* // Sort cars by embedding similarity
* // to the given embedding
* db.select().from(cars)
* .orderBy(cosineDistance(cars.embedding, embedding));
* ```
*
* ```ts
* // Select distance of cars and embedding
* // to the given embedding
* db.select({distance: cosineDistance(cars.embedding, embedding)}).from(cars)
* ```
*/
export declare function cosineDistance(column: SQLWrapper | AnyColumn, value: number[] | string[] | TypedQueryBuilder<any> | string): SQL;
/**
* Hamming distance between two strings or vectors of equal length is the number of positions at which the
* corresponding symbols are different. In other words, it measures the minimum number of
* substitutions required to change one string into the other, or equivalently,
* the minimum number of errors that could have transformed one string into the other
*
* ## Examples
*
* ```ts
* // Sort cars by embedding similarity
* // to the given embedding
* db.select().from(cars)
* .orderBy(hammingDistance(cars.embedding, embedding));
* ```
*/
export declare function hammingDistance(column: SQLWrapper | AnyColumn, value: number[] | string[] | TypedQueryBuilder<any> | string): SQL;
/**
* ## Examples
*
* ```ts
* // Sort cars by embedding similarity
* // to the given embedding
* db.select().from(cars)
* .orderBy(jaccardDistance(cars.embedding, embedding));
* ```
*/
export declare function jaccardDistance(column: SQLWrapper | AnyColumn, value: number[] | string[] | TypedQueryBuilder<any> | string): SQL;

120
node_modules/drizzle-orm/sql/functions/vector.d.ts generated vendored Normal file
View File

@ -0,0 +1,120 @@
import type { AnyColumn } from "../../column.js";
import type { TypedQueryBuilder } from "../../query-builders/query-builder.js";
import { type SQL, type SQLWrapper } from "../sql.js";
/**
* Used in sorting and in querying, if used in sorting,
* this specifies that the given column or expression should be sorted in an order
* that minimizes the L2 distance to the given value.
* If used in querying, this specifies that it should return the L2 distance
* between the given column or expression and the given value.
*
* ## Examples
*
* ```ts
* // Sort cars by embedding similarity
* // to the given embedding
* db.select().from(cars)
* .orderBy(l2Distance(cars.embedding, embedding));
* ```
*
* ```ts
* // Select distance of cars and embedding
* // to the given embedding
* db.select({distance: l2Distance(cars.embedding, embedding)}).from(cars)
* ```
*/
export declare function l2Distance(column: SQLWrapper | AnyColumn, value: number[] | string[] | TypedQueryBuilder<any> | string): SQL;
/**
* L1 distance is one of the possible distance measures between two probability distribution vectors and it is
* calculated as the sum of the absolute differences.
* The smaller the distance between the observed probability vectors, the higher the accuracy of the synthetic data
*
* ## Examples
*
* ```ts
* // Sort cars by embedding similarity
* // to the given embedding
* db.select().from(cars)
* .orderBy(l1Distance(cars.embedding, embedding));
* ```
*
* ```ts
* // Select distance of cars and embedding
* // to the given embedding
* db.select({distance: l1Distance(cars.embedding, embedding)}).from(cars)
* ```
*/
export declare function l1Distance(column: SQLWrapper | AnyColumn, value: number[] | string[] | TypedQueryBuilder<any> | string): SQL;
/**
* Used in sorting and in querying, if used in sorting,
* this specifies that the given column or expression should be sorted in an order
* that minimizes the inner product distance to the given value.
* If used in querying, this specifies that it should return the inner product distance
* between the given column or expression and the given value.
*
* ## Examples
*
* ```ts
* // Sort cars by embedding similarity
* // to the given embedding
* db.select().from(cars)
* .orderBy(innerProduct(cars.embedding, embedding));
* ```
*
* ```ts
* // Select distance of cars and embedding
* // to the given embedding
* db.select({ distance: innerProduct(cars.embedding, embedding) }).from(cars)
* ```
*/
export declare function innerProduct(column: SQLWrapper | AnyColumn, value: number[] | string[] | TypedQueryBuilder<any> | string): SQL;
/**
* Used in sorting and in querying, if used in sorting,
* this specifies that the given column or expression should be sorted in an order
* that minimizes the cosine distance to the given value.
* If used in querying, this specifies that it should return the cosine distance
* between the given column or expression and the given value.
*
* ## Examples
*
* ```ts
* // Sort cars by embedding similarity
* // to the given embedding
* db.select().from(cars)
* .orderBy(cosineDistance(cars.embedding, embedding));
* ```
*
* ```ts
* // Select distance of cars and embedding
* // to the given embedding
* db.select({distance: cosineDistance(cars.embedding, embedding)}).from(cars)
* ```
*/
export declare function cosineDistance(column: SQLWrapper | AnyColumn, value: number[] | string[] | TypedQueryBuilder<any> | string): SQL;
/**
* Hamming distance between two strings or vectors of equal length is the number of positions at which the
* corresponding symbols are different. In other words, it measures the minimum number of
* substitutions required to change one string into the other, or equivalently,
* the minimum number of errors that could have transformed one string into the other
*
* ## Examples
*
* ```ts
* // Sort cars by embedding similarity
* // to the given embedding
* db.select().from(cars)
* .orderBy(hammingDistance(cars.embedding, embedding));
* ```
*/
export declare function hammingDistance(column: SQLWrapper | AnyColumn, value: number[] | string[] | TypedQueryBuilder<any> | string): SQL;
/**
* ## Examples
*
* ```ts
* // Sort cars by embedding similarity
* // to the given embedding
* db.select().from(cars)
* .orderBy(jaccardDistance(cars.embedding, embedding));
* ```
*/
export declare function jaccardDistance(column: SQLWrapper | AnyColumn, value: number[] | string[] | TypedQueryBuilder<any> | string): SQL;

49
node_modules/drizzle-orm/sql/functions/vector.js generated vendored Normal file
View File

@ -0,0 +1,49 @@
import { sql } from "../sql.js";
function toSql(value) {
return JSON.stringify(value);
}
function l2Distance(column, value) {
if (Array.isArray(value)) {
return sql`${column} <-> ${toSql(value)}`;
}
return sql`${column} <-> ${value}`;
}
function l1Distance(column, value) {
if (Array.isArray(value)) {
return sql`${column} <+> ${toSql(value)}`;
}
return sql`${column} <+> ${value}`;
}
function innerProduct(column, value) {
if (Array.isArray(value)) {
return sql`${column} <#> ${toSql(value)}`;
}
return sql`${column} <#> ${value}`;
}
function cosineDistance(column, value) {
if (Array.isArray(value)) {
return sql`${column} <=> ${toSql(value)}`;
}
return sql`${column} <=> ${value}`;
}
function hammingDistance(column, value) {
if (Array.isArray(value)) {
return sql`${column} <~> ${toSql(value)}`;
}
return sql`${column} <~> ${value}`;
}
function jaccardDistance(column, value) {
if (Array.isArray(value)) {
return sql`${column} <%> ${toSql(value)}`;
}
return sql`${column} <%> ${value}`;
}
export {
cosineDistance,
hammingDistance,
innerProduct,
jaccardDistance,
l1Distance,
l2Distance
};
//# sourceMappingURL=vector.js.map

1
node_modules/drizzle-orm/sql/functions/vector.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

27
node_modules/drizzle-orm/sql/index.cjs generated vendored Normal file
View File

@ -0,0 +1,27 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var sql_exports = {};
module.exports = __toCommonJS(sql_exports);
__reExport(sql_exports, require("./expressions/index.cjs"), module.exports);
__reExport(sql_exports, require("./functions/index.cjs"), module.exports);
__reExport(sql_exports, require("./sql.cjs"), module.exports);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
...require("./expressions/index.cjs"),
...require("./functions/index.cjs"),
...require("./sql.cjs")
});
//# sourceMappingURL=index.cjs.map

1
node_modules/drizzle-orm/sql/index.cjs.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/sql/index.ts"],"sourcesContent":["export * from './expressions/index.ts';\nexport * from './functions/index.ts';\nexport * from './sql.ts';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,mCAAd;AACA,wBAAc,iCADd;AAEA,wBAAc,qBAFd;","names":[]}

3
node_modules/drizzle-orm/sql/index.d.cts generated vendored Normal file
View File

@ -0,0 +1,3 @@
export * from "./expressions/index.cjs";
export * from "./functions/index.cjs";
export * from "./sql.cjs";

3
node_modules/drizzle-orm/sql/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,3 @@
export * from "./expressions/index.js";
export * from "./functions/index.js";
export * from "./sql.js";

4
node_modules/drizzle-orm/sql/index.js generated vendored Normal file
View File

@ -0,0 +1,4 @@
export * from "./expressions/index.js";
export * from "./functions/index.js";
export * from "./sql.js";
//# sourceMappingURL=index.js.map

1
node_modules/drizzle-orm/sql/index.js.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"sources":["../../src/sql/index.ts"],"sourcesContent":["export * from './expressions/index.ts';\nexport * from './functions/index.ts';\nexport * from './sql.ts';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}

463
node_modules/drizzle-orm/sql/sql.cjs generated vendored Normal file
View File

@ -0,0 +1,463 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name2 in all)
__defProp(target, name2, { get: all[name2], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var sql_exports = {};
__export(sql_exports, {
FakePrimitiveParam: () => FakePrimitiveParam,
Name: () => Name,
Param: () => Param,
Placeholder: () => Placeholder,
SQL: () => SQL,
StringChunk: () => StringChunk,
View: () => View,
fillPlaceholders: () => fillPlaceholders,
isDriverValueEncoder: () => isDriverValueEncoder,
isSQLWrapper: () => isSQLWrapper,
isView: () => isView,
name: () => name,
noopDecoder: () => noopDecoder,
noopEncoder: () => noopEncoder,
noopMapper: () => noopMapper,
param: () => param,
placeholder: () => placeholder,
sql: () => sql
});
module.exports = __toCommonJS(sql_exports);
var import_entity = require("../entity.cjs");
var import_enum = require("../pg-core/columns/enum.cjs");
var import_subquery = require("../subquery.cjs");
var import_tracing = require("../tracing.cjs");
var import_view_common = require("../view-common.cjs");
var import_column = require("../column.cjs");
var import_table = require("../table.cjs");
class FakePrimitiveParam {
static [import_entity.entityKind] = "FakePrimitiveParam";
}
function isSQLWrapper(value) {
return value !== null && value !== void 0 && typeof value.getSQL === "function";
}
function mergeQueries(queries) {
const result = { sql: "", params: [] };
for (const query of queries) {
result.sql += query.sql;
result.params.push(...query.params);
if (query.typings?.length) {
if (!result.typings) {
result.typings = [];
}
result.typings.push(...query.typings);
}
}
return result;
}
class StringChunk {
static [import_entity.entityKind] = "StringChunk";
value;
constructor(value) {
this.value = Array.isArray(value) ? value : [value];
}
getSQL() {
return new SQL([this]);
}
}
class SQL {
constructor(queryChunks) {
this.queryChunks = queryChunks;
}
static [import_entity.entityKind] = "SQL";
/** @internal */
decoder = noopDecoder;
shouldInlineParams = false;
append(query) {
this.queryChunks.push(...query.queryChunks);
return this;
}
toQuery(config) {
return import_tracing.tracer.startActiveSpan("drizzle.buildSQL", (span) => {
const query = this.buildQueryFromSourceParams(this.queryChunks, config);
span?.setAttributes({
"drizzle.query.text": query.sql,
"drizzle.query.params": JSON.stringify(query.params)
});
return query;
});
}
buildQueryFromSourceParams(chunks, _config) {
const config = Object.assign({}, _config, {
inlineParams: _config.inlineParams || this.shouldInlineParams,
paramStartIndex: _config.paramStartIndex || { value: 0 }
});
const {
casing,
escapeName,
escapeParam,
prepareTyping,
inlineParams,
paramStartIndex
} = config;
return mergeQueries(chunks.map((chunk) => {
if ((0, import_entity.is)(chunk, StringChunk)) {
return { sql: chunk.value.join(""), params: [] };
}
if ((0, import_entity.is)(chunk, Name)) {
return { sql: escapeName(chunk.value), params: [] };
}
if (chunk === void 0) {
return { sql: "", params: [] };
}
if (Array.isArray(chunk)) {
const result = [new StringChunk("(")];
for (const [i, p] of chunk.entries()) {
result.push(p);
if (i < chunk.length - 1) {
result.push(new StringChunk(", "));
}
}
result.push(new StringChunk(")"));
return this.buildQueryFromSourceParams(result, config);
}
if ((0, import_entity.is)(chunk, SQL)) {
return this.buildQueryFromSourceParams(chunk.queryChunks, {
...config,
inlineParams: inlineParams || chunk.shouldInlineParams
});
}
if ((0, import_entity.is)(chunk, import_table.Table)) {
const schemaName = chunk[import_table.Table.Symbol.Schema];
const tableName = chunk[import_table.Table.Symbol.Name];
return {
sql: schemaName === void 0 ? escapeName(tableName) : escapeName(schemaName) + "." + escapeName(tableName),
params: []
};
}
if ((0, import_entity.is)(chunk, import_column.Column)) {
const columnName = casing.getColumnCasing(chunk);
if (_config.invokeSource === "indexes") {
return { sql: escapeName(columnName), params: [] };
}
const schemaName = chunk.table[import_table.Table.Symbol.Schema];
return {
sql: chunk.table[import_table.IsAlias] || schemaName === void 0 ? escapeName(chunk.table[import_table.Table.Symbol.Name]) + "." + escapeName(columnName) : escapeName(schemaName) + "." + escapeName(chunk.table[import_table.Table.Symbol.Name]) + "." + escapeName(columnName),
params: []
};
}
if ((0, import_entity.is)(chunk, View)) {
const schemaName = chunk[import_view_common.ViewBaseConfig].schema;
const viewName = chunk[import_view_common.ViewBaseConfig].name;
return {
sql: schemaName === void 0 ? escapeName(viewName) : escapeName(schemaName) + "." + escapeName(viewName),
params: []
};
}
if ((0, import_entity.is)(chunk, Param)) {
if ((0, import_entity.is)(chunk.value, Placeholder)) {
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
}
const mappedValue = chunk.value === null ? null : chunk.encoder.mapToDriverValue(chunk.value);
if ((0, import_entity.is)(mappedValue, SQL)) {
return this.buildQueryFromSourceParams([mappedValue], config);
}
if (inlineParams) {
return { sql: this.mapInlineParam(mappedValue, config), params: [] };
}
let typings = ["none"];
if (prepareTyping) {
typings = [prepareTyping(chunk.encoder)];
}
return { sql: escapeParam(paramStartIndex.value++, mappedValue), params: [mappedValue], typings };
}
if ((0, import_entity.is)(chunk, Placeholder)) {
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
}
if ((0, import_entity.is)(chunk, SQL.Aliased) && chunk.fieldAlias !== void 0) {
return { sql: escapeName(chunk.fieldAlias), params: [] };
}
if ((0, import_entity.is)(chunk, import_subquery.Subquery)) {
if (chunk._.isWith) {
return { sql: escapeName(chunk._.alias), params: [] };
}
return this.buildQueryFromSourceParams([
new StringChunk("("),
chunk._.sql,
new StringChunk(") "),
new Name(chunk._.alias)
], config);
}
if ((0, import_enum.isPgEnum)(chunk)) {
if (chunk.schema) {
return { sql: escapeName(chunk.schema) + "." + escapeName(chunk.enumName), params: [] };
}
return { sql: escapeName(chunk.enumName), params: [] };
}
if (isSQLWrapper(chunk)) {
if (chunk.shouldOmitSQLParens?.()) {
return this.buildQueryFromSourceParams([chunk.getSQL()], config);
}
return this.buildQueryFromSourceParams([
new StringChunk("("),
chunk.getSQL(),
new StringChunk(")")
], config);
}
if (inlineParams) {
return { sql: this.mapInlineParam(chunk, config), params: [] };
}
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
}));
}
mapInlineParam(chunk, { escapeString }) {
if (chunk === null) {
return "null";
}
if (typeof chunk === "number" || typeof chunk === "boolean") {
return chunk.toString();
}
if (typeof chunk === "string") {
return escapeString(chunk);
}
if (typeof chunk === "object") {
const mappedValueAsString = chunk.toString();
if (mappedValueAsString === "[object Object]") {
return escapeString(JSON.stringify(chunk));
}
return escapeString(mappedValueAsString);
}
throw new Error("Unexpected param value: " + chunk);
}
getSQL() {
return this;
}
as(alias) {
if (alias === void 0) {
return this;
}
return new SQL.Aliased(this, alias);
}
mapWith(decoder) {
this.decoder = typeof decoder === "function" ? { mapFromDriverValue: decoder } : decoder;
return this;
}
inlineParams() {
this.shouldInlineParams = true;
return this;
}
/**
* This method is used to conditionally include a part of the query.
*
* @param condition - Condition to check
* @returns itself if the condition is `true`, otherwise `undefined`
*/
if(condition) {
return condition ? this : void 0;
}
}
class Name {
constructor(value) {
this.value = value;
}
static [import_entity.entityKind] = "Name";
brand;
getSQL() {
return new SQL([this]);
}
}
function name(value) {
return new Name(value);
}
function isDriverValueEncoder(value) {
return typeof value === "object" && value !== null && "mapToDriverValue" in value && typeof value.mapToDriverValue === "function";
}
const noopDecoder = {
mapFromDriverValue: (value) => value
};
const noopEncoder = {
mapToDriverValue: (value) => value
};
const noopMapper = {
...noopDecoder,
...noopEncoder
};
class Param {
/**
* @param value - Parameter value
* @param encoder - Encoder to convert the value to a driver parameter
*/
constructor(value, encoder = noopEncoder) {
this.value = value;
this.encoder = encoder;
}
static [import_entity.entityKind] = "Param";
brand;
getSQL() {
return new SQL([this]);
}
}
function param(value, encoder) {
return new Param(value, encoder);
}
function sql(strings, ...params) {
const queryChunks = [];
if (params.length > 0 || strings.length > 0 && strings[0] !== "") {
queryChunks.push(new StringChunk(strings[0]));
}
for (const [paramIndex, param2] of params.entries()) {
queryChunks.push(param2, new StringChunk(strings[paramIndex + 1]));
}
return new SQL(queryChunks);
}
((sql2) => {
function empty() {
return new SQL([]);
}
sql2.empty = empty;
function fromList(list) {
return new SQL(list);
}
sql2.fromList = fromList;
function raw(str) {
return new SQL([new StringChunk(str)]);
}
sql2.raw = raw;
function join(chunks, separator) {
const result = [];
for (const [i, chunk] of chunks.entries()) {
if (i > 0 && separator !== void 0) {
result.push(separator);
}
result.push(chunk);
}
return new SQL(result);
}
sql2.join = join;
function identifier(value) {
return new Name(value);
}
sql2.identifier = identifier;
function placeholder2(name2) {
return new Placeholder(name2);
}
sql2.placeholder = placeholder2;
function param2(value, encoder) {
return new Param(value, encoder);
}
sql2.param = param2;
})(sql || (sql = {}));
((SQL2) => {
class Aliased {
constructor(sql2, fieldAlias) {
this.sql = sql2;
this.fieldAlias = fieldAlias;
}
static [import_entity.entityKind] = "SQL.Aliased";
/** @internal */
isSelectionField = false;
getSQL() {
return this.sql;
}
/** @internal */
clone() {
return new Aliased(this.sql, this.fieldAlias);
}
}
SQL2.Aliased = Aliased;
})(SQL || (SQL = {}));
class Placeholder {
constructor(name2) {
this.name = name2;
}
static [import_entity.entityKind] = "Placeholder";
getSQL() {
return new SQL([this]);
}
}
function placeholder(name2) {
return new Placeholder(name2);
}
function fillPlaceholders(params, values) {
return params.map((p) => {
if ((0, import_entity.is)(p, Placeholder)) {
if (!(p.name in values)) {
throw new Error(`No value for placeholder "${p.name}" was provided`);
}
return values[p.name];
}
if ((0, import_entity.is)(p, Param) && (0, import_entity.is)(p.value, Placeholder)) {
if (!(p.value.name in values)) {
throw new Error(`No value for placeholder "${p.value.name}" was provided`);
}
return p.encoder.mapToDriverValue(values[p.value.name]);
}
return p;
});
}
const IsDrizzleView = Symbol.for("drizzle:IsDrizzleView");
class View {
static [import_entity.entityKind] = "View";
/** @internal */
[import_view_common.ViewBaseConfig];
/** @internal */
[IsDrizzleView] = true;
constructor({ name: name2, schema, selectedFields, query }) {
this[import_view_common.ViewBaseConfig] = {
name: name2,
originalName: name2,
schema,
selectedFields,
query,
isExisting: !query,
isAlias: false
};
}
getSQL() {
return new SQL([this]);
}
}
function isView(view) {
return typeof view === "object" && view !== null && IsDrizzleView in view;
}
import_column.Column.prototype.getSQL = function() {
return new SQL([this]);
};
import_table.Table.prototype.getSQL = function() {
return new SQL([this]);
};
import_subquery.Subquery.prototype.getSQL = function() {
return new SQL([this]);
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
FakePrimitiveParam,
Name,
Param,
Placeholder,
SQL,
StringChunk,
View,
fillPlaceholders,
isDriverValueEncoder,
isSQLWrapper,
isView,
name,
noopDecoder,
noopEncoder,
noopMapper,
param,
placeholder,
sql
});
//# sourceMappingURL=sql.cjs.map

1
node_modules/drizzle-orm/sql/sql.cjs.map generated vendored Normal file

File diff suppressed because one or more lines are too long

229
node_modules/drizzle-orm/sql/sql.d.cts generated vendored Normal file
View File

@ -0,0 +1,229 @@
import type { CasingCache } from "../casing.cjs";
import { entityKind } from "../entity.cjs";
import type { SelectResult } from "../query-builders/select.types.cjs";
import { Subquery } from "../subquery.cjs";
import type { Assume, Equal } from "../utils.cjs";
import type { AnyColumn } from "../column.cjs";
import { Column } from "../column.cjs";
import { Table } from "../table.cjs";
/**
* This class is used to indicate a primitive param value that is used in `sql` tag.
* It is only used on type level and is never instantiated at runtime.
* If you see a value of this type in the code, its runtime value is actually the primitive param value.
*/
export declare class FakePrimitiveParam {
static readonly [entityKind]: string;
}
export type Chunk = string | Table | View | AnyColumn | Name | Param | Placeholder | SQL;
export interface BuildQueryConfig {
casing: CasingCache;
escapeName(name: string): string;
escapeParam(num: number, value: unknown): string;
escapeString(str: string): string;
prepareTyping?: (encoder: DriverValueEncoder<unknown, unknown>) => QueryTypingsValue;
paramStartIndex?: {
value: number;
};
inlineParams?: boolean;
invokeSource?: 'indexes' | undefined;
}
export type QueryTypingsValue = 'json' | 'decimal' | 'time' | 'timestamp' | 'uuid' | 'date' | 'none';
export interface Query {
sql: string;
params: unknown[];
}
export interface QueryWithTypings extends Query {
typings?: QueryTypingsValue[];
}
/**
* Any value that implements the `getSQL` method. The implementations include:
* - `Table`
* - `Column`
* - `View`
* - `Subquery`
* - `SQL`
* - `SQL.Aliased`
* - `Placeholder`
* - `Param`
*/
export interface SQLWrapper {
getSQL(): SQL;
shouldOmitSQLParens?(): boolean;
}
export declare function isSQLWrapper(value: unknown): value is SQLWrapper;
export declare class StringChunk implements SQLWrapper {
static readonly [entityKind]: string;
readonly value: string[];
constructor(value: string | string[]);
getSQL(): SQL<unknown>;
}
export declare class SQL<T = unknown> implements SQLWrapper {
readonly queryChunks: SQLChunk[];
static readonly [entityKind]: string;
_: {
brand: 'SQL';
type: T;
};
private shouldInlineParams;
constructor(queryChunks: SQLChunk[]);
append(query: SQL): this;
toQuery(config: BuildQueryConfig): QueryWithTypings;
buildQueryFromSourceParams(chunks: SQLChunk[], _config: BuildQueryConfig): Query;
private mapInlineParam;
getSQL(): SQL;
as(alias: string): SQL.Aliased<T>;
/**
* @deprecated
* Use ``sql<DataType>`query`.as(alias)`` instead.
*/
as<TData>(): SQL<TData>;
/**
* @deprecated
* Use ``sql<DataType>`query`.as(alias)`` instead.
*/
as<TData>(alias: string): SQL.Aliased<TData>;
mapWith<TDecoder extends DriverValueDecoder<any, any> | DriverValueDecoder<any, any>['mapFromDriverValue']>(decoder: TDecoder): SQL<GetDecoderResult<TDecoder>>;
inlineParams(): this;
/**
* This method is used to conditionally include a part of the query.
*
* @param condition - Condition to check
* @returns itself if the condition is `true`, otherwise `undefined`
*/
if(condition: any | undefined): this | undefined;
}
export type GetDecoderResult<T> = T extends Column ? T['_']['data'] : T extends DriverValueDecoder<infer TData, any> | DriverValueDecoder<infer TData, any>['mapFromDriverValue'] ? TData : never;
/**
* Any DB name (table, column, index etc.)
*/
export declare class Name implements SQLWrapper {
readonly value: string;
static readonly [entityKind]: string;
protected brand: 'Name';
constructor(value: string);
getSQL(): SQL<unknown>;
}
/**
* Any DB name (table, column, index etc.)
* @deprecated Use `sql.identifier` instead.
*/
export declare function name(value: string): Name;
export interface DriverValueDecoder<TData, TDriverParam> {
mapFromDriverValue(value: TDriverParam): TData;
}
export interface DriverValueEncoder<TData, TDriverParam> {
mapToDriverValue(value: TData): TDriverParam | SQL;
}
export declare function isDriverValueEncoder(value: unknown): value is DriverValueEncoder<any, any>;
export declare const noopDecoder: DriverValueDecoder<any, any>;
export declare const noopEncoder: DriverValueEncoder<any, any>;
export interface DriverValueMapper<TData, TDriverParam> extends DriverValueDecoder<TData, TDriverParam>, DriverValueEncoder<TData, TDriverParam> {
}
export declare const noopMapper: DriverValueMapper<any, any>;
/** Parameter value that is optionally bound to an encoder (for example, a column). */
export declare class Param<TDataType = unknown, TDriverParamType = TDataType> implements SQLWrapper {
readonly value: TDataType;
readonly encoder: DriverValueEncoder<TDataType, TDriverParamType>;
static readonly [entityKind]: string;
protected brand: 'BoundParamValue';
/**
* @param value - Parameter value
* @param encoder - Encoder to convert the value to a driver parameter
*/
constructor(value: TDataType, encoder?: DriverValueEncoder<TDataType, TDriverParamType>);
getSQL(): SQL<unknown>;
}
/** @deprecated Use `sql.param` instead. */
export declare function param<TData, TDriver>(value: TData, encoder?: DriverValueEncoder<TData, TDriver>): Param<TData, TDriver>;
/**
* Anything that can be passed to the `` sql`...` `` tagged function.
*/
export type SQLChunk = StringChunk | SQLChunk[] | SQLWrapper | SQL | Table | View | Subquery | AnyColumn | Param | Name | undefined | FakePrimitiveParam | Placeholder;
export declare function sql<T>(strings: TemplateStringsArray, ...params: any[]): SQL<T>;
export declare namespace sql {
function empty(): SQL;
/** @deprecated - use `sql.join()` */
function fromList(list: SQLChunk[]): SQL;
/**
* Convenience function to create an SQL query from a raw string.
* @param str The raw SQL query string.
*/
function raw(str: string): SQL;
/**
* Join a list of SQL chunks with a separator.
* @example
* ```ts
* const query = sql.join([sql`a`, sql`b`, sql`c`]);
* // sql`abc`
* ```
* @example
* ```ts
* const query = sql.join([sql`a`, sql`b`, sql`c`], sql`, `);
* // sql`a, b, c`
* ```
*/
function join(chunks: SQLChunk[], separator?: SQLChunk): SQL;
/**
* Create a SQL chunk that represents a DB identifier (table, column, index etc.).
* When used in a query, the identifier will be escaped based on the DB engine.
* For example, in PostgreSQL, identifiers are escaped with double quotes.
*
* **WARNING: This function does not offer any protection against SQL injections, so you must validate any user input beforehand.**
*
* @example ```ts
* const query = sql`SELECT * FROM ${sql.identifier('my-table')}`;
* // 'SELECT * FROM "my-table"'
* ```
*/
function identifier(value: string): Name;
function placeholder<TName extends string>(name: TName): Placeholder<TName>;
function param<TData, TDriver>(value: TData, encoder?: DriverValueEncoder<TData, TDriver>): Param<TData, TDriver>;
}
export declare namespace SQL {
class Aliased<T = unknown> implements SQLWrapper {
readonly sql: SQL;
readonly fieldAlias: string;
static readonly [entityKind]: string;
_: {
brand: 'SQL.Aliased';
type: T;
};
constructor(sql: SQL, fieldAlias: string);
getSQL(): SQL;
}
}
export declare class Placeholder<TName extends string = string, TValue = any> implements SQLWrapper {
readonly name: TName;
static readonly [entityKind]: string;
protected: TValue;
constructor(name: TName);
getSQL(): SQL;
}
/** @deprecated Use `sql.placeholder` instead. */
export declare function placeholder<TName extends string>(name: TName): Placeholder<TName>;
export declare function fillPlaceholders(params: unknown[], values: Record<string, unknown>): unknown[];
export type ColumnsSelection = Record<string, unknown>;
export declare abstract class View<TName extends string = string, TExisting extends boolean = boolean, TSelection extends ColumnsSelection = ColumnsSelection> implements SQLWrapper {
static readonly [entityKind]: string;
_: {
brand: 'View';
viewBrand: string;
name: TName;
existing: TExisting;
selectedFields: TSelection;
};
readonly $inferSelect: InferSelectViewModel<View<Assume<TName, string>, TExisting, TSelection>>;
constructor({ name, schema, selectedFields, query }: {
name: TName;
schema: string | undefined;
selectedFields: ColumnsSelection;
query: SQL | undefined;
});
getSQL(): SQL<unknown>;
}
export declare function isView(view: unknown): view is View;
export type InferSelectViewModel<TView extends View> = Equal<TView['_']['selectedFields'], {
[x: string]: unknown;
}> extends true ? {
[x: string]: unknown;
} : SelectResult<TView['_']['selectedFields'], 'single', Record<TView['_']['name'], 'not-null'>>;

229
node_modules/drizzle-orm/sql/sql.d.ts generated vendored Normal file
View File

@ -0,0 +1,229 @@
import type { CasingCache } from "../casing.js";
import { entityKind } from "../entity.js";
import type { SelectResult } from "../query-builders/select.types.js";
import { Subquery } from "../subquery.js";
import type { Assume, Equal } from "../utils.js";
import type { AnyColumn } from "../column.js";
import { Column } from "../column.js";
import { Table } from "../table.js";
/**
* This class is used to indicate a primitive param value that is used in `sql` tag.
* It is only used on type level and is never instantiated at runtime.
* If you see a value of this type in the code, its runtime value is actually the primitive param value.
*/
export declare class FakePrimitiveParam {
static readonly [entityKind]: string;
}
export type Chunk = string | Table | View | AnyColumn | Name | Param | Placeholder | SQL;
export interface BuildQueryConfig {
casing: CasingCache;
escapeName(name: string): string;
escapeParam(num: number, value: unknown): string;
escapeString(str: string): string;
prepareTyping?: (encoder: DriverValueEncoder<unknown, unknown>) => QueryTypingsValue;
paramStartIndex?: {
value: number;
};
inlineParams?: boolean;
invokeSource?: 'indexes' | undefined;
}
export type QueryTypingsValue = 'json' | 'decimal' | 'time' | 'timestamp' | 'uuid' | 'date' | 'none';
export interface Query {
sql: string;
params: unknown[];
}
export interface QueryWithTypings extends Query {
typings?: QueryTypingsValue[];
}
/**
* Any value that implements the `getSQL` method. The implementations include:
* - `Table`
* - `Column`
* - `View`
* - `Subquery`
* - `SQL`
* - `SQL.Aliased`
* - `Placeholder`
* - `Param`
*/
export interface SQLWrapper {
getSQL(): SQL;
shouldOmitSQLParens?(): boolean;
}
export declare function isSQLWrapper(value: unknown): value is SQLWrapper;
export declare class StringChunk implements SQLWrapper {
static readonly [entityKind]: string;
readonly value: string[];
constructor(value: string | string[]);
getSQL(): SQL<unknown>;
}
export declare class SQL<T = unknown> implements SQLWrapper {
readonly queryChunks: SQLChunk[];
static readonly [entityKind]: string;
_: {
brand: 'SQL';
type: T;
};
private shouldInlineParams;
constructor(queryChunks: SQLChunk[]);
append(query: SQL): this;
toQuery(config: BuildQueryConfig): QueryWithTypings;
buildQueryFromSourceParams(chunks: SQLChunk[], _config: BuildQueryConfig): Query;
private mapInlineParam;
getSQL(): SQL;
as(alias: string): SQL.Aliased<T>;
/**
* @deprecated
* Use ``sql<DataType>`query`.as(alias)`` instead.
*/
as<TData>(): SQL<TData>;
/**
* @deprecated
* Use ``sql<DataType>`query`.as(alias)`` instead.
*/
as<TData>(alias: string): SQL.Aliased<TData>;
mapWith<TDecoder extends DriverValueDecoder<any, any> | DriverValueDecoder<any, any>['mapFromDriverValue']>(decoder: TDecoder): SQL<GetDecoderResult<TDecoder>>;
inlineParams(): this;
/**
* This method is used to conditionally include a part of the query.
*
* @param condition - Condition to check
* @returns itself if the condition is `true`, otherwise `undefined`
*/
if(condition: any | undefined): this | undefined;
}
export type GetDecoderResult<T> = T extends Column ? T['_']['data'] : T extends DriverValueDecoder<infer TData, any> | DriverValueDecoder<infer TData, any>['mapFromDriverValue'] ? TData : never;
/**
* Any DB name (table, column, index etc.)
*/
export declare class Name implements SQLWrapper {
readonly value: string;
static readonly [entityKind]: string;
protected brand: 'Name';
constructor(value: string);
getSQL(): SQL<unknown>;
}
/**
* Any DB name (table, column, index etc.)
* @deprecated Use `sql.identifier` instead.
*/
export declare function name(value: string): Name;
export interface DriverValueDecoder<TData, TDriverParam> {
mapFromDriverValue(value: TDriverParam): TData;
}
export interface DriverValueEncoder<TData, TDriverParam> {
mapToDriverValue(value: TData): TDriverParam | SQL;
}
export declare function isDriverValueEncoder(value: unknown): value is DriverValueEncoder<any, any>;
export declare const noopDecoder: DriverValueDecoder<any, any>;
export declare const noopEncoder: DriverValueEncoder<any, any>;
export interface DriverValueMapper<TData, TDriverParam> extends DriverValueDecoder<TData, TDriverParam>, DriverValueEncoder<TData, TDriverParam> {
}
export declare const noopMapper: DriverValueMapper<any, any>;
/** Parameter value that is optionally bound to an encoder (for example, a column). */
export declare class Param<TDataType = unknown, TDriverParamType = TDataType> implements SQLWrapper {
readonly value: TDataType;
readonly encoder: DriverValueEncoder<TDataType, TDriverParamType>;
static readonly [entityKind]: string;
protected brand: 'BoundParamValue';
/**
* @param value - Parameter value
* @param encoder - Encoder to convert the value to a driver parameter
*/
constructor(value: TDataType, encoder?: DriverValueEncoder<TDataType, TDriverParamType>);
getSQL(): SQL<unknown>;
}
/** @deprecated Use `sql.param` instead. */
export declare function param<TData, TDriver>(value: TData, encoder?: DriverValueEncoder<TData, TDriver>): Param<TData, TDriver>;
/**
* Anything that can be passed to the `` sql`...` `` tagged function.
*/
export type SQLChunk = StringChunk | SQLChunk[] | SQLWrapper | SQL | Table | View | Subquery | AnyColumn | Param | Name | undefined | FakePrimitiveParam | Placeholder;
export declare function sql<T>(strings: TemplateStringsArray, ...params: any[]): SQL<T>;
export declare namespace sql {
function empty(): SQL;
/** @deprecated - use `sql.join()` */
function fromList(list: SQLChunk[]): SQL;
/**
* Convenience function to create an SQL query from a raw string.
* @param str The raw SQL query string.
*/
function raw(str: string): SQL;
/**
* Join a list of SQL chunks with a separator.
* @example
* ```ts
* const query = sql.join([sql`a`, sql`b`, sql`c`]);
* // sql`abc`
* ```
* @example
* ```ts
* const query = sql.join([sql`a`, sql`b`, sql`c`], sql`, `);
* // sql`a, b, c`
* ```
*/
function join(chunks: SQLChunk[], separator?: SQLChunk): SQL;
/**
* Create a SQL chunk that represents a DB identifier (table, column, index etc.).
* When used in a query, the identifier will be escaped based on the DB engine.
* For example, in PostgreSQL, identifiers are escaped with double quotes.
*
* **WARNING: This function does not offer any protection against SQL injections, so you must validate any user input beforehand.**
*
* @example ```ts
* const query = sql`SELECT * FROM ${sql.identifier('my-table')}`;
* // 'SELECT * FROM "my-table"'
* ```
*/
function identifier(value: string): Name;
function placeholder<TName extends string>(name: TName): Placeholder<TName>;
function param<TData, TDriver>(value: TData, encoder?: DriverValueEncoder<TData, TDriver>): Param<TData, TDriver>;
}
export declare namespace SQL {
class Aliased<T = unknown> implements SQLWrapper {
readonly sql: SQL;
readonly fieldAlias: string;
static readonly [entityKind]: string;
_: {
brand: 'SQL.Aliased';
type: T;
};
constructor(sql: SQL, fieldAlias: string);
getSQL(): SQL;
}
}
export declare class Placeholder<TName extends string = string, TValue = any> implements SQLWrapper {
readonly name: TName;
static readonly [entityKind]: string;
protected: TValue;
constructor(name: TName);
getSQL(): SQL;
}
/** @deprecated Use `sql.placeholder` instead. */
export declare function placeholder<TName extends string>(name: TName): Placeholder<TName>;
export declare function fillPlaceholders(params: unknown[], values: Record<string, unknown>): unknown[];
export type ColumnsSelection = Record<string, unknown>;
export declare abstract class View<TName extends string = string, TExisting extends boolean = boolean, TSelection extends ColumnsSelection = ColumnsSelection> implements SQLWrapper {
static readonly [entityKind]: string;
_: {
brand: 'View';
viewBrand: string;
name: TName;
existing: TExisting;
selectedFields: TSelection;
};
readonly $inferSelect: InferSelectViewModel<View<Assume<TName, string>, TExisting, TSelection>>;
constructor({ name, schema, selectedFields, query }: {
name: TName;
schema: string | undefined;
selectedFields: ColumnsSelection;
query: SQL | undefined;
});
getSQL(): SQL<unknown>;
}
export declare function isView(view: unknown): view is View;
export type InferSelectViewModel<TView extends View> = Equal<TView['_']['selectedFields'], {
[x: string]: unknown;
}> extends true ? {
[x: string]: unknown;
} : SelectResult<TView['_']['selectedFields'], 'single', Record<TView['_']['name'], 'not-null'>>;

422
node_modules/drizzle-orm/sql/sql.js generated vendored Normal file
View File

@ -0,0 +1,422 @@
import { entityKind, is } from "../entity.js";
import { isPgEnum } from "../pg-core/columns/enum.js";
import { Subquery } from "../subquery.js";
import { tracer } from "../tracing.js";
import { ViewBaseConfig } from "../view-common.js";
import { Column } from "../column.js";
import { IsAlias, Table } from "../table.js";
class FakePrimitiveParam {
static [entityKind] = "FakePrimitiveParam";
}
function isSQLWrapper(value) {
return value !== null && value !== void 0 && typeof value.getSQL === "function";
}
function mergeQueries(queries) {
const result = { sql: "", params: [] };
for (const query of queries) {
result.sql += query.sql;
result.params.push(...query.params);
if (query.typings?.length) {
if (!result.typings) {
result.typings = [];
}
result.typings.push(...query.typings);
}
}
return result;
}
class StringChunk {
static [entityKind] = "StringChunk";
value;
constructor(value) {
this.value = Array.isArray(value) ? value : [value];
}
getSQL() {
return new SQL([this]);
}
}
class SQL {
constructor(queryChunks) {
this.queryChunks = queryChunks;
}
static [entityKind] = "SQL";
/** @internal */
decoder = noopDecoder;
shouldInlineParams = false;
append(query) {
this.queryChunks.push(...query.queryChunks);
return this;
}
toQuery(config) {
return tracer.startActiveSpan("drizzle.buildSQL", (span) => {
const query = this.buildQueryFromSourceParams(this.queryChunks, config);
span?.setAttributes({
"drizzle.query.text": query.sql,
"drizzle.query.params": JSON.stringify(query.params)
});
return query;
});
}
buildQueryFromSourceParams(chunks, _config) {
const config = Object.assign({}, _config, {
inlineParams: _config.inlineParams || this.shouldInlineParams,
paramStartIndex: _config.paramStartIndex || { value: 0 }
});
const {
casing,
escapeName,
escapeParam,
prepareTyping,
inlineParams,
paramStartIndex
} = config;
return mergeQueries(chunks.map((chunk) => {
if (is(chunk, StringChunk)) {
return { sql: chunk.value.join(""), params: [] };
}
if (is(chunk, Name)) {
return { sql: escapeName(chunk.value), params: [] };
}
if (chunk === void 0) {
return { sql: "", params: [] };
}
if (Array.isArray(chunk)) {
const result = [new StringChunk("(")];
for (const [i, p] of chunk.entries()) {
result.push(p);
if (i < chunk.length - 1) {
result.push(new StringChunk(", "));
}
}
result.push(new StringChunk(")"));
return this.buildQueryFromSourceParams(result, config);
}
if (is(chunk, SQL)) {
return this.buildQueryFromSourceParams(chunk.queryChunks, {
...config,
inlineParams: inlineParams || chunk.shouldInlineParams
});
}
if (is(chunk, Table)) {
const schemaName = chunk[Table.Symbol.Schema];
const tableName = chunk[Table.Symbol.Name];
return {
sql: schemaName === void 0 ? escapeName(tableName) : escapeName(schemaName) + "." + escapeName(tableName),
params: []
};
}
if (is(chunk, Column)) {
const columnName = casing.getColumnCasing(chunk);
if (_config.invokeSource === "indexes") {
return { sql: escapeName(columnName), params: [] };
}
const schemaName = chunk.table[Table.Symbol.Schema];
return {
sql: chunk.table[IsAlias] || schemaName === void 0 ? escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName) : escapeName(schemaName) + "." + escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName),
params: []
};
}
if (is(chunk, View)) {
const schemaName = chunk[ViewBaseConfig].schema;
const viewName = chunk[ViewBaseConfig].name;
return {
sql: schemaName === void 0 ? escapeName(viewName) : escapeName(schemaName) + "." + escapeName(viewName),
params: []
};
}
if (is(chunk, Param)) {
if (is(chunk.value, Placeholder)) {
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
}
const mappedValue = chunk.value === null ? null : chunk.encoder.mapToDriverValue(chunk.value);
if (is(mappedValue, SQL)) {
return this.buildQueryFromSourceParams([mappedValue], config);
}
if (inlineParams) {
return { sql: this.mapInlineParam(mappedValue, config), params: [] };
}
let typings = ["none"];
if (prepareTyping) {
typings = [prepareTyping(chunk.encoder)];
}
return { sql: escapeParam(paramStartIndex.value++, mappedValue), params: [mappedValue], typings };
}
if (is(chunk, Placeholder)) {
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
}
if (is(chunk, SQL.Aliased) && chunk.fieldAlias !== void 0) {
return { sql: escapeName(chunk.fieldAlias), params: [] };
}
if (is(chunk, Subquery)) {
if (chunk._.isWith) {
return { sql: escapeName(chunk._.alias), params: [] };
}
return this.buildQueryFromSourceParams([
new StringChunk("("),
chunk._.sql,
new StringChunk(") "),
new Name(chunk._.alias)
], config);
}
if (isPgEnum(chunk)) {
if (chunk.schema) {
return { sql: escapeName(chunk.schema) + "." + escapeName(chunk.enumName), params: [] };
}
return { sql: escapeName(chunk.enumName), params: [] };
}
if (isSQLWrapper(chunk)) {
if (chunk.shouldOmitSQLParens?.()) {
return this.buildQueryFromSourceParams([chunk.getSQL()], config);
}
return this.buildQueryFromSourceParams([
new StringChunk("("),
chunk.getSQL(),
new StringChunk(")")
], config);
}
if (inlineParams) {
return { sql: this.mapInlineParam(chunk, config), params: [] };
}
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
}));
}
mapInlineParam(chunk, { escapeString }) {
if (chunk === null) {
return "null";
}
if (typeof chunk === "number" || typeof chunk === "boolean") {
return chunk.toString();
}
if (typeof chunk === "string") {
return escapeString(chunk);
}
if (typeof chunk === "object") {
const mappedValueAsString = chunk.toString();
if (mappedValueAsString === "[object Object]") {
return escapeString(JSON.stringify(chunk));
}
return escapeString(mappedValueAsString);
}
throw new Error("Unexpected param value: " + chunk);
}
getSQL() {
return this;
}
as(alias) {
if (alias === void 0) {
return this;
}
return new SQL.Aliased(this, alias);
}
mapWith(decoder) {
this.decoder = typeof decoder === "function" ? { mapFromDriverValue: decoder } : decoder;
return this;
}
inlineParams() {
this.shouldInlineParams = true;
return this;
}
/**
* This method is used to conditionally include a part of the query.
*
* @param condition - Condition to check
* @returns itself if the condition is `true`, otherwise `undefined`
*/
if(condition) {
return condition ? this : void 0;
}
}
class Name {
constructor(value) {
this.value = value;
}
static [entityKind] = "Name";
brand;
getSQL() {
return new SQL([this]);
}
}
function name(value) {
return new Name(value);
}
function isDriverValueEncoder(value) {
return typeof value === "object" && value !== null && "mapToDriverValue" in value && typeof value.mapToDriverValue === "function";
}
const noopDecoder = {
mapFromDriverValue: (value) => value
};
const noopEncoder = {
mapToDriverValue: (value) => value
};
const noopMapper = {
...noopDecoder,
...noopEncoder
};
class Param {
/**
* @param value - Parameter value
* @param encoder - Encoder to convert the value to a driver parameter
*/
constructor(value, encoder = noopEncoder) {
this.value = value;
this.encoder = encoder;
}
static [entityKind] = "Param";
brand;
getSQL() {
return new SQL([this]);
}
}
function param(value, encoder) {
return new Param(value, encoder);
}
function sql(strings, ...params) {
const queryChunks = [];
if (params.length > 0 || strings.length > 0 && strings[0] !== "") {
queryChunks.push(new StringChunk(strings[0]));
}
for (const [paramIndex, param2] of params.entries()) {
queryChunks.push(param2, new StringChunk(strings[paramIndex + 1]));
}
return new SQL(queryChunks);
}
((sql2) => {
function empty() {
return new SQL([]);
}
sql2.empty = empty;
function fromList(list) {
return new SQL(list);
}
sql2.fromList = fromList;
function raw(str) {
return new SQL([new StringChunk(str)]);
}
sql2.raw = raw;
function join(chunks, separator) {
const result = [];
for (const [i, chunk] of chunks.entries()) {
if (i > 0 && separator !== void 0) {
result.push(separator);
}
result.push(chunk);
}
return new SQL(result);
}
sql2.join = join;
function identifier(value) {
return new Name(value);
}
sql2.identifier = identifier;
function placeholder2(name2) {
return new Placeholder(name2);
}
sql2.placeholder = placeholder2;
function param2(value, encoder) {
return new Param(value, encoder);
}
sql2.param = param2;
})(sql || (sql = {}));
((SQL2) => {
class Aliased {
constructor(sql2, fieldAlias) {
this.sql = sql2;
this.fieldAlias = fieldAlias;
}
static [entityKind] = "SQL.Aliased";
/** @internal */
isSelectionField = false;
getSQL() {
return this.sql;
}
/** @internal */
clone() {
return new Aliased(this.sql, this.fieldAlias);
}
}
SQL2.Aliased = Aliased;
})(SQL || (SQL = {}));
class Placeholder {
constructor(name2) {
this.name = name2;
}
static [entityKind] = "Placeholder";
getSQL() {
return new SQL([this]);
}
}
function placeholder(name2) {
return new Placeholder(name2);
}
function fillPlaceholders(params, values) {
return params.map((p) => {
if (is(p, Placeholder)) {
if (!(p.name in values)) {
throw new Error(`No value for placeholder "${p.name}" was provided`);
}
return values[p.name];
}
if (is(p, Param) && is(p.value, Placeholder)) {
if (!(p.value.name in values)) {
throw new Error(`No value for placeholder "${p.value.name}" was provided`);
}
return p.encoder.mapToDriverValue(values[p.value.name]);
}
return p;
});
}
const IsDrizzleView = Symbol.for("drizzle:IsDrizzleView");
class View {
static [entityKind] = "View";
/** @internal */
[ViewBaseConfig];
/** @internal */
[IsDrizzleView] = true;
constructor({ name: name2, schema, selectedFields, query }) {
this[ViewBaseConfig] = {
name: name2,
originalName: name2,
schema,
selectedFields,
query,
isExisting: !query,
isAlias: false
};
}
getSQL() {
return new SQL([this]);
}
}
function isView(view) {
return typeof view === "object" && view !== null && IsDrizzleView in view;
}
Column.prototype.getSQL = function() {
return new SQL([this]);
};
Table.prototype.getSQL = function() {
return new SQL([this]);
};
Subquery.prototype.getSQL = function() {
return new SQL([this]);
};
export {
FakePrimitiveParam,
Name,
Param,
Placeholder,
SQL,
StringChunk,
View,
fillPlaceholders,
isDriverValueEncoder,
isSQLWrapper,
isView,
name,
noopDecoder,
noopEncoder,
noopMapper,
param,
placeholder,
sql
};
//# sourceMappingURL=sql.js.map

1
node_modules/drizzle-orm/sql/sql.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long