Initial commit - Event Planner application
This commit is contained in:
18
node_modules/kysely/dist/esm/dynamic/dynamic-reference-builder.d.ts
generated
vendored
Normal file
18
node_modules/kysely/dist/esm/dynamic/dynamic-reference-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import { type OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
import type { SimpleReferenceExpressionNode } from '../operation-node/simple-reference-expression-node.js';
|
||||
export declare class DynamicReferenceBuilder<R extends string = never> implements OperationNodeSource {
|
||||
#private;
|
||||
get dynamicReference(): string;
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* This needs to be here just so that the typings work. Without this
|
||||
* the generated .d.ts file contains no reference to the type param R
|
||||
* which causes this type to be equal to DynamicReferenceBuilder with
|
||||
* any R.
|
||||
*/
|
||||
protected get refType(): R;
|
||||
constructor(reference: string);
|
||||
toOperationNode(): SimpleReferenceExpressionNode;
|
||||
}
|
||||
export declare function isDynamicReferenceBuilder(obj: unknown): obj is DynamicReferenceBuilder<any>;
|
||||
32
node_modules/kysely/dist/esm/dynamic/dynamic-reference-builder.js
generated
vendored
Normal file
32
node_modules/kysely/dist/esm/dynamic/dynamic-reference-builder.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
/// <reference types="./dynamic-reference-builder.d.ts" />
|
||||
import { isOperationNodeSource, } from '../operation-node/operation-node-source.js';
|
||||
import { parseSimpleReferenceExpression } from '../parser/reference-parser.js';
|
||||
import { isObject, isString } from '../util/object-utils.js';
|
||||
export class DynamicReferenceBuilder {
|
||||
#dynamicReference;
|
||||
get dynamicReference() {
|
||||
return this.#dynamicReference;
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* This needs to be here just so that the typings work. Without this
|
||||
* the generated .d.ts file contains no reference to the type param R
|
||||
* which causes this type to be equal to DynamicReferenceBuilder with
|
||||
* any R.
|
||||
*/
|
||||
get refType() {
|
||||
return undefined;
|
||||
}
|
||||
constructor(reference) {
|
||||
this.#dynamicReference = reference;
|
||||
}
|
||||
toOperationNode() {
|
||||
return parseSimpleReferenceExpression(this.#dynamicReference);
|
||||
}
|
||||
}
|
||||
export function isDynamicReferenceBuilder(obj) {
|
||||
return (isObject(obj) &&
|
||||
isOperationNodeSource(obj) &&
|
||||
isString(obj.dynamicReference));
|
||||
}
|
||||
16
node_modules/kysely/dist/esm/dynamic/dynamic-table-builder.d.ts
generated
vendored
Normal file
16
node_modules/kysely/dist/esm/dynamic/dynamic-table-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import { AliasNode } from '../operation-node/alias-node.js';
|
||||
import { type OperationNodeSource } from '../operation-node/operation-node-source.js';
|
||||
export declare class DynamicTableBuilder<T extends string> {
|
||||
#private;
|
||||
get table(): T;
|
||||
constructor(table: T);
|
||||
as<A extends string>(alias: A): AliasedDynamicTableBuilder<T, A>;
|
||||
}
|
||||
export declare class AliasedDynamicTableBuilder<T extends string, A extends string> implements OperationNodeSource {
|
||||
#private;
|
||||
get table(): T;
|
||||
get alias(): A;
|
||||
constructor(table: T, alias: A);
|
||||
toOperationNode(): AliasNode;
|
||||
}
|
||||
export declare function isAliasedDynamicTableBuilder(obj: unknown): obj is AliasedDynamicTableBuilder<any, any>;
|
||||
41
node_modules/kysely/dist/esm/dynamic/dynamic-table-builder.js
generated
vendored
Normal file
41
node_modules/kysely/dist/esm/dynamic/dynamic-table-builder.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
/// <reference types="./dynamic-table-builder.d.ts" />
|
||||
import { AliasNode } from '../operation-node/alias-node.js';
|
||||
import { IdentifierNode } from '../operation-node/identifier-node.js';
|
||||
import { isOperationNodeSource, } from '../operation-node/operation-node-source.js';
|
||||
import { parseTable } from '../parser/table-parser.js';
|
||||
import { isObject, isString } from '../util/object-utils.js';
|
||||
export class DynamicTableBuilder {
|
||||
#table;
|
||||
get table() {
|
||||
return this.#table;
|
||||
}
|
||||
constructor(table) {
|
||||
this.#table = table;
|
||||
}
|
||||
as(alias) {
|
||||
return new AliasedDynamicTableBuilder(this.#table, alias);
|
||||
}
|
||||
}
|
||||
export class AliasedDynamicTableBuilder {
|
||||
#table;
|
||||
#alias;
|
||||
get table() {
|
||||
return this.#table;
|
||||
}
|
||||
get alias() {
|
||||
return this.#alias;
|
||||
}
|
||||
constructor(table, alias) {
|
||||
this.#table = table;
|
||||
this.#alias = alias;
|
||||
}
|
||||
toOperationNode() {
|
||||
return AliasNode.create(parseTable(this.#table), IdentifierNode.create(this.#alias));
|
||||
}
|
||||
}
|
||||
export function isAliasedDynamicTableBuilder(obj) {
|
||||
return (isObject(obj) &&
|
||||
isOperationNodeSource(obj) &&
|
||||
isString(obj.table) &&
|
||||
isString(obj.alias));
|
||||
}
|
||||
124
node_modules/kysely/dist/esm/dynamic/dynamic.d.ts
generated
vendored
Normal file
124
node_modules/kysely/dist/esm/dynamic/dynamic.d.ts
generated
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
import { DynamicReferenceBuilder } from './dynamic-reference-builder.js';
|
||||
import { DynamicTableBuilder } from './dynamic-table-builder.js';
|
||||
export declare class DynamicModule<DB> {
|
||||
/**
|
||||
* Creates a dynamic reference to a column that is not know at compile time.
|
||||
*
|
||||
* Kysely is built in a way that by default you can't refer to tables or columns
|
||||
* that are not actually visible in the current query and context. This is all
|
||||
* done by TypeScript at compile time, which means that you need to know the
|
||||
* columns and tables at compile time. This is not always the case of course.
|
||||
*
|
||||
* This method is meant to be used in those cases where the column names
|
||||
* come from the user input or are not otherwise known at compile time.
|
||||
*
|
||||
* WARNING! Unlike values, column names are not escaped by the database engine
|
||||
* or Kysely and if you pass in unchecked column names using this method, you
|
||||
* create an SQL injection vulnerability. Always __always__ validate the user
|
||||
* input before passing it to this method.
|
||||
*
|
||||
* There are couple of examples below for some use cases, but you can pass
|
||||
* `ref` to other methods as well. If the types allow you to pass a `ref`
|
||||
* value to some place, it should work.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* Filter by a column not know at compile time:
|
||||
*
|
||||
* ```ts
|
||||
* async function someQuery(filterColumn: string, filterValue: string) {
|
||||
* const { ref } = db.dynamic
|
||||
*
|
||||
* return await db
|
||||
* .selectFrom('person')
|
||||
* .selectAll()
|
||||
* .where(ref(filterColumn), '=', filterValue)
|
||||
* .execute()
|
||||
* }
|
||||
*
|
||||
* someQuery('first_name', 'Arnold')
|
||||
* someQuery('person.last_name', 'Aniston')
|
||||
* ```
|
||||
*
|
||||
* Order by a column not know at compile time:
|
||||
*
|
||||
* ```ts
|
||||
* async function someQuery(orderBy: string) {
|
||||
* const { ref } = db.dynamic
|
||||
*
|
||||
* return await db
|
||||
* .selectFrom('person')
|
||||
* .select('person.first_name as fn')
|
||||
* .orderBy(ref(orderBy))
|
||||
* .execute()
|
||||
* }
|
||||
*
|
||||
* someQuery('fn')
|
||||
* ```
|
||||
*
|
||||
* In this example we add selections dynamically:
|
||||
*
|
||||
* ```ts
|
||||
* const { ref } = db.dynamic
|
||||
*
|
||||
* // Some column name provided by the user. Value not known at compile time.
|
||||
* const columnFromUserInput: PossibleColumns = 'birthdate';
|
||||
*
|
||||
* // A type that lists all possible values `columnFromUserInput` can have.
|
||||
* // You can use `keyof Person` if any column of an interface is allowed.
|
||||
* type PossibleColumns = 'last_name' | 'first_name' | 'birthdate'
|
||||
*
|
||||
* const [person] = await db.selectFrom('person')
|
||||
* .select([
|
||||
* ref<PossibleColumns>(columnFromUserInput),
|
||||
* 'id'
|
||||
* ])
|
||||
* .execute()
|
||||
*
|
||||
* // The resulting type contains all `PossibleColumns` as optional fields
|
||||
* // because we cannot know which field was actually selected before
|
||||
* // running the code.
|
||||
* const lastName: string | null | undefined = person?.last_name
|
||||
* const firstName: string | undefined = person?.first_name
|
||||
* const birthDate: Date | null | undefined = person?.birthdate
|
||||
*
|
||||
* // The result type also contains the compile time selection `id`.
|
||||
* person?.id
|
||||
* ```
|
||||
*/
|
||||
ref<R extends string = never>(reference: string): DynamicReferenceBuilder<R>;
|
||||
/**
|
||||
* Creates a table reference to a table that's not fully known at compile time.
|
||||
*
|
||||
* The type `T` is allowed to be a union of multiple tables.
|
||||
*
|
||||
* <!-- siteExample("select", "Generic find query", 130) -->
|
||||
*
|
||||
* A generic type-safe helper function for finding a row by a column value:
|
||||
*
|
||||
* ```ts
|
||||
* import { SelectType } from 'kysely'
|
||||
* import { Database } from 'type-editor'
|
||||
*
|
||||
* async function getRowByColumn<
|
||||
* T extends keyof Database,
|
||||
* C extends keyof Database[T] & string,
|
||||
* V extends SelectType<Database[T][C]>,
|
||||
* >(t: T, c: C, v: V) {
|
||||
* // We need to use the dynamic module since the table name
|
||||
* // is not known at compile time.
|
||||
* const { table, ref } = db.dynamic
|
||||
*
|
||||
* return await db
|
||||
* .selectFrom(table(t).as('t'))
|
||||
* .selectAll()
|
||||
* .where(ref(c), '=', v)
|
||||
* .orderBy('t.id')
|
||||
* .executeTakeFirstOrThrow()
|
||||
* }
|
||||
*
|
||||
* const person = await getRowByColumn('person', 'first_name', 'Arnold')
|
||||
* ```
|
||||
*/
|
||||
table<T extends keyof DB & string>(table: T): DynamicTableBuilder<T>;
|
||||
}
|
||||
129
node_modules/kysely/dist/esm/dynamic/dynamic.js
generated
vendored
Normal file
129
node_modules/kysely/dist/esm/dynamic/dynamic.js
generated
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
/// <reference types="./dynamic.d.ts" />
|
||||
import { DynamicReferenceBuilder } from './dynamic-reference-builder.js';
|
||||
import { DynamicTableBuilder } from './dynamic-table-builder.js';
|
||||
export class DynamicModule {
|
||||
/**
|
||||
* Creates a dynamic reference to a column that is not know at compile time.
|
||||
*
|
||||
* Kysely is built in a way that by default you can't refer to tables or columns
|
||||
* that are not actually visible in the current query and context. This is all
|
||||
* done by TypeScript at compile time, which means that you need to know the
|
||||
* columns and tables at compile time. This is not always the case of course.
|
||||
*
|
||||
* This method is meant to be used in those cases where the column names
|
||||
* come from the user input or are not otherwise known at compile time.
|
||||
*
|
||||
* WARNING! Unlike values, column names are not escaped by the database engine
|
||||
* or Kysely and if you pass in unchecked column names using this method, you
|
||||
* create an SQL injection vulnerability. Always __always__ validate the user
|
||||
* input before passing it to this method.
|
||||
*
|
||||
* There are couple of examples below for some use cases, but you can pass
|
||||
* `ref` to other methods as well. If the types allow you to pass a `ref`
|
||||
* value to some place, it should work.
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* Filter by a column not know at compile time:
|
||||
*
|
||||
* ```ts
|
||||
* async function someQuery(filterColumn: string, filterValue: string) {
|
||||
* const { ref } = db.dynamic
|
||||
*
|
||||
* return await db
|
||||
* .selectFrom('person')
|
||||
* .selectAll()
|
||||
* .where(ref(filterColumn), '=', filterValue)
|
||||
* .execute()
|
||||
* }
|
||||
*
|
||||
* someQuery('first_name', 'Arnold')
|
||||
* someQuery('person.last_name', 'Aniston')
|
||||
* ```
|
||||
*
|
||||
* Order by a column not know at compile time:
|
||||
*
|
||||
* ```ts
|
||||
* async function someQuery(orderBy: string) {
|
||||
* const { ref } = db.dynamic
|
||||
*
|
||||
* return await db
|
||||
* .selectFrom('person')
|
||||
* .select('person.first_name as fn')
|
||||
* .orderBy(ref(orderBy))
|
||||
* .execute()
|
||||
* }
|
||||
*
|
||||
* someQuery('fn')
|
||||
* ```
|
||||
*
|
||||
* In this example we add selections dynamically:
|
||||
*
|
||||
* ```ts
|
||||
* const { ref } = db.dynamic
|
||||
*
|
||||
* // Some column name provided by the user. Value not known at compile time.
|
||||
* const columnFromUserInput: PossibleColumns = 'birthdate';
|
||||
*
|
||||
* // A type that lists all possible values `columnFromUserInput` can have.
|
||||
* // You can use `keyof Person` if any column of an interface is allowed.
|
||||
* type PossibleColumns = 'last_name' | 'first_name' | 'birthdate'
|
||||
*
|
||||
* const [person] = await db.selectFrom('person')
|
||||
* .select([
|
||||
* ref<PossibleColumns>(columnFromUserInput),
|
||||
* 'id'
|
||||
* ])
|
||||
* .execute()
|
||||
*
|
||||
* // The resulting type contains all `PossibleColumns` as optional fields
|
||||
* // because we cannot know which field was actually selected before
|
||||
* // running the code.
|
||||
* const lastName: string | null | undefined = person?.last_name
|
||||
* const firstName: string | undefined = person?.first_name
|
||||
* const birthDate: Date | null | undefined = person?.birthdate
|
||||
*
|
||||
* // The result type also contains the compile time selection `id`.
|
||||
* person?.id
|
||||
* ```
|
||||
*/
|
||||
ref(reference) {
|
||||
return new DynamicReferenceBuilder(reference);
|
||||
}
|
||||
/**
|
||||
* Creates a table reference to a table that's not fully known at compile time.
|
||||
*
|
||||
* The type `T` is allowed to be a union of multiple tables.
|
||||
*
|
||||
* <!-- siteExample("select", "Generic find query", 130) -->
|
||||
*
|
||||
* A generic type-safe helper function for finding a row by a column value:
|
||||
*
|
||||
* ```ts
|
||||
* import { SelectType } from 'kysely'
|
||||
* import { Database } from 'type-editor'
|
||||
*
|
||||
* async function getRowByColumn<
|
||||
* T extends keyof Database,
|
||||
* C extends keyof Database[T] & string,
|
||||
* V extends SelectType<Database[T][C]>,
|
||||
* >(t: T, c: C, v: V) {
|
||||
* // We need to use the dynamic module since the table name
|
||||
* // is not known at compile time.
|
||||
* const { table, ref } = db.dynamic
|
||||
*
|
||||
* return await db
|
||||
* .selectFrom(table(t).as('t'))
|
||||
* .selectAll()
|
||||
* .where(ref(c), '=', v)
|
||||
* .orderBy('t.id')
|
||||
* .executeTakeFirstOrThrow()
|
||||
* }
|
||||
*
|
||||
* const person = await getRowByColumn('person', 'first_name', 'Arnold')
|
||||
* ```
|
||||
*/
|
||||
table(table) {
|
||||
return new DynamicTableBuilder(table);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user