Initial commit - Event Planner application

This commit is contained in:
mberlin
2026-03-18 14:55:56 -03:00
commit 86d779eb4d
7548 changed files with 1006324 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
import type { ConnectionProvider } from '../driver/connection-provider.js';
import type { DatabaseConnection } from '../driver/database-connection.js';
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
import type { RootOperationNode, QueryCompiler } from '../query-compiler/query-compiler.js';
import type { KyselyPlugin } from '../plugin/kysely-plugin.js';
import { QueryExecutorBase } from './query-executor-base.js';
import type { DialectAdapter } from '../dialect/dialect-adapter.js';
import type { QueryId } from '../util/query-id.js';
export declare class DefaultQueryExecutor extends QueryExecutorBase {
#private;
constructor(compiler: QueryCompiler, adapter: DialectAdapter, connectionProvider: ConnectionProvider, plugins?: KyselyPlugin[]);
/**
* Returns the adapter for the current dialect.
*/
get adapter(): DialectAdapter;
/**
* Compiles the transformed query into SQL. You usually want to pass
* the output of {@link transformQuery} into this method but you can
* compile any query using this method.
*/
compileQuery(node: RootOperationNode, queryId: QueryId): CompiledQuery;
/**
* Provides a connection for the callback and takes care of disposing
* the connection after the callback has been run.
*/
provideConnection<T>(consumer: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
/**
* Returns a copy of this executor with a list of plugins added
* as the last plugins.
*/
withPlugins(plugins: ReadonlyArray<KyselyPlugin>): DefaultQueryExecutor;
/**
* Returns a copy of this executor with a plugin added as the
* last plugin.
*/
withPlugin(plugin: KyselyPlugin): DefaultQueryExecutor;
/**
* Returns a copy of this executor with a plugin added as the
* first plugin.
*/
withPluginAtFront(plugin: KyselyPlugin): DefaultQueryExecutor;
/**
* Returns a copy of this executor with a new connection provider.
*/
withConnectionProvider(connectionProvider: ConnectionProvider): DefaultQueryExecutor;
/**
* Returns a copy of this executor without any plugins.
*/
withoutPlugins(): DefaultQueryExecutor;
}

View File

@@ -0,0 +1,37 @@
/// <reference types="./default-query-executor.d.ts" />
import { QueryExecutorBase } from './query-executor-base.js';
export class DefaultQueryExecutor extends QueryExecutorBase {
#compiler;
#adapter;
#connectionProvider;
constructor(compiler, adapter, connectionProvider, plugins = []) {
super(plugins);
this.#compiler = compiler;
this.#adapter = adapter;
this.#connectionProvider = connectionProvider;
}
get adapter() {
return this.#adapter;
}
compileQuery(node, queryId) {
return this.#compiler.compileQuery(node, queryId);
}
provideConnection(consumer) {
return this.#connectionProvider.provideConnection(consumer);
}
withPlugins(plugins) {
return new DefaultQueryExecutor(this.#compiler, this.#adapter, this.#connectionProvider, [...this.plugins, ...plugins]);
}
withPlugin(plugin) {
return new DefaultQueryExecutor(this.#compiler, this.#adapter, this.#connectionProvider, [...this.plugins, plugin]);
}
withPluginAtFront(plugin) {
return new DefaultQueryExecutor(this.#compiler, this.#adapter, this.#connectionProvider, [plugin, ...this.plugins]);
}
withConnectionProvider(connectionProvider) {
return new DefaultQueryExecutor(this.#compiler, this.#adapter, connectionProvider, [...this.plugins]);
}
withoutPlugins() {
return new DefaultQueryExecutor(this.#compiler, this.#adapter, this.#connectionProvider, []);
}
}

View File

@@ -0,0 +1,50 @@
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
import type { KyselyPlugin } from '../plugin/kysely-plugin.js';
import type { DialectAdapter } from '../dialect/dialect-adapter.js';
import { QueryExecutorBase } from './query-executor-base.js';
/**
* A {@link QueryExecutor} subclass that can be used when you don't
* have a {@link QueryCompiler}, {@link ConnectionProvider} or any
* other needed things to actually execute queries.
*/
export declare class NoopQueryExecutor extends QueryExecutorBase {
/**
* Returns the adapter for the current dialect.
*/
get adapter(): DialectAdapter;
/**
* Compiles the transformed query into SQL. You usually want to pass
* the output of {@link transformQuery} into this method but you can
* compile any query using this method.
*/
compileQuery(): CompiledQuery;
/**
* Provides a connection for the callback and takes care of disposing
* the connection after the callback has been run.
*/
provideConnection<T>(): Promise<T>;
/**
* Returns a copy of this executor with a new connection provider.
*/
withConnectionProvider(): NoopQueryExecutor;
/**
* Returns a copy of this executor with a plugin added as the
* last plugin.
*/
withPlugin(plugin: KyselyPlugin): NoopQueryExecutor;
/**
* Returns a copy of this executor with a list of plugins added
* as the last plugins.
*/
withPlugins(plugins: ReadonlyArray<KyselyPlugin>): NoopQueryExecutor;
/**
* Returns a copy of this executor with a plugin added as the
* first plugin.
*/
withPluginAtFront(plugin: KyselyPlugin): NoopQueryExecutor;
/**
* Returns a copy of this executor without any plugins.
*/
withoutPlugins(): NoopQueryExecutor;
}
export declare const NOOP_QUERY_EXECUTOR: NoopQueryExecutor;

View File

@@ -0,0 +1,34 @@
/// <reference types="./noop-query-executor.d.ts" />
import { QueryExecutorBase } from './query-executor-base.js';
/**
* A {@link QueryExecutor} subclass that can be used when you don't
* have a {@link QueryCompiler}, {@link ConnectionProvider} or any
* other needed things to actually execute queries.
*/
export class NoopQueryExecutor extends QueryExecutorBase {
get adapter() {
throw new Error('this query cannot be compiled to SQL');
}
compileQuery() {
throw new Error('this query cannot be compiled to SQL');
}
provideConnection() {
throw new Error('this query cannot be executed');
}
withConnectionProvider() {
throw new Error('this query cannot have a connection provider');
}
withPlugin(plugin) {
return new NoopQueryExecutor([...this.plugins, plugin]);
}
withPlugins(plugins) {
return new NoopQueryExecutor([...this.plugins, ...plugins]);
}
withPluginAtFront(plugin) {
return new NoopQueryExecutor([plugin, ...this.plugins]);
}
withoutPlugins() {
return new NoopQueryExecutor([]);
}
}
export const NOOP_QUERY_EXECUTOR = new NoopQueryExecutor();

View File

@@ -0,0 +1,68 @@
import type { ConnectionProvider } from '../driver/connection-provider.js';
import type { DatabaseConnection, QueryResult } from '../driver/database-connection.js';
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
import type { RootOperationNode } from '../query-compiler/query-compiler.js';
import type { KyselyPlugin } from '../plugin/kysely-plugin.js';
import type { QueryId } from '../util/query-id.js';
import type { DialectAdapter } from '../dialect/dialect-adapter.js';
import type { QueryExecutor } from './query-executor.js';
export declare abstract class QueryExecutorBase implements QueryExecutor {
#private;
constructor(plugins?: ReadonlyArray<KyselyPlugin>);
abstract get adapter(): DialectAdapter;
/**
* Returns all installed plugins.
*/
get plugins(): ReadonlyArray<KyselyPlugin>;
/**
* Given the query the user has built (expressed as an operation node tree)
* this method runs it through all plugins' `transformQuery` methods and
* returns the result.
*/
transformQuery<T extends RootOperationNode>(node: T, queryId: QueryId): T;
/**
* Compiles the transformed query into SQL. You usually want to pass
* the output of {@link transformQuery} into this method but you can
* compile any query using this method.
*/
abstract compileQuery(node: RootOperationNode, queryId: QueryId): CompiledQuery;
/**
* Provides a connection for the callback and takes care of disposing
* the connection after the callback has been run.
*/
abstract provideConnection<T>(consumer: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
/**
* Executes a compiled query and runs the result through all plugins'
* `transformResult` method.
*/
executeQuery<R>(compiledQuery: CompiledQuery): Promise<QueryResult<R>>;
/**
* Executes a compiled query and runs the result through all plugins'
* `transformResult` method. Results are streamead instead of loaded
* at once.
*/
stream<R>(compiledQuery: CompiledQuery, chunkSize: number): AsyncIterableIterator<QueryResult<R>>;
/**
* Returns a copy of this executor with a new connection provider.
*/
abstract withConnectionProvider(connectionProvider: ConnectionProvider): QueryExecutorBase;
/**
* Returns a copy of this executor with a plugin added as the
* last plugin.
*/
abstract withPlugin(plugin: KyselyPlugin): QueryExecutorBase;
/**
* Returns a copy of this executor with a list of plugins added
* as the last plugins.
*/
abstract withPlugins(plugin: ReadonlyArray<KyselyPlugin>): QueryExecutorBase;
/**
* Returns a copy of this executor with a plugin added as the
* first plugin.
*/
abstract withPluginAtFront(plugin: KyselyPlugin): QueryExecutorBase;
/**
* Returns a copy of this executor without any plugins.
*/
abstract withoutPlugins(): QueryExecutorBase;
}

View File

@@ -0,0 +1,59 @@
/// <reference types="./query-executor-base.d.ts" />
import { freeze } from '../util/object-utils.js';
import { provideControlledConnection } from '../util/provide-controlled-connection.js';
import { logOnce } from '../util/log-once.js';
const NO_PLUGINS = freeze([]);
export class QueryExecutorBase {
#plugins;
constructor(plugins = NO_PLUGINS) {
this.#plugins = plugins;
}
get plugins() {
return this.#plugins;
}
transformQuery(node, queryId) {
for (const plugin of this.#plugins) {
const transformedNode = plugin.transformQuery({ node, queryId });
// We need to do a runtime check here. There is no good way
// to write types that enforce this constraint.
if (transformedNode.kind === node.kind) {
node = transformedNode;
}
else {
throw new Error([
`KyselyPlugin.transformQuery must return a node`,
`of the same kind that was given to it.`,
`The plugin was given a ${node.kind}`,
`but it returned a ${transformedNode.kind}`,
].join(' '));
}
}
return node;
}
async executeQuery(compiledQuery) {
return await this.provideConnection(async (connection) => {
const result = await connection.executeQuery(compiledQuery);
if ('numUpdatedOrDeletedRows' in result) {
logOnce('kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`.');
}
return await this.#transformResult(result, compiledQuery.queryId);
});
}
async *stream(compiledQuery, chunkSize) {
const { connection, release } = await provideControlledConnection(this);
try {
for await (const result of connection.streamQuery(compiledQuery, chunkSize)) {
yield await this.#transformResult(result, compiledQuery.queryId);
}
}
finally {
release();
}
}
async #transformResult(result, queryId) {
for (const plugin of this.#plugins) {
result = await plugin.transformResult({ result, queryId });
}
return result;
}
}

View File

@@ -0,0 +1,8 @@
import type { QueryExecutor } from './query-executor.js';
/**
* @internal
* @private
*/
export interface QueryExecutorProvider {
getExecutor(): QueryExecutor;
}

View File

@@ -0,0 +1,2 @@
/// <reference types="./query-executor-provider.d.ts" />
export {};

View File

@@ -0,0 +1,74 @@
import type { ConnectionProvider } from '../driver/connection-provider.js';
import type { QueryResult } from '../driver/database-connection.js';
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
import type { RootOperationNode } from '../query-compiler/query-compiler.js';
import type { KyselyPlugin } from '../plugin/kysely-plugin.js';
import type { QueryId } from '../util/query-id.js';
import type { DialectAdapter } from '../dialect/dialect-adapter.js';
/**
* This interface abstracts away the details of how to compile a query into SQL
* and execute it. Instead of passing around all those details, {@link SelectQueryBuilder}
* and other classes that execute queries can just pass around and instance of
* `QueryExecutor`.
*/
export interface QueryExecutor extends ConnectionProvider {
/**
* Returns the adapter for the current dialect.
*/
get adapter(): DialectAdapter;
/**
* Returns all installed plugins.
*/
get plugins(): ReadonlyArray<KyselyPlugin>;
/**
* Given the query the user has built (expressed as an operation node tree)
* this method runs it through all plugins' `transformQuery` methods and
* returns the result.
*/
transformQuery<T extends RootOperationNode>(node: T, queryId: QueryId): T;
/**
* Compiles the transformed query into SQL. You usually want to pass
* the output of {@link transformQuery} into this method but you can
* compile any query using this method.
*/
compileQuery<R = unknown>(node: RootOperationNode, queryId: QueryId): CompiledQuery<R>;
/**
* Executes a compiled query and runs the result through all plugins'
* `transformResult` method.
*/
executeQuery<R>(compiledQuery: CompiledQuery<R>): Promise<QueryResult<R>>;
/**
* Executes a compiled query and runs the result through all plugins'
* `transformResult` method. Results are streamead instead of loaded
* at once.
*/
stream<R>(compiledQuery: CompiledQuery<R>,
/**
* How many rows should be pulled from the database at once. Supported
* only by the postgres driver.
*/
chunkSize: number): AsyncIterableIterator<QueryResult<R>>;
/**
* Returns a copy of this executor with a new connection provider.
*/
withConnectionProvider(connectionProvider: ConnectionProvider): QueryExecutor;
/**
* Returns a copy of this executor with a plugin added as the
* last plugin.
*/
withPlugin(plugin: KyselyPlugin): QueryExecutor;
/**
* Returns a copy of this executor with a list of plugins added
* as the last plugins.
*/
withPlugins(plugin: ReadonlyArray<KyselyPlugin>): QueryExecutor;
/**
* Returns a copy of this executor with a plugin added as the
* first plugin.
*/
withPluginAtFront(plugin: KyselyPlugin): QueryExecutor;
/**
* Returns a copy of this executor without any plugins.
*/
withoutPlugins(): QueryExecutor;
}

View File

@@ -0,0 +1,2 @@
/// <reference types="./query-executor.d.ts" />
export {};