feat: add sqlstring and supports-color modules

- Introduced sqlstring module for SQL escape and formatting.
- Added supports-color module to detect terminal color support.
- Created dashboard and login views with Bootstrap styling.
- Implemented user schema in SQL with mock data for testing.
This commit is contained in:
2025-06-20 22:57:32 +02:00
parent b6f72d059d
commit 63d120cc4e
479 changed files with 75965 additions and 11 deletions

View File

@@ -0,0 +1,30 @@
import { RsaPublicKey, RsaPrivateKey, KeyLike } from 'crypto';
import { Connection } from './Connection.js';
export type AuthPlugin = (pluginMetadata: {
connection: Connection;
command: string;
}) => (
pluginData: Buffer
) => Promise<string> | string | Buffer | Promise<Buffer> | null;
type AuthPluginDefinition<T> = (pluginOptions?: T) => AuthPlugin;
export const authPlugins: {
caching_sha2_password: AuthPluginDefinition<{
overrideIsSecure?: boolean;
serverPublicKey?: RsaPublicKey | RsaPrivateKey | KeyLike;
onServerPublicKey?: (data: Buffer) => void;
}>;
mysql_clear_password: AuthPluginDefinition<{
password?: string;
}>;
mysql_native_password: AuthPluginDefinition<{
password?: string;
passwordSha1?: string;
}>;
sha256_password: AuthPluginDefinition<{
serverPublicKey?: RsaPublicKey | RsaPrivateKey | KeyLike;
onServerPublicKey?: (data: Buffer) => void;
}>;
};

View File

