@types/mysql
- Version 2.15.27
- Published
- 25.3 kB
- 1 dependency
- MIT license
Install
npm i @types/mysqlyarn add @types/mysqlpnpm add @types/mysqlOverview
TypeScript definitions for mysql
Index
Functions
Interfaces
Enums
Type Aliases
Functions
function createConnection
createConnection: (connectionUri: string | ConnectionConfig) => Connection;function createPool
createPool: (config: PoolConfig | string) => Pool;function createPoolCluster
createPoolCluster: (config?: PoolClusterConfig) => PoolCluster;function escape
escape: (value: any, stringifyObjects?: boolean, timeZone?: string) => string;Escape an untrusted string to be used as a SQL value. Use this on user provided data.
Parameter value
Value to escape
Parameter stringifyObjects
If true, don't convert objects into SQL lists
Parameter timeZone
Convert dates from UTC to the given timezone.
function escapeId
escapeId: (value: string, forbidQualified?: boolean) => string;Escape an untrusted string to be used as a SQL identifier (database, table, or column name). Use this on user provided data.
Parameter value
Value to escape.
Parameter forbidQualified
Don't allow qualified identifiers (eg escape '.')
function format
format: ( sql: string, values?: any[], stringifyObjects?: boolean, timeZone?: string) => string;Safely format a SQL query containing multiple untrusted values.
Parameter sql
Query, with insertion points specified with ? (for values) or ?? (for identifiers)
Parameter values
Array of objects to insert.
Parameter stringifyObjects
If true, don't convert objects into SQL lists
Parameter timeZone
Convert dates from UTC to the given timezone.
function raw
raw: (sql: string) => { toSqlString: () => string };Create a string that will be inserted unescaped with format(), escape(). Note: the value will still be escaped if used as an identifier (??) by format().
Parameter sql
Interfaces
interface Connection
interface Connection extends EscapeFunctions, events.EventEmitter {}property config
config: ConnectionConfig;property createQuery
createQuery: QueryFunction;property query
query: QueryFunction;property state
state: | 'connected' | 'authenticated' | 'disconnected' | 'protocol_error' | (string & {});property threadId
threadId: number | null;method beginTransaction
beginTransaction: { (options?: QueryOptions, callback?: (err: MysqlError) => void): void; (callback: (err: MysqlError) => void): void;};method changeUser
changeUser: { (options: ConnectionOptions, callback?: (err: MysqlError) => void): void; (callback: (err: MysqlError) => void): void;};method commit
commit: { (options?: QueryOptions, callback?: (err: MysqlError) => void): void; (callback: (err: MysqlError) => void): void;};method connect
connect: { (callback?: (err: MysqlError, ...args: any[]) => void): void; (options: any, callback?: (err: MysqlError, ...args: any[]) => void): void;};method destroy
destroy: () => void;Close the connection immediately, without waiting for any queued data (eg queries) to be sent. No further events or callbacks will be triggered.
method end
end: { (callback?: (err?: MysqlError) => void): void; (options: any, callback: (err?: MysqlError) => void): void;};Close the connection. Any queued data (eg queries) will be sent first. If there are any fatal errors, the connection will be immediately closed.
Parameter callback
Handler for any fatal error
method pause
pause: () => void;Pause the connection. No more 'result' events will fire until resume() is called.
method ping
ping: { (options?: QueryOptions, callback?: (err: MysqlError) => void): void; (callback: (err: MysqlError) => void): void;};method resume
resume: () => void;Resume the connection.
method rollback
rollback: { (options?: QueryOptions, callback?: (err: MysqlError) => void): void; (callback: (err: MysqlError) => void): void;};method statistics
statistics: { (options?: QueryOptions, callback?: (err: MysqlError) => void): void; (callback: (err: MysqlError) => void): void;};interface ConnectionConfig
interface ConnectionConfig extends ConnectionOptions {}property bigNumberStrings
bigNumberStrings?: boolean | undefined;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] (http://ecma262-5.com/ELS5_HTML.htm#Section_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.
property connectTimeout
connectTimeout?: number | undefined;The milliseconds before a timeout occurs during the initial connection to the MySQL server. (Default: 10 seconds)
property dateStrings
dateStrings?: boolean | Array<'TIMESTAMP' | 'DATETIME' | 'DATE'> | undefined;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)
property debug
debug?: boolean | string[] | Types[] | undefined;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)
property flags
flags?: string | string[] | undefined;List of connection flags to use other than the default ones. It is also possible to blacklist default ones
property host
host?: string | undefined;The hostname of the database you are connecting to. (Default: localhost)
property insecureAuth
insecureAuth?: boolean | undefined;Allow connecting to MySQL instances that ask for the old (insecure) authentication method. (Default: false)
property localAddress
localAddress?: string | undefined;The source IP address to use for TCP connection
property multipleStatements
multipleStatements?: boolean | undefined;Allow multiple mysql statements per query. Be careful with this, it exposes you to SQL injection attacks. (Default: false)
property port
port?: number | undefined;The port number to connect to. (Default: 3306)
property socketPath
socketPath?: string | undefined;The path to a unix domain socket to connect to. When used host and port are ignored
property ssl
ssl?: | string | (tls.SecureContextOptions & { rejectUnauthorized?: boolean | undefined }) | undefined;object with ssl parameters or a string containing name of ssl profile
property stringifyObjects
stringifyObjects?: boolean | undefined;Stringify objects instead of converting to values. (Default: 'false')
property supportBigNumbers
supportBigNumbers?: boolean | undefined;When dealing with big numbers (BIGINT and DECIMAL columns) in the database, you should enable this option (Default: false)
property timezone
timezone?: string | undefined;The timezone used to store local dates. (Default: 'local')
property trace
trace?: boolean | undefined;Generates stack traces on errors to include call site of library entrance ("long stack traces"). Slight performance penalty for most calls. (Default: true)
property typeCast
typeCast?: TypeCast | undefined;Determines if column values should be converted to native JavaScript types. 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. (Default: true)
You can also specify a function (field: any, next: () => void) => {} to do the type casting yourself.
WARNING: YOU MUST INVOKE the parser using one of these three field functions in your custom typeCast callback. They can only be called once.
field.string() field.buffer() field.geometry()
are aliases for
parser.parseLengthCodedString() parser.parseLengthCodedBuffer() parser.parseGeometryValue()
You can find which field function you need to use by looking at: RowDataPacket.prototype._typeCast
method queryFormat
queryFormat: (query: string, values: any) => string;A custom query format function
interface ConnectionOptions
interface ConnectionOptions {}property charset
charset?: string | undefined;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')
property database
database?: string | undefined;Name of the database to use for this connection
property password
password?: string | undefined;The password of that MySQL user
property timeout
timeout?: number | undefined;Number of milliseconds
property user
user?: string | undefined;The MySQL user to authenticate as
interface EscapeFunctions
interface EscapeFunctions {}method escape
escape: (value: any, stringifyObjects?: boolean, timeZone?: string) => string;Escape an untrusted string to be used as a SQL value. Use this on user provided data.
Parameter value
Value to escape
Parameter stringifyObjects
If true, don't convert objects into SQL lists
Parameter timeZone
Convert dates from UTC to the given timezone.
method escapeId
escapeId: (value: string, forbidQualified?: boolean) => string;Escape an untrusted string to be used as a SQL identifier (database, table, or column name). Use this on user provided data.
Parameter value
Value to escape.
Parameter forbidQualified
Don't allow qualified identifiers (eg escape '.')
method format
format: ( sql: string, values?: any[], stringifyObjects?: boolean, timeZone?: string) => string;Safely format a SQL query containing multiple untrusted values.
Parameter sql
Query, with insertion points specified with ? (for values) or ?? (for identifiers)
Parameter values
Array of objects to insert.
Parameter stringifyObjects
If true, don't convert objects into SQL lists
Parameter timeZone
Convert dates from UTC to the given timezone.
interface GeometryType
interface GeometryType extends Array<{ x: number; y: number } | GeometryType> {}interface MysqlError
interface MysqlError extends Error {}property code
code: string;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').
property errno
errno: number;The error number for the error code
property fatal
fatal: boolean;Boolean, indicating if this error is terminal to the connection object.
property fieldCount
fieldCount?: number | undefined;The field count
property sql
sql?: string | undefined;SQL of failed query
property sqlMessage
sqlMessage?: string | undefined;Error message from MySQL
property sqlState
sqlState?: string | undefined;The sql state
property sqlStateMarker
sqlStateMarker?: string | undefined;The sql state marker
interface OkPacket
interface OkPacket {}property affectedRows
affectedRows: number;The number of affected rows from an insert, update, or delete statement.
property changedRows
changedRows: number;The number of changed rows from an update statement. "changedRows" differs from "affectedRows" in that it does not count updated rows whose values were not changed.
property fieldCount
fieldCount: number;property insertId
insertId: number;The insert id after inserting a row into a table with an auto increment primary key.
property message
message: string;The server result message from an insert, update, or delete statement.
property protocol41
protocol41: boolean;property serverStatus
serverStatus?: number | undefined;property warningCount
warningCount?: number | undefined;interface Pool
interface Pool extends EscapeFunctions, events.EventEmitter {}property config
config: PoolActualConfig;property query
query: QueryFunction;method acquireConnection
acquireConnection: ( connection: PoolConnection, callback: (err: MysqlError, connection: PoolConnection) => void) => void;method end
end: (callback?: (err: MysqlError) => void) => void;Close the connection. Any queued data (eg queries) will be sent first. If there are any fatal errors, the connection will be immediately closed.
Parameter callback
Handler for any fatal error
method getConnection
getConnection: ( callback: (err: MysqlError, connection: PoolConnection) => void) => void;interface PoolActualConfig
interface PoolActualConfig extends PoolSpecificConfig {}property connectionConfig
connectionConfig: ConnectionConfig;interface PoolCluster
interface PoolCluster extends events.EventEmitter {}property config
config: PoolClusterConfig;method add
add: { (config: PoolConfig): void; (id: string, config: PoolConfig): void };method end
end: (callback?: (err: MysqlError) => void) => void;Close the connection. Any queued data (eg queries) will be sent first. If there are any fatal errors, the connection will be immediately closed.
Parameter callback
Handler for any fatal error
method getConnection
getConnection: { (callback: (err: MysqlError, connection: PoolConnection) => void): void; ( pattern: string, callback: (err: MysqlError, connection: PoolConnection) => void ): void; ( pattern: string, selector: string, callback: (err: MysqlError, connection: PoolConnection) => void ): void;};method of
of: { (pattern: string, selector?: string): Pool; (pattern: false, selector: string): Pool;};method remove
remove: (pattern: string) => void;remove all pools which match pattern
interface PoolClusterConfig
interface PoolClusterConfig {}property canRetry
canRetry?: boolean | undefined;If true, PoolCluster will attempt to reconnect when connection fails. (Default: true)
property defaultSelector
defaultSelector?: string | undefined;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.
property removeNodeErrorCount
removeNodeErrorCount?: number | undefined;If connection fails, node's errorCount increases. When errorCount is greater than removeNodeErrorCount, remove a node in the PoolCluster. (Default: 5)
property restoreNodeTimeout
restoreNodeTimeout?: number | undefined;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)
interface PoolConfig
interface PoolConfig extends PoolSpecificConfig, ConnectionConfig {}interface PoolConnection
interface PoolConnection extends Connection {}method destroy
destroy: () => void;Close the connection immediately, without waiting for any queued data (eg queries) to be sent. No further events or callbacks will be triggered.
method end
end: () => void;Close the connection. Any queued data (eg queries) will be sent first. If there are any fatal errors, the connection will be immediately closed.
Parameter callback
Handler for any fatal error
method release
release: () => void;interface PoolSpecificConfig
interface PoolSpecificConfig {}property acquireTimeout
acquireTimeout?: number | undefined;The milliseconds before a timeout occurs during the connection acquisition. This is slightly different from connectTimeout, because acquiring a pool connection does not always involve making a connection. (Default: 10 seconds)
property connectionLimit
connectionLimit?: number | undefined;The maximum number of connections to create at once. (Default: 10)
property queueLimit
queueLimit?: number | undefined;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)
property waitForConnections
waitForConnections?: boolean | undefined;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)
interface Query
interface Query {}property EofPacket
EofPacket: packetCallback;property ErrorPacket
ErrorPacket: packetCallback;property FieldPacket
FieldPacket: packetCallback;property nestedTables
nestedTables: boolean;Default false
property OkPacket
OkPacket: packetCallback;property ResultSetHeaderPacket
ResultSetHeaderPacket: packetCallback;property sql
sql: string;Template query
property typeCast
typeCast?: TypeCast | undefined;Default true
property values
values?: string[] | undefined;Values for template query
method determinePacket
determinePacket: (byte: number, parser: any) => any;Determines the packet class to use given the first byte of the packet.
Parameter byte
The first byte of the packet
Parameter parser
The packet parser
method on
on: { (ev: string, callback: (...args: any[]) => void): Query; (ev: 'result', callback: (row: any, index: number) => void): Query; (ev: 'error', callback: (err: MysqlError) => void): Query; ( ev: 'fields', callback: (fields: FieldInfo[], index: number) => void ): Query; (ev: 'packet', callback: (packet: any) => void): Query; (ev: 'end', callback: () => void): Query;};method RowDataPacket
RowDataPacket: (packet: any, parser: any, connection: Connection) => void;method start
start: () => void;Emits a query packet to start the query
method stream
stream: (options?: stream.ReadableOptions) => stream.Readable;Creates a Readable stream with the given options
Parameter options
The options for the stream. (see readable-stream package)
interface QueryFunction
interface QueryFunction {}call signature
(query: Query): Query;call signature
(options: string | QueryOptions, callback?: queryCallback): Query;call signature
(options: string | QueryOptions, values: any, callback?: queryCallback): Query;interface QueryOptions
interface QueryOptions {}property nestTables
nestTables?: any;Either a boolean or string. If true, tables will be nested objects. If string (e.g. '_'), tables will be nested as tableName_fieldName
property sql
sql: string;The SQL for the query
property timeout
timeout?: number | undefined;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.
property typeCast
typeCast?: TypeCast | undefined;Determines if column values should be converted to native JavaScript types. 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. (Default: true)
You can also specify a function (field: any, next: () => void) => {} to do the type casting yourself.
WARNING: YOU MUST INVOKE the parser using one of these three field functions in your custom typeCast callback. They can only be called once.
field.string() field.buffer() field.geometry()
are aliases for
parser.parseLengthCodedString() parser.parseLengthCodedBuffer() parser.parseGeometryValue()
You can find which field function you need to use by looking at: RowDataPacket.prototype._typeCast
property values
values?: any;Values for template query
interface UntypedFieldInfo
interface UntypedFieldInfo {}property catalog
catalog: string;property charsetNr
charsetNr: number;property db
db: string;property decimals
decimals: number;property default
default?: string | undefined;property flags
flags: number;property length
length: number;property name
name: string;property orgName
orgName: string;property orgTable
orgTable: string;property protocol41
protocol41: boolean;property table
table: string;property zeroFill
zeroFill: boolean;Enums
enum Types
const enum Types { DECIMAL = 0x00, TINY = 0x01, SHORT = 0x02, LONG = 0x03, FLOAT = 0x04, DOUBLE = 0x05, NULL = 0x06, TIMESTAMP = 0x07, LONGLONG = 0x08, INT24 = 0x09, DATE = 0x0a, TIME = 0x0b, DATETIME = 0x0c, YEAR = 0x0d, NEWDATE = 0x0e, VARCHAR = 0x0f, BIT = 0x10, TIMESTAMP2 = 0x11, DATETIME2 = 0x12, TIME2 = 0x13, JSON = 0xf5, NEWDECIMAL = 0xf6, ENUM = 0xf7, SET = 0xf8, TINY_BLOB = 0xf9, MEDIUM_BLOB = 0xfa, LONG_BLOB = 0xfb, BLOB = 0xfc, VAR_STRING = 0xfd, STRING = 0xfe, GEOMETRY = 0xff,}member BIT
BIT = 0x10member BLOB
BLOB = 0xfcmember DATE
DATE = 0x0amember DATETIME
DATETIME = 0x0cmember DATETIME2
DATETIME2 = 0x12member DECIMAL
DECIMAL = 0x00member DOUBLE
DOUBLE = 0x05member ENUM
ENUM = 0xf7member FLOAT
FLOAT = 0x04member GEOMETRY
GEOMETRY = 0xffmember INT24
INT24 = 0x09member JSON
JSON = 0xf5member LONG
LONG = 0x03member LONG_BLOB
LONG_BLOB = 0xfbmember LONGLONG
LONGLONG = 0x08member MEDIUM_BLOB
MEDIUM_BLOB = 0xfamember NEWDATE
NEWDATE = 0x0emember NEWDECIMAL
NEWDECIMAL = 0xf6member NULL
NULL = 0x06member SET
SET = 0xf8member SHORT
SHORT = 0x02member STRING
STRING = 0xfemember TIME
TIME = 0x0bmember TIME2
TIME2 = 0x13member TIMESTAMP
TIMESTAMP = 0x07member TIMESTAMP2
TIMESTAMP2 = 0x11member TINY
TINY = 0x01member TINY_BLOB
TINY_BLOB = 0xf9member VAR_STRING
VAR_STRING = 0xfdmember VARCHAR
VARCHAR = 0x0fmember YEAR
YEAR = 0x0dType Aliases
type packetCallback
type packetCallback = (packet: any) => void;type queryCallback
type queryCallback = ( err: MysqlError | null, results?: any, fields?: FieldInfo[]) => void;type TypeCast
type TypeCast = | boolean | (( field: UntypedFieldInfo & { type: string; length: number; string(): null | string; buffer(): null | Buffer; geometry(): null | GeometryType; }, next: () => any ) => any);Package Files (1)
Dependencies (1)
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/mysql.
- Markdown[](https://www.jsdocs.io/package/@types/mysql)
- HTML<a href="https://www.jsdocs.io/package/@types/mysql"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 5361 ms. - Missing or incorrect documentation? Open an issue for this package.
