Initial commit - Event Planner application
This commit is contained in:
8
node_modules/kysely/dist/esm/driver/connection-provider.d.ts
generated
vendored
Normal file
8
node_modules/kysely/dist/esm/driver/connection-provider.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import type { DatabaseConnection } from './database-connection.js';
|
||||
export interface ConnectionProvider {
|
||||
/**
|
||||
* 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>;
|
||||
}
|
||||
2
node_modules/kysely/dist/esm/driver/connection-provider.js
generated
vendored
Normal file
2
node_modules/kysely/dist/esm/driver/connection-provider.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/// <reference types="./connection-provider.d.ts" />
|
||||
export {};
|
||||
35
node_modules/kysely/dist/esm/driver/database-connection.d.ts
generated
vendored
Normal file
35
node_modules/kysely/dist/esm/driver/database-connection.d.ts
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
|
||||
/**
|
||||
* A single connection to the database engine.
|
||||
*
|
||||
* These are created by an instance of {@link Driver}.
|
||||
*/
|
||||
export interface DatabaseConnection {
|
||||
executeQuery<R>(compiledQuery: CompiledQuery): Promise<QueryResult<R>>;
|
||||
streamQuery<R>(compiledQuery: CompiledQuery, chunkSize?: number): AsyncIterableIterator<QueryResult<R>>;
|
||||
}
|
||||
export interface QueryResult<O> {
|
||||
/**
|
||||
* This is defined for insert, update, delete and merge queries and contains
|
||||
* the number of rows the query inserted/updated/deleted.
|
||||
*/
|
||||
readonly numAffectedRows?: bigint;
|
||||
/**
|
||||
* This is defined for update queries and contains the number of rows
|
||||
* the query changed.
|
||||
*
|
||||
* This is **optional** and only provided in dialects such as MySQL.
|
||||
* You would probably use {@link numAffectedRows} in most cases.
|
||||
*/
|
||||
readonly numChangedRows?: bigint;
|
||||
/**
|
||||
* This is defined for insert queries on dialects that return
|
||||
* the auto incrementing primary key from an insert.
|
||||
*/
|
||||
readonly insertId?: bigint;
|
||||
/**
|
||||
* The rows returned by the query. This is always defined and is
|
||||
* empty if the query returned no rows.
|
||||
*/
|
||||
readonly rows: O[];
|
||||
}
|
||||
2
node_modules/kysely/dist/esm/driver/database-connection.js
generated
vendored
Normal file
2
node_modules/kysely/dist/esm/driver/database-connection.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/// <reference types="./database-connection.d.ts" />
|
||||
export {};
|
||||
12
node_modules/kysely/dist/esm/driver/default-connection-provider.d.ts
generated
vendored
Normal file
12
node_modules/kysely/dist/esm/driver/default-connection-provider.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import type { DatabaseConnection } from './database-connection.js';
|
||||
import type { ConnectionProvider } from './connection-provider.js';
|
||||
import type { Driver } from './driver.js';
|
||||
export declare class DefaultConnectionProvider implements ConnectionProvider {
|
||||
#private;
|
||||
constructor(driver: Driver);
|
||||
/**
|
||||
* 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>;
|
||||
}
|
||||
16
node_modules/kysely/dist/esm/driver/default-connection-provider.js
generated
vendored
Normal file
16
node_modules/kysely/dist/esm/driver/default-connection-provider.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
/// <reference types="./default-connection-provider.d.ts" />
|
||||
export class DefaultConnectionProvider {
|
||||
#driver;
|
||||
constructor(driver) {
|
||||
this.#driver = driver;
|
||||
}
|
||||
async provideConnection(consumer) {
|
||||
const connection = await this.#driver.acquireConnection();
|
||||
try {
|
||||
return await consumer(connection);
|
||||
}
|
||||
finally {
|
||||
await this.#driver.releaseConnection(connection);
|
||||
}
|
||||
}
|
||||
}
|
||||
61
node_modules/kysely/dist/esm/driver/driver.d.ts
generated
vendored
Normal file
61
node_modules/kysely/dist/esm/driver/driver.d.ts
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
import type { QueryCompiler } from '../query-compiler/query-compiler.js';
|
||||
import type { ArrayItemType } from '../util/type-utils.js';
|
||||
import type { DatabaseConnection } from './database-connection.js';
|
||||
/**
|
||||
* A Driver creates and releases {@link DatabaseConnection | database connections}
|
||||
* and is also responsible for connection pooling (if the dialect supports pooling).
|
||||
*/
|
||||
export interface Driver {
|
||||
/**
|
||||
* Initializes the driver.
|
||||
*
|
||||
* After calling this method the driver should be usable and `acquireConnection` etc.
|
||||
* methods should be callable.
|
||||
*/
|
||||
init(): Promise<void>;
|
||||
/**
|
||||
* Acquires a new connection from the pool.
|
||||
*/
|
||||
acquireConnection(): Promise<DatabaseConnection>;
|
||||
/**
|
||||
* Begins a transaction.
|
||||
*/
|
||||
beginTransaction(connection: DatabaseConnection, settings: TransactionSettings): Promise<void>;
|
||||
/**
|
||||
* Commits a transaction.
|
||||
*/
|
||||
commitTransaction(connection: DatabaseConnection): Promise<void>;
|
||||
/**
|
||||
* Rolls back a transaction.
|
||||
*/
|
||||
rollbackTransaction(connection: DatabaseConnection): Promise<void>;
|
||||
/**
|
||||
* Establishses a new savepoint within a transaction.
|
||||
*/
|
||||
savepoint?(connection: DatabaseConnection, savepointName: string, compileQuery: QueryCompiler['compileQuery']): Promise<void>;
|
||||
/**
|
||||
* Rolls back to a savepoint within a transaction.
|
||||
*/
|
||||
rollbackToSavepoint?(connection: DatabaseConnection, savepointName: string, compileQuery: QueryCompiler['compileQuery']): Promise<void>;
|
||||
/**
|
||||
* Releases a savepoint within a transaction.
|
||||
*/
|
||||
releaseSavepoint?(connection: DatabaseConnection, savepointName: string, compileQuery: QueryCompiler['compileQuery']): Promise<void>;
|
||||
/**
|
||||
* Releases a connection back to the pool.
|
||||
*/
|
||||
releaseConnection(connection: DatabaseConnection): Promise<void>;
|
||||
/**
|
||||
* Destroys the driver and releases all resources.
|
||||
*/
|
||||
destroy(): Promise<void>;
|
||||
}
|
||||
export interface TransactionSettings {
|
||||
readonly accessMode?: AccessMode;
|
||||
readonly isolationLevel?: IsolationLevel;
|
||||
}
|
||||
export declare const TRANSACTION_ACCESS_MODES: readonly ["read only", "read write"];
|
||||
export type AccessMode = ArrayItemType<typeof TRANSACTION_ACCESS_MODES>;
|
||||
export declare const TRANSACTION_ISOLATION_LEVELS: readonly ["read uncommitted", "read committed", "repeatable read", "serializable", "snapshot"];
|
||||
export type IsolationLevel = ArrayItemType<typeof TRANSACTION_ISOLATION_LEVELS>;
|
||||
export declare function validateTransactionSettings(settings: TransactionSettings): void;
|
||||
19
node_modules/kysely/dist/esm/driver/driver.js
generated
vendored
Normal file
19
node_modules/kysely/dist/esm/driver/driver.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
/// <reference types="./driver.d.ts" />
|
||||
export const TRANSACTION_ACCESS_MODES = ['read only', 'read write'];
|
||||
export const TRANSACTION_ISOLATION_LEVELS = [
|
||||
'read uncommitted',
|
||||
'read committed',
|
||||
'repeatable read',
|
||||
'serializable',
|
||||
'snapshot',
|
||||
];
|
||||
export function validateTransactionSettings(settings) {
|
||||
if (settings.accessMode &&
|
||||
!TRANSACTION_ACCESS_MODES.includes(settings.accessMode)) {
|
||||
throw new Error(`invalid transaction access mode ${settings.accessMode}`);
|
||||
}
|
||||
if (settings.isolationLevel &&
|
||||
!TRANSACTION_ISOLATION_LEVELS.includes(settings.isolationLevel)) {
|
||||
throw new Error(`invalid transaction isolation level ${settings.isolationLevel}`);
|
||||
}
|
||||
}
|
||||
75
node_modules/kysely/dist/esm/driver/dummy-driver.d.ts
generated
vendored
Normal file
75
node_modules/kysely/dist/esm/driver/dummy-driver.d.ts
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
import type { DatabaseConnection } from './database-connection.js';
|
||||
import type { Driver } from './driver.js';
|
||||
/**
|
||||
* A driver that does absolutely nothing.
|
||||
*
|
||||
* You can use this to create Kysely instances solely for building queries
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* This example creates a Kysely instance for building postgres queries:
|
||||
*
|
||||
* ```ts
|
||||
* import {
|
||||
* DummyDriver,
|
||||
* Kysely,
|
||||
* PostgresAdapter,
|
||||
* PostgresIntrospector,
|
||||
* PostgresQueryCompiler
|
||||
* } from 'kysely'
|
||||
* import type { Database } from 'type-editor' // imaginary module
|
||||
*
|
||||
* const db = new Kysely<Database>({
|
||||
* dialect: {
|
||||
* createAdapter: () => new PostgresAdapter(),
|
||||
* createDriver: () => new DummyDriver(),
|
||||
* createIntrospector: (db: Kysely<any>) => new PostgresIntrospector(db),
|
||||
* createQueryCompiler: () => new PostgresQueryCompiler(),
|
||||
* },
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* You can use it to build a query and compile it to SQL but trying to
|
||||
* execute the query will throw an error.
|
||||
*
|
||||
* ```ts
|
||||
* const { sql } = db.selectFrom('person').selectAll().compile()
|
||||
* console.log(sql) // select * from "person"
|
||||
* ```
|
||||
*/
|
||||
export declare class DummyDriver implements Driver {
|
||||
/**
|
||||
* Initializes the driver.
|
||||
*
|
||||
* After calling this method the driver should be usable and `acquireConnection` etc.
|
||||
* methods should be callable.
|
||||
*/
|
||||
init(): Promise<void>;
|
||||
/**
|
||||
* Acquires a new connection from the pool.
|
||||
*/
|
||||
acquireConnection(): Promise<DatabaseConnection>;
|
||||
/**
|
||||
* Begins a transaction.
|
||||
*/
|
||||
beginTransaction(): Promise<void>;
|
||||
/**
|
||||
* Commits a transaction.
|
||||
*/
|
||||
commitTransaction(): Promise<void>;
|
||||
/**
|
||||
* Rolls back a transaction.
|
||||
*/
|
||||
rollbackTransaction(): Promise<void>;
|
||||
/**
|
||||
* Releases a connection back to the pool.
|
||||
*/
|
||||
releaseConnection(): Promise<void>;
|
||||
/**
|
||||
* Destroys the driver and releases all resources.
|
||||
*/
|
||||
destroy(): Promise<void>;
|
||||
releaseSavepoint(): Promise<void>;
|
||||
rollbackToSavepoint(): Promise<void>;
|
||||
savepoint(): Promise<void>;
|
||||
}
|
||||
80
node_modules/kysely/dist/esm/driver/dummy-driver.js
generated
vendored
Normal file
80
node_modules/kysely/dist/esm/driver/dummy-driver.js
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
/// <reference types="./dummy-driver.d.ts" />
|
||||
/**
|
||||
* A driver that does absolutely nothing.
|
||||
*
|
||||
* You can use this to create Kysely instances solely for building queries
|
||||
*
|
||||
* ### Examples
|
||||
*
|
||||
* This example creates a Kysely instance for building postgres queries:
|
||||
*
|
||||
* ```ts
|
||||
* import {
|
||||
* DummyDriver,
|
||||
* Kysely,
|
||||
* PostgresAdapter,
|
||||
* PostgresIntrospector,
|
||||
* PostgresQueryCompiler
|
||||
* } from 'kysely'
|
||||
* import type { Database } from 'type-editor' // imaginary module
|
||||
*
|
||||
* const db = new Kysely<Database>({
|
||||
* dialect: {
|
||||
* createAdapter: () => new PostgresAdapter(),
|
||||
* createDriver: () => new DummyDriver(),
|
||||
* createIntrospector: (db: Kysely<any>) => new PostgresIntrospector(db),
|
||||
* createQueryCompiler: () => new PostgresQueryCompiler(),
|
||||
* },
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* You can use it to build a query and compile it to SQL but trying to
|
||||
* execute the query will throw an error.
|
||||
*
|
||||
* ```ts
|
||||
* const { sql } = db.selectFrom('person').selectAll().compile()
|
||||
* console.log(sql) // select * from "person"
|
||||
* ```
|
||||
*/
|
||||
export class DummyDriver {
|
||||
async init() {
|
||||
// Nothing to do here.
|
||||
}
|
||||
async acquireConnection() {
|
||||
return new DummyConnection();
|
||||
}
|
||||
async beginTransaction() {
|
||||
// Nothing to do here.
|
||||
}
|
||||
async commitTransaction() {
|
||||
// Nothing to do here.
|
||||
}
|
||||
async rollbackTransaction() {
|
||||
// Nothing to do here.
|
||||
}
|
||||
async releaseConnection() {
|
||||
// Nothing to do here.
|
||||
}
|
||||
async destroy() {
|
||||
// Nothing to do here.
|
||||
}
|
||||
async releaseSavepoint() {
|
||||
// Nothing to do here.
|
||||
}
|
||||
async rollbackToSavepoint() {
|
||||
// Nothing to do here.
|
||||
}
|
||||
async savepoint() {
|
||||
// Nothing to do here.
|
||||
}
|
||||
}
|
||||
class DummyConnection {
|
||||
async executeQuery() {
|
||||
return {
|
||||
rows: [],
|
||||
};
|
||||
}
|
||||
async *streamQuery() {
|
||||
// Nothing to do here.
|
||||
}
|
||||
}
|
||||
47
node_modules/kysely/dist/esm/driver/runtime-driver.d.ts
generated
vendored
Normal file
47
node_modules/kysely/dist/esm/driver/runtime-driver.d.ts
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
import type { QueryCompiler } from '../query-compiler/query-compiler.js';
|
||||
import type { Log } from '../util/log.js';
|
||||
import type { DatabaseConnection } from './database-connection.js';
|
||||
import type { Driver, TransactionSettings } from './driver.js';
|
||||
/**
|
||||
* A small wrapper around {@link Driver} that makes sure the driver is
|
||||
* initialized before it is used, only initialized and destroyed
|
||||
* once etc.
|
||||
*/
|
||||
export declare class RuntimeDriver implements Driver {
|
||||
#private;
|
||||
constructor(driver: Driver, log: Log);
|
||||
/**
|
||||
* Initializes the driver.
|
||||
*
|
||||
* After calling this method the driver should be usable and `acquireConnection` etc.
|
||||
* methods should be callable.
|
||||
*/
|
||||
init(): Promise<void>;
|
||||
/**
|
||||
* Acquires a new connection from the pool.
|
||||
*/
|
||||
acquireConnection(): Promise<DatabaseConnection>;
|
||||
/**
|
||||
* Releases a connection back to the pool.
|
||||
*/
|
||||
releaseConnection(connection: DatabaseConnection): Promise<void>;
|
||||
/**
|
||||
* Begins a transaction.
|
||||
*/
|
||||
beginTransaction(connection: DatabaseConnection, settings: TransactionSettings): Promise<void>;
|
||||
/**
|
||||
* Commits a transaction.
|
||||
*/
|
||||
commitTransaction(connection: DatabaseConnection): Promise<void>;
|
||||
/**
|
||||
* Rolls back a transaction.
|
||||
*/
|
||||
rollbackTransaction(connection: DatabaseConnection): Promise<void>;
|
||||
savepoint(connection: DatabaseConnection, savepointName: string, compileQuery: QueryCompiler['compileQuery']): Promise<void>;
|
||||
rollbackToSavepoint(connection: DatabaseConnection, savepointName: string, compileQuery: QueryCompiler['compileQuery']): Promise<void>;
|
||||
releaseSavepoint(connection: DatabaseConnection, savepointName: string, compileQuery: QueryCompiler['compileQuery']): Promise<void>;
|
||||
/**
|
||||
* Destroys the driver and releases all resources.
|
||||
*/
|
||||
destroy(): Promise<void>;
|
||||
}
|
||||
162
node_modules/kysely/dist/esm/driver/runtime-driver.js
generated
vendored
Normal file
162
node_modules/kysely/dist/esm/driver/runtime-driver.js
generated
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
/// <reference types="./runtime-driver.d.ts" />
|
||||
import { performanceNow } from '../util/performance-now.js';
|
||||
/**
|
||||
* A small wrapper around {@link Driver} that makes sure the driver is
|
||||
* initialized before it is used, only initialized and destroyed
|
||||
* once etc.
|
||||
*/
|
||||
export class RuntimeDriver {
|
||||
#driver;
|
||||
#log;
|
||||
#initPromise;
|
||||
#initDone;
|
||||
#destroyPromise;
|
||||
#connections = new WeakSet();
|
||||
constructor(driver, log) {
|
||||
this.#initDone = false;
|
||||
this.#driver = driver;
|
||||
this.#log = log;
|
||||
}
|
||||
async init() {
|
||||
if (this.#destroyPromise) {
|
||||
throw new Error('driver has already been destroyed');
|
||||
}
|
||||
if (!this.#initPromise) {
|
||||
this.#initPromise = this.#driver
|
||||
.init()
|
||||
.then(() => {
|
||||
this.#initDone = true;
|
||||
})
|
||||
.catch((err) => {
|
||||
this.#initPromise = undefined;
|
||||
return Promise.reject(err);
|
||||
});
|
||||
}
|
||||
await this.#initPromise;
|
||||
}
|
||||
async acquireConnection() {
|
||||
if (this.#destroyPromise) {
|
||||
throw new Error('driver has already been destroyed');
|
||||
}
|
||||
if (!this.#initDone) {
|
||||
await this.init();
|
||||
}
|
||||
const connection = await this.#driver.acquireConnection();
|
||||
if (!this.#connections.has(connection)) {
|
||||
if (this.#needsLogging()) {
|
||||
this.#addLogging(connection);
|
||||
}
|
||||
this.#connections.add(connection);
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
async releaseConnection(connection) {
|
||||
await this.#driver.releaseConnection(connection);
|
||||
}
|
||||
beginTransaction(connection, settings) {
|
||||
return this.#driver.beginTransaction(connection, settings);
|
||||
}
|
||||
commitTransaction(connection) {
|
||||
return this.#driver.commitTransaction(connection);
|
||||
}
|
||||
rollbackTransaction(connection) {
|
||||
return this.#driver.rollbackTransaction(connection);
|
||||
}
|
||||
savepoint(connection, savepointName, compileQuery) {
|
||||
if (this.#driver.savepoint) {
|
||||
return this.#driver.savepoint(connection, savepointName, compileQuery);
|
||||
}
|
||||
throw new Error('The `savepoint` method is not supported by this driver');
|
||||
}
|
||||
rollbackToSavepoint(connection, savepointName, compileQuery) {
|
||||
if (this.#driver.rollbackToSavepoint) {
|
||||
return this.#driver.rollbackToSavepoint(connection, savepointName, compileQuery);
|
||||
}
|
||||
throw new Error('The `rollbackToSavepoint` method is not supported by this driver');
|
||||
}
|
||||
releaseSavepoint(connection, savepointName, compileQuery) {
|
||||
if (this.#driver.releaseSavepoint) {
|
||||
return this.#driver.releaseSavepoint(connection, savepointName, compileQuery);
|
||||
}
|
||||
throw new Error('The `releaseSavepoint` method is not supported by this driver');
|
||||
}
|
||||
async destroy() {
|
||||
if (!this.#initPromise) {
|
||||
return;
|
||||
}
|
||||
await this.#initPromise;
|
||||
if (!this.#destroyPromise) {
|
||||
this.#destroyPromise = this.#driver.destroy().catch((err) => {
|
||||
this.#destroyPromise = undefined;
|
||||
return Promise.reject(err);
|
||||
});
|
||||
}
|
||||
await this.#destroyPromise;
|
||||
}
|
||||
#needsLogging() {
|
||||
return (this.#log.isLevelEnabled('query') || this.#log.isLevelEnabled('error'));
|
||||
}
|
||||
// This method monkey patches the database connection's executeQuery method
|
||||
// by adding logging code around it. Monkey patching is not pretty, but it's
|
||||
// the best option in this case.
|
||||
#addLogging(connection) {
|
||||
const executeQuery = connection.executeQuery;
|
||||
const streamQuery = connection.streamQuery;
|
||||
const dis = this;
|
||||
connection.executeQuery = async (compiledQuery) => {
|
||||
let caughtError;
|
||||
const startTime = performanceNow();
|
||||
try {
|
||||
return await executeQuery.call(connection, compiledQuery);
|
||||
}
|
||||
catch (error) {
|
||||
caughtError = error;
|
||||
await dis.#logError(error, compiledQuery, startTime);
|
||||
throw error;
|
||||
}
|
||||
finally {
|
||||
if (!caughtError) {
|
||||
await dis.#logQuery(compiledQuery, startTime);
|
||||
}
|
||||
}
|
||||
};
|
||||
connection.streamQuery = async function* (compiledQuery, chunkSize) {
|
||||
let caughtError;
|
||||
const startTime = performanceNow();
|
||||
try {
|
||||
for await (const result of streamQuery.call(connection, compiledQuery, chunkSize)) {
|
||||
yield result;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
caughtError = error;
|
||||
await dis.#logError(error, compiledQuery, startTime);
|
||||
throw error;
|
||||
}
|
||||
finally {
|
||||
if (!caughtError) {
|
||||
await dis.#logQuery(compiledQuery, startTime, true);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
async #logError(error, compiledQuery, startTime) {
|
||||
await this.#log.error(() => ({
|
||||
level: 'error',
|
||||
error,
|
||||
query: compiledQuery,
|
||||
queryDurationMillis: this.#calculateDurationMillis(startTime),
|
||||
}));
|
||||
}
|
||||
async #logQuery(compiledQuery, startTime, isStream = false) {
|
||||
await this.#log.query(() => ({
|
||||
level: 'query',
|
||||
isStream,
|
||||
query: compiledQuery,
|
||||
queryDurationMillis: this.#calculateDurationMillis(startTime),
|
||||
}));
|
||||
}
|
||||
#calculateDurationMillis(startTime) {
|
||||
return performanceNow() - startTime;
|
||||
}
|
||||
}
|
||||
11
node_modules/kysely/dist/esm/driver/single-connection-provider.d.ts
generated
vendored
Normal file
11
node_modules/kysely/dist/esm/driver/single-connection-provider.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import type { DatabaseConnection } from './database-connection.js';
|
||||
import type { ConnectionProvider } from './connection-provider.js';
|
||||
export declare class SingleConnectionProvider implements ConnectionProvider {
|
||||
#private;
|
||||
constructor(connection: DatabaseConnection);
|
||||
/**
|
||||
* 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>;
|
||||
}
|
||||
26
node_modules/kysely/dist/esm/driver/single-connection-provider.js
generated
vendored
Normal file
26
node_modules/kysely/dist/esm/driver/single-connection-provider.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
/// <reference types="./single-connection-provider.d.ts" />
|
||||
const ignoreError = () => { };
|
||||
export class SingleConnectionProvider {
|
||||
#connection;
|
||||
#runningPromise;
|
||||
constructor(connection) {
|
||||
this.#connection = connection;
|
||||
}
|
||||
async provideConnection(consumer) {
|
||||
while (this.#runningPromise) {
|
||||
await this.#runningPromise.catch(ignoreError);
|
||||
}
|
||||
// `#runningPromise` must be set to undefined before it's
|
||||
// resolved or rejected. Otherwise the while loop above
|
||||
// will misbehave.
|
||||
this.#runningPromise = this.#run(consumer).finally(() => {
|
||||
this.#runningPromise = undefined;
|
||||
});
|
||||
return this.#runningPromise;
|
||||
}
|
||||
// Run the runner in an async function to make sure it doesn't
|
||||
// throw synchronous errors.
|
||||
async #run(runner) {
|
||||
return await runner(this.#connection);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user