@@ -0,0 +1,428 @@
// This file was modified by Oracle on November 04, 2021.
// Type definitions and corresponding descriptions were introduced for the
// connection options relevant for multifactor authentication.
// Modifications copyright (c) 2021, Oracle and/or its affiliates.
import { EventEmitter } from 'events';
import { Readable } from 'stream';
import { Query, QueryError } from './protocol/sequences/Query.js';
import { Prepare, PrepareStatementInfo } from './protocol/sequences/Prepare.js';
import {
OkPacket,
FieldPacket,
RowDataPacket,
ResultSetHeader,
OkPacketParams,
ErrorPacketParams,
} from './protocol/packets/index.js';
import { Connection as PromiseConnection } from '../../../promise.js';
import { AuthPlugin } from './Auth.js';
import { QueryableBase } from './protocol/sequences/QueryableBase.js';
import { ExecutableBase } from './protocol/sequences/ExecutableBase.js';
import { TypeCast } from './parsers/typeCast.js';
export interface SslOptions {
/**
* A string or buffer holding the PFX or PKCS12 encoded private key, certificate and CA certificates
*/
pfx?: string;
/**
* Either a string/buffer or list of strings/Buffers holding the PEM encoded private key(s) to use
*/
key?: string | string[] | Buffer | Buffer[];
/**
* A string of passphrase for the private key or pfx
*/
passphrase?: string;
/**
* A string/buffer or list of strings/Buffers holding the PEM encoded certificate(s)
*/
cert?: string | string[] | Buffer | Buffer[];
/**
* Either a string/Buffer or list of strings/Buffers of PEM encoded CA certificates to trust.
*/
ca?: string | string[] | Buffer | Buffer[];
/**
* Either a string or list of strings of PEM encoded CRLs (Certificate Revocation List)
*/
crl?: string | string[];
/**
* A string describing the ciphers to use or exclude
*/
ciphers?: string;
/**
* You can also connect to a MySQL server without properly providing the appropriate CA to trust. You should not do this.
*/
rejectUnauthorized?: boolean;
/**
* Configure the minimum supported version of SSL, the default is TLSv1.2.
*/
minVersion?: string;
/**
* Configure the maximum supported version of SSL, the default is TLSv1.3.
*/
maxVersion?: string;
/**
* You can verify the server name identity presented on the server certificate when connecting to a MySQL server.
* You should enable this but it is disabled by default right now for backwards compatibility.
*/
verifyIdentity?: boolean;
}
export interface ConnectionOptions {
/**
* DECIMAL and NEWDECIMAL types will be returned as numbers if this option is set to `true` ( default: `false`).
*/
decimalNumbers?: boolean;
/**
* The MySQL user to authenticate as
*/
user?: string;
/**
* The password of that MySQL user
*/
password?: string;
/**
* Alias for the MySQL user password. Makes a bit more sense in a multifactor authentication setup (see
* "password2" and "password3")
*/
password1?: string;
/**
* 2nd factor authentication password. Mandatory when the authentication policy for the MySQL user account
* requires an additional authentication method that needs a password.
* https://dev.mysql.com/doc/refman/8.0/en/multifactor-authentication.html
*/
password2?: string;
/**
* 3rd factor authentication password. Mandatory when the authentication policy for the MySQL user account
* requires two additional authentication methods and the last one needs a password.
* https://dev.mysql.com/doc/refman/8.0/en/multifactor-authentication.html
*/
password3?: string;
/**
* Name of the database to use for this connection
*/
database?: string;
/**
* The charset for the connection. This is called 'collation' in the SQL-level of MySQL (like utf8_general_ci).
* If a SQL-level charset is specified (like utf8mb4) then the default collation for that charset is used.
* (Default: 'UTF8_GENERAL_CI')
*/
charset?: string;
/**
* The hostname of the database you are connecting to. (Default: localhost)
*/
host?: string;
/**
* The port number to connect to. (Default: 3306)
*/
port?: number;
/**
* The source IP address to use for TCP connection
*/
localAddress?: string;
/**
* The path to a unix domain socket to connect to. When used host and port are ignored
*/
socketPath?: string;
/**
* The timezone used to store local dates. (Default: 'local')
*/
timezone?: string | 'local';
/**
* The milliseconds before a timeout occurs during the initial connection to the MySQL server. (Default: 10 seconds)
*/
connectTimeout?: number;
/**
* Stringify objects instead of converting to values. (Default: 'false')
*/
stringifyObjects?: boolean;
/**
* Allow connecting to MySQL instances that ask for the old (insecure) authentication method. (Default: false)
*/
insecureAuth?: boolean;
/**
* By specifying a function that returns a readable stream, an arbitrary stream can be sent when sending a local fs file.
*/
infileStreamFactory?: (path: string) => Readable;
/**
* Determines if column values should be converted to native JavaScript types.
*
* @default true
*
* It is not recommended (and may go away / change in the future) to disable type casting, but you can currently do so on either the connection or query level.
*
* ---
*
* You can also specify a function to do the type casting yourself:
* ```ts
* (field: Field, next: () => unknown) => {
* return next();
* }
* ```
*
* ---
*
* **WARNING:**
*
* YOU MUST INVOKE the parser using one of these three field functions in your custom typeCast callback. They can only be called once:
*
* ```js
* field.string();
* field.buffer();
* field.geometry();
* ```
* Which are aliases for:
*
* ```js
* parser.parseLengthCodedString();
* parser.parseLengthCodedBuffer();
* parser.parseGeometryValue();
* ```
*
* You can find which field function you need to use by looking at `RowDataPacket.prototype._typeCast`.
*/
typeCast?: TypeCast;
/**
* A custom query format function
*/
queryFormat?: (query: string, values: any) => void;
/**
* When dealing with big numbers (BIGINT and DECIMAL columns) in the database, you should enable this option
* (Default: false)
*/
supportBigNumbers?: boolean;
/**
* Enabling both supportBigNumbers and bigNumberStrings forces big numbers (BIGINT and DECIMAL columns) to be
* always returned as JavaScript String objects (Default: false). Enabling supportBigNumbers but leaving
* bigNumberStrings disabled will return big numbers as String objects only when they cannot be accurately
* represented with [JavaScript Number objects](https://262.ecma-international.org/5.1/#sec-8.5)
* (which happens when they exceed the [-2^53, +2^53] range), otherwise they will be returned as Number objects.
* This option is ignored if supportBigNumbers is disabled.
*/
bigNumberStrings?: boolean;
/**
* Force date types (TIMESTAMP, DATETIME, DATE) to be returned as strings rather then inflated into JavaScript Date
* objects. Can be true/false or an array of type names to keep as strings.
*
* (Default: false)
*/
dateStrings?: boolean | Array<'TIMESTAMP' | 'DATETIME' | 'DATE'>;
/**
* This will print all incoming and outgoing packets on stdout.
* You can also restrict debugging to packet types by passing an array of types (strings) to debug;
*
* (Default: false)
*/
debug?: any;
/**
* Generates stack traces on Error to include call site of library entrance ('long stack traces'). Slight
* performance penalty for most calls. (Default: true)
*/
trace?: boolean;
/**
* Allow multiple mysql statements per query. Be careful with this, it exposes you to SQL injection attacks. (Default: false)
*/
multipleStatements?: boolean;
/**
* List of connection flags to use other than the default ones. It is also possible to blacklist default ones
*/
flags?: Array<string>;
/**
* object with ssl parameters or a string containing name of ssl profile
*/
ssl?: string | SslOptions;
/**
* Return each row as an array, not as an object.
* This is useful when you have duplicate column names.
* This can also be set in the `QueryOption` object to be applied per-query.
*/
rowsAsArray?: boolean;
/**
* Enable keep-alive on the socket. (Default: true)
*/
enableKeepAlive?: boolean;
/**
* If keep-alive is enabled users can supply an initial delay. (Default: 0)
*/
keepAliveInitialDelay?: number;
charsetNumber?: number;
compress?: boolean;
authSwitchHandler?: (data: any, callback: () => void) => any;
connectAttributes?: { [param: string]: any };
isServer?: boolean;
maxPreparedStatements?: number;
namedPlaceholders?: boolean;
nestTables?: boolean | string;
passwordSha1?: string;
pool?: any;
stream?: any;
uri?: string;
connectionLimit?: number;
maxIdle?: number;
idleTimeout?: number;
Promise?: any;
queueLimit?: number;
waitForConnections?: boolean;
disableEval?: boolean;
authPlugins?: {
[key: string]: AuthPlugin;
};
/**
* Force JSON to be returned as string
*
* (Default: false)
*/
jsonStrings?: boolean;
}
declare class Connection extends QueryableBase(ExecutableBase(EventEmitter)) {
config: ConnectionOptions;
threadId: number;
authorized: boolean;
static createQuery<
T extends
| RowDataPacket[][]
| RowDataPacket[]
| OkPacket
| OkPacket[]
| ResultSetHeader,
>(
sql: string,
callback?: (err: QueryError | null, result: T, fields: FieldPacket[]) => any
): Query;
static createQuery<
T extends
| RowDataPacket[][]
| RowDataPacket[]
| OkPacket
| OkPacket[]
| ResultSetHeader,
>(
sql: string,
values: any | any[] | { [param: string]: any },
callback?: (err: QueryError | null, result: T, fields: FieldPacket[]) => any
): Query;
beginTransaction(callback: (err: QueryError | null) => void): void;
connect(callback?: (err: QueryError | null) => void): void;
commit(callback?: (err: QueryError | null) => void): void;
changeUser(
options: ConnectionOptions,
callback?: (err: QueryError | null) => void
): void;
end(callback?: (err: QueryError | null) => void): void;
end(options: any, callback?: (err: QueryError | null) => void): void;
destroy(): void;
pause(): void;
resume(): void;
escape(value: any): string;
escapeId(value: string): string;
escapeId(values: string[]): string;
format(sql: string, values?: any | any[] | { [param: string]: any }): string;
on(event: string, listener: (...args: any[]) => void): this;
rollback(callback: (err: QueryError | null) => void): void;
prepare(
sql: string,
callback?: (err: QueryError | null, statement: PrepareStatementInfo) => any
): Prepare;
unprepare(sql: string): PrepareStatementInfo;
serverHandshake(args: any): any;
promise(promiseImpl?: PromiseConstructor): PromiseConnection;
ping(callback?: (err: QueryError | null) => any): void;
writeOk(args?: OkPacketParams): void;
writeError(args?: ErrorPacketParams): void;
writeEof(warnings?: number, statusFlags?: number): void;
writeTextResult(rows?: Array<any>, columns?: Array<any>): void;
writePacket(packet: any): void;
sequenceId: number;
}
export { Connection };

