Initial commit - Event Planner application
This commit is contained in:
218
node_modules/kysely/dist/cjs/raw-builder/raw-builder.d.ts
generated
vendored
Normal file
218
node_modules/kysely/dist/cjs/raw-builder/raw-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,218 @@
|
||||
import type { QueryResult } from '../driver/database-connection.js';
|
||||
import type { RawNode } from '../operation-node/raw-node.js';
|
||||
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
|
||||
import type { KyselyPlugin } from '../plugin/kysely-plugin.js';
|
||||
import type { QueryExecutorProvider } from '../query-executor/query-executor-provider.js';
|
||||
import type { QueryId } from '../util/query-id.js';
|
||||
import type { AliasableExpression, AliasedExpression, Expression } from '../expression/expression.js';
|
||||
/**
|
||||
* An instance of this class can be used to create raw SQL snippets or queries.
|
||||
*
|
||||
* You shouldn't need to create `RawBuilder` instances directly. Instead you should
|
||||
* use the {@link sql} template tag.
|
||||
*/
|
||||
export interface RawBuilder<O> extends AliasableExpression<O> {
|
||||
get isRawBuilder(): true;
|
||||
/**
|
||||
* Returns an aliased version of the SQL expression.
|
||||
*
|
||||
* In addition to slapping `as "the_alias"` to the end of the SQL,
|
||||
* this method also provides strict typing:
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* const result = await db
|
||||
* .selectFrom('person')
|
||||
* .select(
|
||||
* sql<string>`concat(first_name, ' ', last_name)`.as('full_name')
|
||||
* )
|
||||
* .executeTakeFirstOrThrow()
|
||||
*
|
||||
* // `full_name: string` field exists in the result type.
|
||||
* console.log(result.full_name)
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* select concat(first_name, ' ', last_name) as "full_name"
|
||||
* from "person"
|
||||
* ```
|
||||
*
|
||||
* You can also pass in a raw SQL snippet but in that case you must
|
||||
* provide the alias as the only type argument:
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* const values = sql<{ a: number, b: string }>`(values (1, 'foo'))`
|
||||
*
|
||||
* // The alias is `t(a, b)` which specifies the column names
|
||||
* // in addition to the table name. We must tell kysely that
|
||||
* // columns of the table can be referenced through `t`
|
||||
* // by providing an explicit type argument.
|
||||
* const aliasedValues = values.as<'t'>(sql`t(a, b)`)
|
||||
*
|
||||
* await db
|
||||
* .insertInto('person')
|
||||
* .columns(['first_name', 'last_name'])
|
||||
* .expression(
|
||||
* db.selectFrom(aliasedValues).select(['t.a', 't.b'])
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* insert into "person" ("first_name", "last_name")
|
||||
* from (values (1, 'foo')) as t(a, b)
|
||||
* select "t"."a", "t"."b"
|
||||
* ```
|
||||
*/
|
||||
as<A extends string>(alias: A): AliasedRawBuilder<O, A>;
|
||||
/**
|
||||
* Returns an aliased version of the expression.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* In addition to slapping `as "the_alias"` at the end of the expression,
|
||||
* this method also provides strict typing:
|
||||
*
|
||||
* ```ts
|
||||
* const result = await db
|
||||
* .selectFrom('person')
|
||||
* .select((eb) =>
|
||||
* // `eb.fn<string>` returns an AliasableExpression<string>
|
||||
* eb.fn<string>('concat', ['first_name', eb.val(' '), 'last_name']).as('full_name')
|
||||
* )
|
||||
* .executeTakeFirstOrThrow()
|
||||
*
|
||||
* // `full_name: string` field exists in the result type.
|
||||
* console.log(result.full_name)
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* select
|
||||
* concat("first_name", $1, "last_name") as "full_name"
|
||||
* from
|
||||
* "person"
|
||||
* ```
|
||||
*
|
||||
* You can also pass in a raw SQL snippet (or any expression) but in that case you must
|
||||
* provide the alias as the only type argument:
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* const values = sql<{ a: number, b: string }>`(values (1, 'foo'))`
|
||||
*
|
||||
* // The alias is `t(a, b)` which specifies the column names
|
||||
* // in addition to the table name. We must tell kysely that
|
||||
* // columns of the table can be referenced through `t`
|
||||
* // by providing an explicit type argument.
|
||||
* const aliasedValues = values.as<'t'>(sql`t(a, b)`)
|
||||
*
|
||||
* await db
|
||||
* .insertInto('person')
|
||||
* .columns(['first_name', 'last_name'])
|
||||
* .expression(
|
||||
* db.selectFrom(aliasedValues).select(['t.a', 't.b'])
|
||||
* )
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* insert into "person" ("first_name", "last_name")
|
||||
* from (values (1, 'foo')) as t(a, b)
|
||||
* select "t"."a", "t"."b"
|
||||
* ```
|
||||
*/
|
||||
as<A extends string>(alias: Expression<any>): AliasedRawBuilder<O, A>;
|
||||
/**
|
||||
* Change the output type of the raw expression.
|
||||
*
|
||||
* This method call doesn't change the SQL in any way. This methods simply
|
||||
* returns a copy of this `RawBuilder` with a new output type.
|
||||
*/
|
||||
$castTo<C>(): RawBuilder<C>;
|
||||
/**
|
||||
* Omit null from the expression's type.
|
||||
*
|
||||
* This function can be useful in cases where you know an expression can't be
|
||||
* null, but Kysely is unable to infer it.
|
||||
*
|
||||
* This method call doesn't change the SQL in any way. This methods simply
|
||||
* returns a copy of `this` with a new output type.
|
||||
*/
|
||||
$notNull(): RawBuilder<Exclude<O, null>>;
|
||||
/**
|
||||
* Adds a plugin for this SQL snippet.
|
||||
*/
|
||||
withPlugin(plugin: KyselyPlugin): RawBuilder<O>;
|
||||
/**
|
||||
* Compiles the builder to a `CompiledQuery`.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* const compiledQuery = sql`select * from ${sql.table('person')}`.compile(db)
|
||||
* console.log(compiledQuery.sql)
|
||||
* ```
|
||||
*/
|
||||
compile(executorProvider: QueryExecutorProvider): CompiledQuery<O>;
|
||||
/**
|
||||
* Executes the raw query.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* const result = await sql`select * from ${sql.table('person')}`.execute(db)
|
||||
* ```
|
||||
*/
|
||||
execute(executorProvider: QueryExecutorProvider): Promise<QueryResult<O>>;
|
||||
/**
|
||||
* Creates the OperationNode that describes how to compile this expression into SQL.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* If you are creating a custom expression, it's often easiest to use the {@link sql}
|
||||
* template tag to build the node:
|
||||
*
|
||||
* ```ts
|
||||
* import { type Expression, type OperationNode, sql } from 'kysely'
|
||||
*
|
||||
* class SomeExpression<T> implements Expression<T> {
|
||||
* get expressionType(): T | undefined {
|
||||
* return undefined
|
||||
* }
|
||||
*
|
||||
* toOperationNode(): OperationNode {
|
||||
* return sql`some sql here`.toOperationNode()
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
toOperationNode(): RawNode;
|
||||
}
|
||||
export interface RawBuilderProps {
|
||||
readonly queryId: QueryId;
|
||||
readonly rawNode: RawNode;
|
||||
readonly plugins?: ReadonlyArray<KyselyPlugin>;
|
||||
}
|
||||
export declare function createRawBuilder<O>(props: RawBuilderProps): RawBuilder<O>;
|
||||
/**
|
||||
* {@link RawBuilder} with an alias. The result of calling {@link RawBuilder.as}.
|
||||
*/
|
||||
export interface AliasedRawBuilder<O = unknown, A extends string = never> extends AliasedExpression<O, A> {
|
||||
get rawBuilder(): RawBuilder<O>;
|
||||
}
|
||||
86
node_modules/kysely/dist/cjs/raw-builder/raw-builder.js
generated
vendored
Normal file
86
node_modules/kysely/dist/cjs/raw-builder/raw-builder.js
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createRawBuilder = createRawBuilder;
|
||||
const alias_node_js_1 = require("../operation-node/alias-node.js");
|
||||
const object_utils_js_1 = require("../util/object-utils.js");
|
||||
const noop_query_executor_js_1 = require("../query-executor/noop-query-executor.js");
|
||||
const identifier_node_js_1 = require("../operation-node/identifier-node.js");
|
||||
const operation_node_source_js_1 = require("../operation-node/operation-node-source.js");
|
||||
class RawBuilderImpl {
|
||||
#props;
|
||||
constructor(props) {
|
||||
this.#props = (0, object_utils_js_1.freeze)(props);
|
||||
}
|
||||
get expressionType() {
|
||||
return undefined;
|
||||
}
|
||||
get isRawBuilder() {
|
||||
return true;
|
||||
}
|
||||
as(alias) {
|
||||
return new AliasedRawBuilderImpl(this, alias);
|
||||
}
|
||||
$castTo() {
|
||||
return new RawBuilderImpl({ ...this.#props });
|
||||
}
|
||||
$notNull() {
|
||||
return new RawBuilderImpl(this.#props);
|
||||
}
|
||||
withPlugin(plugin) {
|
||||
return new RawBuilderImpl({
|
||||
...this.#props,
|
||||
plugins: this.#props.plugins !== undefined
|
||||
? (0, object_utils_js_1.freeze)([...this.#props.plugins, plugin])
|
||||
: (0, object_utils_js_1.freeze)([plugin]),
|
||||
});
|
||||
}
|
||||
toOperationNode() {
|
||||
return this.#toOperationNode(this.#getExecutor());
|
||||
}
|
||||
compile(executorProvider) {
|
||||
return this.#compile(this.#getExecutor(executorProvider));
|
||||
}
|
||||
async execute(executorProvider) {
|
||||
const executor = this.#getExecutor(executorProvider);
|
||||
return executor.executeQuery(this.#compile(executor));
|
||||
}
|
||||
#getExecutor(executorProvider) {
|
||||
const executor = executorProvider !== undefined
|
||||
? executorProvider.getExecutor()
|
||||
: noop_query_executor_js_1.NOOP_QUERY_EXECUTOR;
|
||||
return this.#props.plugins !== undefined
|
||||
? executor.withPlugins(this.#props.plugins)
|
||||
: executor;
|
||||
}
|
||||
#toOperationNode(executor) {
|
||||
return executor.transformQuery(this.#props.rawNode, this.#props.queryId);
|
||||
}
|
||||
#compile(executor) {
|
||||
return executor.compileQuery(this.#toOperationNode(executor), this.#props.queryId);
|
||||
}
|
||||
}
|
||||
function createRawBuilder(props) {
|
||||
return new RawBuilderImpl(props);
|
||||
}
|
||||
class AliasedRawBuilderImpl {
|
||||
#rawBuilder;
|
||||
#alias;
|
||||
constructor(rawBuilder, alias) {
|
||||
this.#rawBuilder = rawBuilder;
|
||||
this.#alias = alias;
|
||||
}
|
||||
get expression() {
|
||||
return this.#rawBuilder;
|
||||
}
|
||||
get alias() {
|
||||
return this.#alias;
|
||||
}
|
||||
get rawBuilder() {
|
||||
return this.#rawBuilder;
|
||||
}
|
||||
toOperationNode() {
|
||||
return alias_node_js_1.AliasNode.create(this.#rawBuilder.toOperationNode(), (0, operation_node_source_js_1.isOperationNodeSource)(this.#alias)
|
||||
? this.#alias.toOperationNode()
|
||||
: identifier_node_js_1.IdentifierNode.create(this.#alias));
|
||||
}
|
||||
}
|
||||
366
node_modules/kysely/dist/cjs/raw-builder/sql.d.ts
generated
vendored
Normal file
366
node_modules/kysely/dist/cjs/raw-builder/sql.d.ts
generated
vendored
Normal file
@@ -0,0 +1,366 @@
|
||||
import { type RawBuilder } from './raw-builder.js';
|
||||
export interface Sql {
|
||||
/**
|
||||
* Template tag for creating raw SQL snippets and queries.
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
* import type { Person } from 'type-editor' // imaginary module
|
||||
*
|
||||
* const id = 123
|
||||
* const snippet = sql<Person[]>`select * from person where id = ${id}`
|
||||
* ```
|
||||
*
|
||||
* Substitutions (the things inside `${}`) are automatically passed to the database
|
||||
* as parameters and are never interpolated to the SQL string. There's no need to worry
|
||||
* about SQL injection vulnerabilities. Substitutions can be values, other `sql`
|
||||
* expressions, queries and almost anything else Kysely can produce and they get
|
||||
* handled correctly. See the examples below.
|
||||
*
|
||||
* If you need your substitutions to be interpreted as identifiers, value literals or
|
||||
* lists of things, see the {@link Sql.ref}, {@link Sql.table}, {@link Sql.id},
|
||||
* {@link Sql.lit}, {@link Sql.raw} and {@link Sql.join} functions.
|
||||
*
|
||||
* You can pass sql snippets returned by the `sql` tag pretty much anywhere. Whenever
|
||||
* something can't be done using the Kysely API, you should be able to drop down to
|
||||
* raw SQL using the `sql` tag. Here's an example query that uses raw sql in a bunch
|
||||
* of methods:
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* const nicknames = ['johnny', 'john', 'jon']
|
||||
* const date1 = new Date('2000-01-01')
|
||||
* const date2 = new Date('2001-01-01')
|
||||
*
|
||||
* const persons = await db
|
||||
* .selectFrom('person')
|
||||
* .select(
|
||||
* // If you use `sql` in a select statement, remember to call the `as`
|
||||
* // method to give it an alias.
|
||||
* sql<string>`concat(first_name, ' ', last_name)`.as('full_name')
|
||||
* )
|
||||
* .where(sql<boolean>`birthdate between ${date1} and ${date2}`)
|
||||
* // Here we assume we have list of nicknames for the person
|
||||
* // (a list of strings) and we use the PostgreSQL `@>` operator
|
||||
* // to test if all of them are valid nicknames for the user.
|
||||
* .where('nicknames', '@>', sql<string[]>`ARRAY[${sql.join(nicknames)}]`)
|
||||
* .orderBy(sql<string>`concat(first_name, ' ', last_name)`)
|
||||
* .execute()
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* select concat(first_name, ' ', last_name) as "full_name"
|
||||
* from "person"
|
||||
* where birthdate between $1 and $2
|
||||
* and "nicknames" @> ARRAY[$3, $4, $5, $6, $7, $8, $9, $10]
|
||||
* order by concat(first_name, ' ', last_name)
|
||||
* ```
|
||||
*
|
||||
* SQL snippets can be executed by calling the `execute` method and passing a `Kysely`
|
||||
* instance as the only argument:
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
* import type { Person } from 'type-editor'
|
||||
*
|
||||
* const { rows: results } = await sql<Person[]>`select * from person`.execute(db)
|
||||
* ```
|
||||
*
|
||||
* You can merge other `sql` expressions and queries using substitutions:
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* const petName = db.selectFrom('pet').select('name').limit(1)
|
||||
* const fullName = sql<string>`concat(first_name, ' ', last_name)`
|
||||
*
|
||||
* sql<{ full_name: string; pet_name: string }[]>`
|
||||
* select ${fullName} as full_name, ${petName} as pet_name
|
||||
* from person
|
||||
* `.execute(db)
|
||||
* ```
|
||||
*
|
||||
* Substitutions also handle {@link ExpressionBuilder.ref},
|
||||
* {@link DynamicModule.ref} and pretty much anything else you
|
||||
* throw at it. Here's an example of calling a function in a
|
||||
* type-safe way:
|
||||
*
|
||||
* ```ts
|
||||
* db.selectFrom('person')
|
||||
* .select([
|
||||
* 'first_name',
|
||||
* 'last_name',
|
||||
* (eb) => {
|
||||
* // The `eb.ref` method is type-safe and only accepts
|
||||
* // column references that are possible.
|
||||
* const firstName = eb.ref('first_name')
|
||||
* const lastName = eb.ref('last_name')
|
||||
*
|
||||
* const fullName = sql<string>`concat(${firstName}, ' ', ${lastName})`
|
||||
* return fullName.as('full_name')
|
||||
* }
|
||||
* ])
|
||||
* ```
|
||||
*
|
||||
* don't know if that amount of ceremony is worth the small increase in
|
||||
* type-safety though... But it's possible.
|
||||
*/
|
||||
<T = unknown>(sqlFragments: TemplateStringsArray, ...parameters: unknown[]): RawBuilder<T>;
|
||||
/**
|
||||
* `sql.val(value)` is a shortcut for:
|
||||
*
|
||||
* ```ts
|
||||
* import { sql } from 'kysely'
|
||||
*
|
||||
* const value = 123
|
||||
* type ValueType = typeof value
|
||||
*
|
||||
* sql<ValueType>`${value}`
|
||||
* ```
|
||||
*/
|
||||
val<V>(value: V): RawBuilder<V>;
|
||||
/**
|
||||
* @deprecated Use {@link Sql.val} instead.
|
||||
*/
|
||||
value<V>(value: V): RawBuilder<V>;
|
||||
/**
|
||||
* This can be used to add runtime column references to SQL snippets.
|
||||
*
|
||||
* By default `${}` substitutions in {@link sql} template strings get
|
||||
* transformed into parameters. You can use this function to tell
|
||||
* Kysely to interpret them as column references instead.
|
||||
*
|
||||
* WARNING! Using this with unchecked inputs WILL lead to SQL injection
|
||||
* vulnerabilities. The input is not checked or escaped by Kysely in any way.
|
||||
*
|
||||
* ```ts
|
||||
* const columnRef = 'first_name'
|
||||
*
|
||||
* sql`select ${sql.ref(columnRef)} from person`
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* select "first_name" from person
|
||||
* ```
|
||||
*
|
||||
* The references can also include a table name:
|
||||
*
|
||||
* ```ts
|
||||
* const columnRef = 'person.first_name'
|
||||
*
|
||||
* sql`select ${sql.ref(columnRef)}} from person`
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* select "person"."first_name" from person
|
||||
* ```
|
||||
*
|
||||
* The references can also include a schema on supported databases:
|
||||
*
|
||||
* ```ts
|
||||
* const columnRef = 'public.person.first_name'
|
||||
*
|
||||
* sql`select ${sql.ref(columnRef)}} from person`
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* select "public"."person"."first_name" from person
|
||||
* ```
|
||||
*/
|
||||
ref<R = unknown>(columnReference: string): RawBuilder<R>;
|
||||
/**
|
||||
* This can be used to add runtime table references to SQL snippets.
|
||||
*
|
||||
* By default `${}` substitutions in {@link sql} template strings get
|
||||
* transformed into parameters. You can use this function to tell
|
||||
* Kysely to interpret them as table references instead.
|
||||
*
|
||||
* WARNING! Using this with unchecked inputs WILL lead to SQL injection
|
||||
* vulnerabilities. The input is not checked or escaped by Kysely in any way.
|
||||
*
|
||||
* ```ts
|
||||
* const table = 'person'
|
||||
*
|
||||
* sql`select first_name from ${sql.table(table)}`
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* select first_name from "person"
|
||||
* ```
|
||||
*
|
||||
* The references can also include a schema on supported databases:
|
||||
*
|
||||
* ```ts
|
||||
* const table = 'public.person'
|
||||
*
|
||||
* sql`select first_name from ${sql.table(table)}`
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* select first_name from "public"."person"
|
||||
* ```
|
||||
*/
|
||||
table<T = unknown>(tableReference: string): RawBuilder<T>;
|
||||
/**
|
||||
* This can be used to add arbitrary identifiers to SQL snippets.
|
||||
*
|
||||
* Does the same thing as {@link Sql.ref | ref} and {@link Sql.table | table}
|
||||
* but can also be used for any other identifiers like index names.
|
||||
*
|
||||
* You should use {@link Sql.ref | ref} and {@link Sql.table | table}
|
||||
* instead of this whenever possible as they produce a more semantic
|
||||
* operation node tree.
|
||||
*
|
||||
* WARNING! Using this with unchecked inputs WILL lead to SQL injection
|
||||
* vulnerabilities. The input is not checked or escaped by Kysely in any way.
|
||||
*
|
||||
* ```ts
|
||||
* const indexName = 'person_first_name_index'
|
||||
*
|
||||
* sql`create index ${indexName} on person`
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* create index "person_first_name_index" on person
|
||||
* ```
|
||||
*
|
||||
* Multiple identifiers get separated by dots:
|
||||
*
|
||||
* ```ts
|
||||
* const schema = 'public'
|
||||
* const columnName = 'first_name'
|
||||
* const table = 'person'
|
||||
*
|
||||
* sql`select ${sql.id(schema, table, columnName)} from ${sql.id(schema, table)}`
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* select "public"."person"."first_name" from "public"."person"
|
||||
* ```
|
||||
*/
|
||||
id<T = unknown>(...ids: readonly string[]): RawBuilder<T>;
|
||||
/**
|
||||
* This can be used to add literal values to SQL snippets.
|
||||
*
|
||||
* WARNING! Using this with unchecked inputs WILL lead to SQL injection
|
||||
* vulnerabilities. The input is not checked or escaped by Kysely in any way.
|
||||
* You almost always want to use normal substitutions that get sent to the
|
||||
* db as parameters.
|
||||
*
|
||||
* ```ts
|
||||
* const firstName = 'first_name'
|
||||
*
|
||||
* sql`select * from person where first_name = ${sql.lit(firstName)}`
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* select * from person where first_name = 'first_name'
|
||||
* ```
|
||||
*
|
||||
* As you can see from the example above, the value was added directly to
|
||||
* the SQL string instead of as a parameter. Only use this function when
|
||||
* something can't be sent as a parameter.
|
||||
*/
|
||||
lit<V>(value: V): RawBuilder<V>;
|
||||
/**
|
||||
* @deprecated Use {@link lit} instead.
|
||||
*/
|
||||
literal<V>(value: V): RawBuilder<V>;
|
||||
/**
|
||||
* This can be used to add arbitrary runtime SQL to SQL snippets.
|
||||
*
|
||||
* WARNING! Using this with unchecked inputs WILL lead to SQL injection
|
||||
* vulnerabilities. The input is not checked or escaped by Kysely in any way.
|
||||
*
|
||||
* ```ts
|
||||
* const firstName = "'first_name'"
|
||||
*
|
||||
* sql`select * from person where first_name = ${sql.raw(firstName)}`
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* select * from person where first_name = 'first_name'
|
||||
* ```
|
||||
*
|
||||
* Note that the difference to `sql.lit` is that this function
|
||||
* doesn't assume the inputs are values. The input to this function
|
||||
* can be any sql and it's simply glued to the parent string as-is.
|
||||
*/
|
||||
raw<R = unknown>(anySql: string): RawBuilder<R>;
|
||||
/**
|
||||
* This can be used to add lists of things to SQL snippets.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* ```ts
|
||||
* import type { Person } from 'type-editor' // imaginary module
|
||||
*
|
||||
* function findByNicknames(nicknames: string[]): Promise<Person[]> {
|
||||
* return db
|
||||
* .selectFrom('person')
|
||||
* .selectAll()
|
||||
* .where('nicknames', '@>', sql<string[]>`ARRAY[${sql.join(nicknames)}]`)
|
||||
* .execute()
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* select * from "person"
|
||||
* where "nicknames" @> ARRAY[$1, $2, $3, $4, $5, $6, $7, $8]
|
||||
* ```
|
||||
*
|
||||
* The second argument is the joining SQL expression that defaults
|
||||
* to
|
||||
*
|
||||
* ```ts
|
||||
* sql`, `
|
||||
* ```
|
||||
*
|
||||
* In addition to values, items in the list can be also {@link sql}
|
||||
* expressions, queries or anything else the normal substitutions
|
||||
* support:
|
||||
*
|
||||
* ```ts
|
||||
* const things = [
|
||||
* 123,
|
||||
* sql`(1 == 1)`,
|
||||
* db.selectFrom('person').selectAll(),
|
||||
* sql.lit(false),
|
||||
* sql.id('first_name')
|
||||
* ]
|
||||
*
|
||||
* sql`BEFORE ${sql.join(things, sql`::varchar, `)} AFTER`
|
||||
* ```
|
||||
*
|
||||
* The generated SQL (PostgreSQL):
|
||||
*
|
||||
* ```sql
|
||||
* BEFORE $1::varchar, (1 == 1)::varchar, (select * from "person")::varchar, false::varchar, "first_name" AFTER
|
||||
* ```
|
||||
*/
|
||||
join<T = unknown>(array: readonly unknown[], separator?: RawBuilder<any>): RawBuilder<T>;
|
||||
}
|
||||
export declare const sql: Sql;
|
||||
84
node_modules/kysely/dist/cjs/raw-builder/sql.js
generated
vendored
Normal file
84
node_modules/kysely/dist/cjs/raw-builder/sql.js
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.sql = void 0;
|
||||
const identifier_node_js_1 = require("../operation-node/identifier-node.js");
|
||||
const operation_node_source_js_1 = require("../operation-node/operation-node-source.js");
|
||||
const raw_node_js_1 = require("../operation-node/raw-node.js");
|
||||
const value_node_js_1 = require("../operation-node/value-node.js");
|
||||
const reference_parser_js_1 = require("../parser/reference-parser.js");
|
||||
const table_parser_js_1 = require("../parser/table-parser.js");
|
||||
const value_parser_js_1 = require("../parser/value-parser.js");
|
||||
const query_id_js_1 = require("../util/query-id.js");
|
||||
const raw_builder_js_1 = require("./raw-builder.js");
|
||||
exports.sql = Object.assign((sqlFragments, ...parameters) => {
|
||||
return (0, raw_builder_js_1.createRawBuilder)({
|
||||
queryId: (0, query_id_js_1.createQueryId)(),
|
||||
rawNode: raw_node_js_1.RawNode.create(sqlFragments, parameters?.map(parseParameter) ?? []),
|
||||
});
|
||||
}, {
|
||||
ref(columnReference) {
|
||||
return (0, raw_builder_js_1.createRawBuilder)({
|
||||
queryId: (0, query_id_js_1.createQueryId)(),
|
||||
rawNode: raw_node_js_1.RawNode.createWithChild((0, reference_parser_js_1.parseStringReference)(columnReference)),
|
||||
});
|
||||
},
|
||||
val(value) {
|
||||
return (0, raw_builder_js_1.createRawBuilder)({
|
||||
queryId: (0, query_id_js_1.createQueryId)(),
|
||||
rawNode: raw_node_js_1.RawNode.createWithChild((0, value_parser_js_1.parseValueExpression)(value)),
|
||||
});
|
||||
},
|
||||
value(value) {
|
||||
return this.val(value);
|
||||
},
|
||||
table(tableReference) {
|
||||
return (0, raw_builder_js_1.createRawBuilder)({
|
||||
queryId: (0, query_id_js_1.createQueryId)(),
|
||||
rawNode: raw_node_js_1.RawNode.createWithChild((0, table_parser_js_1.parseTable)(tableReference)),
|
||||
});
|
||||
},
|
||||
id(...ids) {
|
||||
const fragments = new Array(ids.length + 1).fill('.');
|
||||
fragments[0] = '';
|
||||
fragments[fragments.length - 1] = '';
|
||||
return (0, raw_builder_js_1.createRawBuilder)({
|
||||
queryId: (0, query_id_js_1.createQueryId)(),
|
||||
rawNode: raw_node_js_1.RawNode.create(fragments, ids.map(identifier_node_js_1.IdentifierNode.create)),
|
||||
});
|
||||
},
|
||||
lit(value) {
|
||||
return (0, raw_builder_js_1.createRawBuilder)({
|
||||
queryId: (0, query_id_js_1.createQueryId)(),
|
||||
rawNode: raw_node_js_1.RawNode.createWithChild(value_node_js_1.ValueNode.createImmediate(value)),
|
||||
});
|
||||
},
|
||||
literal(value) {
|
||||
return this.lit(value);
|
||||
},
|
||||
raw(sql) {
|
||||
return (0, raw_builder_js_1.createRawBuilder)({
|
||||
queryId: (0, query_id_js_1.createQueryId)(),
|
||||
rawNode: raw_node_js_1.RawNode.createWithSql(sql),
|
||||
});
|
||||
},
|
||||
join(array, separator = (0, exports.sql) `, `) {
|
||||
const nodes = new Array(Math.max(2 * array.length - 1, 0));
|
||||
const sep = separator.toOperationNode();
|
||||
for (let i = 0; i < array.length; ++i) {
|
||||
nodes[2 * i] = parseParameter(array[i]);
|
||||
if (i !== array.length - 1) {
|
||||
nodes[2 * i + 1] = sep;
|
||||
}
|
||||
}
|
||||
return (0, raw_builder_js_1.createRawBuilder)({
|
||||
queryId: (0, query_id_js_1.createQueryId)(),
|
||||
rawNode: raw_node_js_1.RawNode.createWithChildren(nodes),
|
||||
});
|
||||
},
|
||||
});
|
||||
function parseParameter(param) {
|
||||
if ((0, operation_node_source_js_1.isOperationNodeSource)(param)) {
|
||||
return param.toOperationNode();
|
||||
}
|
||||
return (0, value_parser_js_1.parseValueExpression)(param);
|
||||
}
|
||||
Reference in New Issue
Block a user