View File

@@ -0,0 +1,69 @@
import { EventEmitter } from 'events';
import { PrepareStatementInfo } from './protocol/sequences/Prepare.js';
import { ConnectionOptions } from './Connection.js';
import { PoolConnection } from './PoolConnection.js';
import {
Pool as PromisePool,
PoolConnection as PromisePoolConnection,
} from '../../../promise.js';
import { QueryableBase } from './protocol/sequences/QueryableBase.js';
import { ExecutableBase } from './protocol/sequences/ExecutableBase.js';
export interface PoolOptions extends ConnectionOptions {
/**
* Determines the pool's action when no connections are available and the limit has been reached. If true, the pool will queue
* the connection request and call it when one becomes available. If false, the pool will immediately call back with an error.
* (Default: true)
*/
waitForConnections?: boolean;
/**
* The maximum number of connections to create at once. (Default: 10)
*/
connectionLimit?: number;
/**
* The maximum number of idle connections. (Default: same as `connectionLimit`)
*/
maxIdle?: number;
/**
* The idle connections timeout, in milliseconds. (Default: 60000)
*/
idleTimeout?: number;
/**
* The maximum number of connection requests the pool will queue before returning an error from getConnection. If set to 0, there
* is no limit to the number of queued connection requests. (Default: 0)
*/
queueLimit?: number;
}
declare class Pool extends QueryableBase(ExecutableBase(EventEmitter)) {
getConnection(
callback: (
err: NodeJS.ErrnoException | null,
connection: PoolConnection
) => any
): void;
releaseConnection(connection: PoolConnection | PromisePoolConnection): void;
end(
callback?: (err: NodeJS.ErrnoException | null, ...args: any[]) => any
): void;
on(event: string, listener: (...args: any[]) => void): this;
on(event: 'connection', listener: (connection: PoolConnection) => any): this;
on(event: 'acquire', listener: (connection: PoolConnection) => any): this;
on(event: 'release', listener: (connection: PoolConnection) => any): this;
on(event: 'enqueue', listener: () => any): this;
unprepare(sql: string): PrepareStatementInfo;
promise(promiseImpl?: PromiseConstructor): PromisePool;
config: PoolOptions;
}
export { Pool };

View File

@@ -0,0 +1,90 @@
import { EventEmitter } from 'events';
import { PoolConnection } from './PoolConnection.js';
import { PoolOptions } from './Pool.js';
import { ExecutableBase as ExecutableBaseClass } from './protocol/sequences/ExecutableBase.js';
import { QueryableBase as QueryableBaseClass } from './protocol/sequences/QueryableBase.js';
// Expose class interfaces
declare class QueryableAndExecutableBase extends QueryableBaseClass(
ExecutableBaseClass(EventEmitter)
) {}
export interface PoolClusterOptions {
/**
* If true, PoolCluster will attempt to reconnect when connection fails. (Default: true)
*/
canRetry?: boolean;
/**
* If connection fails, node's errorCount increases. When errorCount is greater than removeNodeErrorCount,
* remove a node in the PoolCluster. (Default: 5)
*/
removeNodeErrorCount?: number;
/**
* If connection fails, specifies the number of milliseconds before another connection attempt will be made.
* If set to 0, then node will be removed instead and never re-used. (Default: 0)
*/
restoreNodeTimeout?: number;
/**
* The default selector. (Default: RR)
* RR: Select one alternately. (Round-Robin)
* RANDOM: Select the node by random function.
* ORDER: Select the first node available unconditionally.
*/
defaultSelector?: string;
}
export interface PoolNamespace extends QueryableAndExecutableBase {
getConnection(
callback: (
err: NodeJS.ErrnoException | null,
connection: PoolConnection
) => any
): void;
}
declare class PoolCluster extends EventEmitter {
config: PoolClusterOptions;
add(config: PoolOptions): void;
add(group: string, connectionUri: string): void;
add(group: string, config: PoolOptions): void;
remove(pattern: string): void;
end(): void;
getConnection(
callback: (
err: NodeJS.ErrnoException | null,
connection: PoolConnection
) => void
): void;
getConnection(
group: string,
callback: (
err: NodeJS.ErrnoException | null,
connection: PoolConnection
) => void
): void;
getConnection(
group: string,
selector: string,
callback: (
err: NodeJS.ErrnoException | null,
connection: PoolConnection
) => void
): void;
of(pattern: string, selector?: string): PoolNamespace;
on(event: string, listener: (...args: any[]) => void): this;
on(event: 'online', listener: (nodeId: number) => void): this;
on(event: 'offline', listener: (nodeId: number) => void): this;
on(event: 'remove', listener: (nodeId: number) => void): this;
on(event: 'warn', listener: (err: Error) => void): this;
}
export { PoolCluster };

View File

@@ -0,0 +1,10 @@
import { Connection } from './Connection.js';
import { Pool as PromisePool } from '../../../promise.js';
declare class PoolConnection extends Connection {
connection: Connection;
release(): void;
promise(promiseImpl?: PromiseConstructor): PromisePool;
}
export { PoolConnection };

View File

@@ -0,0 +1,11 @@
import { EventEmitter } from 'events';
import { Connection } from './Connection.js';
declare class Server extends EventEmitter {
connections: Array<Connection>;
listen(port: number): Server;
close(callback: (error: Error, count: number) => any): void;
}
export { Server };

View File

@@ -0,0 +1,8 @@
/**
* Constant `CharsetToEncoding`.
*
* Please note that `CharsetToEncoding` can only be accessed from the `mysql` object and not imported directly.
*/
declare const CharsetToEncoding: string[];
export { CharsetToEncoding };

View File

@@ -0,0 +1,326 @@
interface Charsets {
BIG5_CHINESE_CI: number;
LATIN2_CZECH_CS: number;
DEC8_SWEDISH_CI: number;
CP850_GENERAL_CI: number;
LATIN1_GERMAN1_CI: number;
HP8_ENGLISH_CI: number;
KOI8R_GENERAL_CI: number;
LATIN1_SWEDISH_CI: number;
LATIN2_GENERAL_CI: number;
SWE7_SWEDISH_CI: number;
ASCII_GENERAL_CI: number;
UJIS_JAPANESE_CI: number;
SJIS_JAPANESE_CI: number;
CP1251_BULGARIAN_CI: number;
LATIN1_DANISH_CI: number;
HEBREW_GENERAL_CI: number;
TIS620_THAI_CI: number;
EUCKR_KOREAN_CI: number;
LATIN7_ESTONIAN_CS: number;
LATIN2_HUNGARIAN_CI: number;
KOI8U_GENERAL_CI: number;
CP1251_UKRAINIAN_CI: number;
GB2312_CHINESE_CI: number;
GREEK_GENERAL_CI: number;
CP1250_GENERAL_CI: number;
LATIN2_CROATIAN_CI: number;
GBK_CHINESE_CI: number;
CP1257_LITHUANIAN_CI: number;
LATIN5_TURKISH_CI: number;
LATIN1_GERMAN2_CI: number;
ARMSCII8_GENERAL_CI: number;
UTF8_GENERAL_CI: number;
CP1250_CZECH_CS: number;
UCS2_GENERAL_CI: number;
CP866_GENERAL_CI: number;
KEYBCS2_GENERAL_CI: number;
MACCE_GENERAL_CI: number;
MACROMAN_GENERAL_CI: number;
CP852_GENERAL_CI: number;
LATIN7_GENERAL_CI: number;
LATIN7_GENERAL_CS: number;
MACCE_BIN: number;
CP1250_CROATIAN_CI: number;
UTF8MB4_GENERAL_CI: number;
UTF8MB4_BIN: number;
LATIN1_BIN: number;
LATIN1_GENERAL_CI: number;
LATIN1_GENERAL_CS: number;
CP1251_BIN: number;
CP1251_GENERAL_CI: number;
CP1251_GENERAL_CS: number;
MACROMAN_BIN: number;
UTF16_GENERAL_CI: number;
UTF16_BIN: number;
UTF16LE_GENERAL_CI: number;
CP1256_GENERAL_CI: number;
CP1257_BIN: number;
CP1257_GENERAL_CI: number;
UTF32_GENERAL_CI: number;
UTF32_BIN: number;
UTF16LE_BIN: number;
BINARY: number;
ARMSCII8_BIN: number;
ASCII_BIN: number;
CP1250_BIN: number;
CP1256_BIN: number;
CP866_BIN: number;
DEC8_BIN: number;
GREEK_BIN: number;
HEBREW_BIN: number;
HP8_BIN: number;
KEYBCS2_BIN: number;
KOI8R_BIN: number;
KOI8U_BIN: number;
UTF8_TOLOWER_CI: number;
LATIN2_BIN: number;
LATIN5_BIN: number;
LATIN7_BIN: number;
CP850_BIN: number;
CP852_BIN: number;
SWE7_BIN: number;
UTF8_BIN: number;
BIG5_BIN: number;
EUCKR_BIN: number;
GB2312_BIN: number;
GBK_BIN: number;
SJIS_BIN: number;
TIS620_BIN: number;
UCS2_BIN: number;
UJIS_BIN: number;
GEOSTD8_GENERAL_CI: number;
GEOSTD8_BIN: number;
LATIN1_SPANISH_CI: number;
CP932_JAPANESE_CI: number;
CP932_BIN: number;
EUCJPMS_JAPANESE_CI: number;
EUCJPMS_BIN: number;
CP1250_POLISH_CI: number;
UTF16_UNICODE_CI: number;
UTF16_ICELANDIC_CI: number;
UTF16_LATVIAN_CI: number;
UTF16_ROMANIAN_CI: number;
UTF16_SLOVENIAN_CI: number;
UTF16_POLISH_CI: number;
UTF16_ESTONIAN_CI: number;
UTF16_SPANISH_CI: number;
UTF16_SWEDISH_CI: number;
UTF16_TURKISH_CI: number;
UTF16_CZECH_CI: number;
UTF16_DANISH_CI: number;
UTF16_LITHUANIAN_CI: number;
UTF16_SLOVAK_CI: number;
UTF16_SPANISH2_CI: number;
UTF16_ROMAN_CI: number;
UTF16_PERSIAN_CI: number;
UTF16_ESPERANTO_CI: number;
UTF16_HUNGARIAN_CI: number;
UTF16_SINHALA_CI: number;
UTF16_GERMAN2_CI: number;
UTF16_CROATIAN_CI: number;
UTF16_UNICODE_520_CI: number;
UTF16_VIETNAMESE_CI: number;
UCS2_UNICODE_CI: number;
UCS2_ICELANDIC_CI: number;
UCS2_LATVIAN_CI: number;
UCS2_ROMANIAN_CI: number;
UCS2_SLOVENIAN_CI: number;
UCS2_POLISH_CI: number;
UCS2_ESTONIAN_CI: number;
UCS2_SPANISH_CI: number;
UCS2_SWEDISH_CI: number;
UCS2_TURKISH_CI: number;
UCS2_CZECH_CI: number;
UCS2_DANISH_CI: number;
UCS2_LITHUANIAN_CI: number;
UCS2_SLOVAK_CI: number;
UCS2_SPANISH2_CI: number;
UCS2_ROMAN_CI: number;
UCS2_PERSIAN_CI: number;
UCS2_ESPERANTO_CI: number;
UCS2_HUNGARIAN_CI: number;
UCS2_SINHALA_CI: number;
UCS2_GERMAN2_CI: number;
UCS2_CROATIAN_CI: number;
UCS2_UNICODE_520_CI: number;
UCS2_VIETNAMESE_CI: number;
UCS2_GENERAL_MYSQL500_CI: number;
UTF32_UNICODE_CI: number;
UTF32_ICELANDIC_CI: number;
UTF32_LATVIAN_CI: number;
UTF32_ROMANIAN_CI: number;
UTF32_SLOVENIAN_CI: number;
UTF32_POLISH_CI: number;
UTF32_ESTONIAN_CI: number;
UTF32_SPANISH_CI: number;
UTF32_SWEDISH_CI: number;
UTF32_TURKISH_CI: number;
UTF32_CZECH_CI: number;
UTF32_DANISH_CI: number;
UTF32_LITHUANIAN_CI: number;
UTF32_SLOVAK_CI: number;
UTF32_SPANISH2_CI: number;
UTF32_ROMAN_CI: number;
UTF32_PERSIAN_CI: number;
UTF32_ESPERANTO_CI: number;
UTF32_HUNGARIAN_CI: number;
UTF32_SINHALA_CI: number;
UTF32_GERMAN2_CI: number;
UTF32_CROATIAN_CI: number;
UTF32_UNICODE_520_CI: number;
UTF32_VIETNAMESE_CI: number;
UTF8_UNICODE_CI: number;
UTF8_ICELANDIC_CI: number;
UTF8_LATVIAN_CI: number;
UTF8_ROMANIAN_CI: number;
UTF8_SLOVENIAN_CI: number;
UTF8_POLISH_CI: number;
UTF8_ESTONIAN_CI: number;
UTF8_SPANISH_CI: number;
UTF8_SWEDISH_CI: number;
UTF8_TURKISH_CI: number;
UTF8_CZECH_CI: number;
UTF8_DANISH_CI: number;
UTF8_LITHUANIAN_CI: number;
UTF8_SLOVAK_CI: number;
UTF8_SPANISH2_CI: number;
UTF8_ROMAN_CI: number;
UTF8_PERSIAN_CI: number;
UTF8_ESPERANTO_CI: number;
UTF8_HUNGARIAN_CI: number;
UTF8_SINHALA_CI: number;
UTF8_GERMAN2_CI: number;
UTF8_CROATIAN_CI: number;
UTF8_UNICODE_520_CI: number;
UTF8_VIETNAMESE_CI: number;
UTF8_GENERAL_MYSQL500_CI: number;
UTF8MB4_UNICODE_CI: number;
UTF8MB4_ICELANDIC_CI: number;
UTF8MB4_LATVIAN_CI: number;
UTF8MB4_ROMANIAN_CI: number;
UTF8MB4_SLOVENIAN_CI: number;
UTF8MB4_POLISH_CI: number;
UTF8MB4_ESTONIAN_CI: number;
UTF8MB4_SPANISH_CI: number;
UTF8MB4_SWEDISH_CI: number;
UTF8MB4_TURKISH_CI: number;
UTF8MB4_CZECH_CI: number;
UTF8MB4_DANISH_CI: number;
UTF8MB4_LITHUANIAN_CI: number;
UTF8MB4_SLOVAK_CI: number;
UTF8MB4_SPANISH2_CI: number;
UTF8MB4_ROMAN_CI: number;
UTF8MB4_PERSIAN_CI: number;
UTF8MB4_ESPERANTO_CI: number;
UTF8MB4_HUNGARIAN_CI: number;
UTF8MB4_SINHALA_CI: number;
UTF8MB4_GERMAN2_CI: number;
UTF8MB4_CROATIAN_CI: number;
UTF8MB4_UNICODE_520_CI: number;
UTF8MB4_VIETNAMESE_CI: number;
GB18030_CHINESE_CI: number;
GB18030_BIN: number;
GB18030_UNICODE_520_CI: number;
/** @deprecated */
UTF8_GENERAL50_CI: number;
UTF8MB4_0900_AI_CI: number;
UTF8MB4_DE_PB_0900_AI_CI: number;
UTF8MB4_IS_0900_AI_CI: number;
UTF8MB4_LV_0900_AI_CI: number;
UTF8MB4_RO_0900_AI_CI: number;
UTF8MB4_SL_0900_AI_CI: number;
UTF8MB4_PL_0900_AI_CI: number;
UTF8MB4_ET_0900_AI_CI: number;
UTF8MB4_ES_0900_AI_CI: number;
UTF8MB4_SV_0900_AI_CI: number;
UTF8MB4_TR_0900_AI_CI: number;
UTF8MB4_CS_0900_AI_CI: number;
UTF8MB4_DA_0900_AI_CI: number;
UTF8MB4_LT_0900_AI_CI: number;
UTF8MB4_SK_0900_AI_CI: number;
UTF8MB4_ES_TRAD_0900_AI_CI: number;
UTF8MB4_LA_0900_AI_CI: number;
UTF8MB4_EO_0900_AI_CI: number;
UTF8MB4_HU_0900_AI_CI: number;
UTF8MB4_HR_0900_AI_CI: number;
UTF8MB4_VI_0900_AI_CI: number;
UTF8MB4_0900_AS_CS: number;
UTF8MB4_DE_PB_0900_AS_CS: number;
UTF8MB4_IS_0900_AS_CS: number;
UTF8MB4_LV_0900_AS_CS: number;
UTF8MB4_RO_0900_AS_CS: number;
UTF8MB4_SL_0900_AS_CS: number;
UTF8MB4_PL_0900_AS_CS: number;
UTF8MB4_ET_0900_AS_CS: number;
UTF8MB4_ES_0900_AS_CS: number;
UTF8MB4_SV_0900_AS_CS: number;
UTF8MB4_TR_0900_AS_CS: number;
UTF8MB4_CS_0900_AS_CS: number;
UTF8MB4_DA_0900_AS_CS: number;
UTF8MB4_LT_0900_AS_CS: number;
UTF8MB4_SK_0900_AS_CS: number;
UTF8MB4_ES_TRAD_0900_AS_CS: number;
UTF8MB4_LA_0900_AS_CS: number;
UTF8MB4_EO_0900_AS_CS: number;
UTF8MB4_HU_0900_AS_CS: number;
UTF8MB4_HR_0900_AS_CS: number;
UTF8MB4_VI_0900_AS_CS: number;
UTF8MB4_JA_0900_AS_CS: number;
UTF8MB4_JA_0900_AS_CS_KS: number;
UTF8MB4_0900_AS_CI: number;
UTF8MB4_RU_0900_AI_CI: number;
UTF8MB4_RU_0900_AS_CS: number;
UTF8MB4_ZH_0900_AS_CS: number;
UTF8MB4_0900_BIN: number;
BIG5: number;
DEC8: number;
CP850: number;
HP8: number;
KOI8R: number;
LATIN1: number;
LATIN2: number;
SWE7: number;
ASCII: number;
UJIS: number;
SJIS: number;
HEBREW: number;
TIS620: number;
EUCKR: number;
KOI8U: number;
GB2312: number;
GREEK: number;
CP1250: number;
GBK: number;
LATIN5: number;
ARMSCII8: number;
UTF8: number;
UCS2: number;
CP866: number;
KEYBCS2: number;
MACCE: number;
MACROMAN: number;
CP852: number;
LATIN7: number;
UTF8MB4: number;
CP1251: number;
UTF16: number;
UTF16LE: number;
CP1256: number;
CP1257: number;
UTF32: number;
CP932: number;
EUCJPMS: number;
GB18030: number;
GEOSTD8: number;
}
/**
* Constant `Charsets`.
*
* Please note that `Charsets` can only be accessed from the `mysql` object and not imported directly.
*/
declare const Charsets: Charsets;
export { Charsets };

View File

@@ -0,0 +1,70 @@
interface Types {
0x00: string;
0x01: string;
0x02: string;
0x03: string;
0x04: string;
0x05: string;
0x06: string;
0x07: string;
0x08: string;
0x09: string;
0x0a: string;
0x0b: string;
0x0c: string;
0x0d: string;
0x0e: string;
0x0f: string;
0x10: string;
0xf2: string;
0xf5: string;
0xf6: string;
0xf7: string;
0xf8: string;
0xf9: string;
0xfa: string;
0xfb: string;
0xfc: string;
0xfd: string;
0xfe: string;
0xff: string;
DECIMAL: number;
TINY: number;
SHORT: number;
LONG: number;
FLOAT: number;
DOUBLE: number;
NULL: number;
TIMESTAMP: number;
LONGLONG: number;
INT24: number;
DATE: number;
TIME: number;
DATETIME: number;
YEAR: number;
NEWDATE: number;
VARCHAR: number;
BIT: number;
VECTOR: number;
JSON: number;
NEWDECIMAL: number;
ENUM: number;
SET: number;
TINY_BLOB: number;
MEDIUM_BLOB: number;
LONG_BLOB: number;
BLOB: number;
VAR_STRING: number;
STRING: number;
GEOMETRY: number;
}
/**
* Constant `Types`.
*
* Please note that `Types` can only be accessed from the `mysql` object and not imported directly.
*/
declare const Types: Types;
export { Types };

View File

@@ -0,0 +1,5 @@
import { Types } from './Types.js';
import { Charsets } from './Charsets.js';
import { CharsetToEncoding } from './CharsetToEncoding.js';
export { Types, Charsets, CharsetToEncoding };

View File

@@ -0,0 +1,4 @@
declare function setMaxParserCache(max: number): void;
declare function clearParserCache(): void;
export { setMaxParserCache, clearParserCache };

View File

@@ -0,0 +1,18 @@
import { setMaxParserCache, clearParserCache } from './ParserCache.js';
import {
TypeCast,
Field as TypeCastField,
Geometry as TypeCastGeometry,
Next as TypeCastNext,
Type as TypeCastType,
} from './typeCast.js';
export {
setMaxParserCache,
clearParserCache,
TypeCast,
TypeCastField,
TypeCastGeometry,
TypeCastNext,
TypeCastType,
};

View File

@@ -0,0 +1,54 @@
export type Geometry = {
x: number;
y: number;
};
export type Type = {
type:
| 'DECIMAL'
| 'TINY'
| 'SHORT'
| 'LONG'
| 'FLOAT'
| 'DOUBLE'
| 'NULL'
| 'TIMESTAMP'
| 'TIMESTAMP2'
| 'LONGLONG'
| 'INT24'
| 'DATE'
| 'TIME'
| 'TIME2'
| 'DATETIME'
| 'DATETIME2'
| 'YEAR'
| 'NEWDATE'
| 'VARCHAR'
| 'BIT'
| 'VECTOR'
| 'JSON'
| 'NEWDECIMAL'
| 'ENUM'
| 'SET'
| 'TINY_BLOB'
| 'MEDIUM_BLOB'
| 'LONG_BLOB'
| 'BLOB'
| 'VAR_STRING'
| 'STRING'
| 'GEOMETRY';
};
export type Field = Type & {
length: number;
db: string;
table: string;
name: string;
string: (encoding?: BufferEncoding | string | undefined) => string | null;
buffer: () => Buffer | null;
geometry: () => Geometry | Geometry[] | null;
};
export type Next = () => unknown;
export type TypeCast = ((field: Field, next: Next) => any) | boolean;

View File

@@ -0,0 +1,10 @@
// TODO (major version): remove workaround for `Field` compatibility.
import { TypeCastField } from '../../../lib/parsers/index.js';
/**
* @deprecated
* `Field` is deprecated and might be removed in the future major release. Please use `TypeCastField` type instead.
*/
declare interface Field extends TypeCastField {}
export { Field };

View File

@@ -0,0 +1,27 @@
declare interface FieldPacket {
constructor: {
name: 'FieldPacket';
};
catalog: string;
charsetNr?: number;
db?: string;
schema?: string;
characterSet?: number;
decimals: number;
default?: any;
flags: number | string[];
length?: number;
name: string;
orgName: string;
orgTable: string;
protocol41?: boolean;
table: string;
type?: number;
columnType?: number;
zerofill?: boolean;
typeName?: string;
encoding?: string;
columnLength?: number;
}
export { FieldPacket };

View File

@@ -0,0 +1,23 @@
/**
* @deprecated
* `OkPacket` is deprecated and might be removed in the future major release. Please use `ResultSetHeader` instead.
*/
declare interface OkPacket {
constructor: {
name: 'OkPacket';
};
fieldCount: number;
affectedRows: number;
/**
* @deprecated
* `changedRows` is deprecated and might be removed in the future major release. Please use `affectedRows` property instead.
*/
changedRows: number;
insertId: number;
serverStatus: number;
warningCount: number;
message: string;
protocol41: boolean;
}
export { OkPacket };

View File

@@ -0,0 +1,13 @@
import { OkPacket } from './OkPacket.js';
import { ResultSetHeader } from './ResultSetHeader.js';
import { RowDataPacket } from './RowDataPacket.js';
declare type ProcedureCallPacket<
T = [RowDataPacket[], ResultSetHeader] | ResultSetHeader,
> = T extends RowDataPacket[]
? [T, ResultSetHeader]
: T extends ResultSetHeader | OkPacket
? ResultSetHeader
: [RowDataPacket[], ResultSetHeader] | ResultSetHeader;
export { ProcedureCallPacket };

View File

@@ -0,0 +1,18 @@
declare interface ResultSetHeader {
constructor: {
name: 'ResultSetHeader';
};
affectedRows: number;
fieldCount: number;
info: string;
insertId: number;
serverStatus: number;
warningStatus: number;
/**
* @deprecated
* `changedRows` is deprecated and might be removed in the future major release. Please use `affectedRows` property instead.
*/
changedRows: number;
}
export { ResultSetHeader };

View File

@@ -0,0 +1,9 @@
declare interface RowDataPacket {
constructor: {
name: 'RowDataPacket';
};
[column: string]: any;
[column: number]: any;
}
export { RowDataPacket };

View File

@@ -0,0 +1,28 @@
import { OkPacket } from './OkPacket.js';
import { RowDataPacket } from './RowDataPacket.js';
import { FieldPacket } from './FieldPacket.js';
import { Field } from './Field.js';
import { ProcedureCallPacket } from './ProcedurePacket.js';
import { ResultSetHeader } from './ResultSetHeader.js';
import { OkPacketParams } from './params/OkPacketParams.js';
import { ErrorPacketParams } from './params/ErrorPacketParams.js';
export type QueryResult =
| OkPacket
| ResultSetHeader
| ResultSetHeader[]
| RowDataPacket[]
| RowDataPacket[][]
| OkPacket[]
| ProcedureCallPacket;
export {
OkPacket,
RowDataPacket,
FieldPacket,
Field,
ProcedureCallPacket,
ResultSetHeader,
OkPacketParams,
ErrorPacketParams,
};

View File

@@ -0,0 +1,6 @@
declare interface ErrorPacketParams {
message?: string;
code?: number | string;
}
export { ErrorPacketParams };

View File

@@ -0,0 +1,9 @@
declare interface OkPacketParams {
affectedRows?: number;
insertId?: number;
serverStatus?: number;
warningCount?: number;
message?: string;
}
export { OkPacketParams };

View File

@@ -0,0 +1,40 @@
import { FieldPacket, QueryResult } from '../packets/index.js';
import {
Query,
QueryError,
QueryOptions,
QueryableConstructor,
} from './Query.js';
export declare function ExecutableBase<T extends QueryableConstructor>(
Base?: T
): {
new (...args: any[]): {
execute<T extends QueryResult>(
sql: string,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| undefined
): Query;
execute<T extends QueryResult>(
sql: string,
values: any,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| undefined
): Query;
execute<T extends QueryResult>(
options: QueryOptions,
callback?:
| ((err: QueryError | null, result: T, fields?: FieldPacket[]) => any)
| undefined
): Query;
execute<T extends QueryResult>(
options: QueryOptions,
values: any,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| undefined
): Query;
};
} & T;

View File

@@ -0,0 +1,65 @@
import { Sequence } from './Sequence.js';
import { Query, QueryError, StreamOptions } from '../sequences/Query.js';
import {
OkPacket,
FieldPacket,
RowDataPacket,
ResultSetHeader,
} from '../packets/index.js';
import { Readable } from 'stream';
export class PrepareStatementInfo {
close(): void;
execute<
T extends
| RowDataPacket[][]
| RowDataPacket[]
| OkPacket
| OkPacket[]
| ResultSetHeader,
>(
parameters: any | any[] | { [param: string]: any },
callback?: (err: QueryError | null, result: T, fields: FieldPacket[]) => any
): Query;
}
declare class Prepare extends Sequence {
/**
* The SQL for a constructed query
*/
sql: string;
/**
* Emits a query packet to start the query
*/
start(): void;
/**
* Determines the packet class to use given the first byte of the packet.
*
* @param firstByte The first byte of the packet
* @param parser The packet parser
*/
determinePacket(firstByte: number, parser: any): any;
/**
* Creates a Readable stream with the given options
*
* @param options The options for the stream.
*/
stream(options?: StreamOptions): Readable;
on(event: string, listener: (args: []) => void): this;
on(event: 'error', listener: (err: QueryError) => any): this;
on(
event: 'fields',
listener: (fields: FieldPacket, index: number) => any
): this;
on(
event: 'result',
listener: (result: RowDataPacket | OkPacket, index: number) => any
): this;
on(event: 'end', listener: () => any): this;
}
export { Prepare };

View File

@@ -0,0 +1,170 @@
import { Sequence } from './Sequence.js';
import { OkPacket, RowDataPacket, FieldPacket } from '../packets/index.js';
import { Readable } from 'stream';
import { TypeCast } from '../../parsers/typeCast.js';
export interface QueryOptions {
/**
* The SQL for the query
*/
sql: string;
/**
* The values for the query
*/
values?: any | any[] | { [param: string]: any };
/**
* This overrides the namedPlaceholders option set at the connection level.
*/
namedPlaceholders?: boolean;
/**
* Every operation takes an optional inactivity timeout option. This allows you to specify appropriate timeouts for
* operations. It is important to note that these timeouts are not part of the MySQL protocol, and rather timeout
* operations through the client. This means that when a timeout is reached, the connection it occurred on will be
* destroyed and no further operations can be performed.
*/
timeout?: number;
/**
* Either a boolean or string. If true, tables will be nested objects. If string (e.g. '_'), tables will be
* nested as tableName_fieldName
*/
nestTables?: any;
/**
* Determines if column values should be converted to native JavaScript types.
*
* @default true
*
* It is not recommended (and may go away / change in the future) to disable type casting, but you can currently do so on either the connection or query level.
*
* ---
*
* You can also specify a function to do the type casting yourself:
* ```ts
* (field: Field, next: () => unknown) => {
* return next();
* }
* ```
*
* ---
*
* **WARNING:**
*
* YOU MUST INVOKE the parser using one of these three field functions in your custom typeCast callback. They can only be called once:
*
* ```js
* field.string();
* field.buffer();
* field.geometry();
* ```
* Which are aliases for:
*
* ```js
* parser.parseLengthCodedString();
* parser.parseLengthCodedBuffer();
* parser.parseGeometryValue();
* ```
*
* You can find which field function you need to use by looking at `RowDataPacket.prototype._typeCast`.
*/
typeCast?: TypeCast;
/**
* This overrides the same option set at the connection level.
*
*/
rowsAsArray?: boolean;
/**
* By specifying a function that returns a readable stream, an arbitrary stream can be sent when sending a local fs file.
*/
infileStreamFactory?: (path: string) => Readable;
}
export interface StreamOptions {
/**
* Sets the max buffer size in objects of a stream
*/
highWaterMark?: number;
/**
* The object mode of the stream (Default: true)
*/
objectMode?: any;
}
export interface QueryError extends NodeJS.ErrnoException {
/**
* Either a MySQL server error (e.g. 'ER_ACCESS_DENIED_ERROR'),
* a node.js error (e.g. 'ECONNREFUSED') or an internal error
* (e.g. 'PROTOCOL_CONNECTION_LOST').
*/
code: string;
/**
* The sql state marker
*/
sqlStateMarker?: string;
/**
* The sql state
*/
sqlState?: string;
/**
* The field count
*/
fieldCount?: number;
/**
* Boolean, indicating if this error is terminal to the connection object.
*/
fatal: boolean;
}
declare class Query extends Sequence {
/**
* The SQL for a constructed query
*/
sql: string;
/**
* Emits a query packet to start the query
*/
start(): void;
/**
* Determines the packet class to use given the first byte of the packet.
*
* @param firstByte The first byte of the packet
* @param parser The packet parser
*/
determinePacket(firstByte: number, parser: any): any;
/**
* Creates a Readable stream with the given options
*
* @param options The options for the stream.
*/
stream(options?: StreamOptions): Readable;
on(event: string, listener: (...args: any[]) => void): this;
on(event: 'error', listener: (err: QueryError) => any): this;
on(
event: 'fields',
listener: (fields: FieldPacket, index: number) => any
): this;
on(
event: 'result',
listener: (result: RowDataPacket | OkPacket, index: number) => any
): this;
on(event: 'end', listener: () => any): this;
}
export type QueryableConstructor<T = object> = new (...args: any[]) => T;
export { Query };

View File

@@ -0,0 +1,40 @@
import { FieldPacket, QueryResult } from '../packets/index.js';
import {
Query,
QueryError,
QueryOptions,
QueryableConstructor,
} from './Query.js';
export declare function QueryableBase<T extends QueryableConstructor>(
Base?: T
): {
new (...args: any[]): {
query<T extends QueryResult>(
sql: string,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| undefined
): Query;
query<T extends QueryResult>(
sql: string,
values: any,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| undefined
): Query;
query<T extends QueryResult>(
options: QueryOptions,
callback?:
| ((err: QueryError | null, result: T, fields?: FieldPacket[]) => any)
| undefined
): Query;
query<T extends QueryResult>(
options: QueryOptions,
values: any,
callback?:
| ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
| undefined
): Query;
};
} & T;

View File

@@ -0,0 +1,5 @@
import { EventEmitter } from 'events';
declare class Sequence extends EventEmitter {}
export { Sequence };

View File

@@ -0,0 +1,21 @@
import { FieldPacket, QueryResult } from '../../packets/index.js';
import { QueryOptions, QueryableConstructor } from '../Query.js';
export declare function ExecutableBase<T extends QueryableConstructor>(
Base?: T
): {
new (...args: any[]): {
execute<T extends QueryResult>(sql: string): Promise<[T, FieldPacket[]]>;
execute<T extends QueryResult>(
sql: string,
values: any
): Promise<[T, FieldPacket[]]>;
execute<T extends QueryResult>(
options: QueryOptions
): Promise<[T, FieldPacket[]]>;
execute<T extends QueryResult>(
options: QueryOptions,
values: any
): Promise<[T, FieldPacket[]]>;
};
} & T;

View File

@@ -0,0 +1,21 @@
import { FieldPacket, QueryResult } from '../../packets/index.js';
import { QueryOptions, QueryableConstructor } from '../Query.js';
export declare function QueryableBase<T extends QueryableConstructor>(
Base?: T
): {
new (...args: any[]): {
query<T extends QueryResult>(sql: string): Promise<[T, FieldPacket[]]>;
query<T extends QueryResult>(
sql: string,
values: any
): Promise<[T, FieldPacket[]]>;
query<T extends QueryResult>(
options: QueryOptions
): Promise<[T, FieldPacket[]]>;
query<T extends QueryResult>(
options: QueryOptions,
values: any
): Promise<[T, FieldPacket[]]>;
};
} & T;