index.d.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * sqlstring types are based on https://www.npmjs.com/package/@types/sqlstring, version 2.3.2
  3. */
  4. import { Pool as BasePool, PoolOptions } from './lib/Pool.js';
  5. import {
  6. Connection as BaseConnection,
  7. ConnectionOptions,
  8. SslOptions,
  9. } from './lib/Connection.js';
  10. import {
  11. Query as BaseQuery,
  12. QueryOptions,
  13. QueryError,
  14. } from './lib/protocol/sequences/Query.js';
  15. import {
  16. PoolCluster as BasePoolCluster,
  17. PoolClusterOptions,
  18. PoolNamespace,
  19. } from './lib/PoolCluster.js';
  20. import { PoolConnection as BasePoolConnection } from './lib/PoolConnection.js';
  21. import {
  22. Prepare as BasePrepare,
  23. PrepareStatementInfo,
  24. } from './lib/protocol/sequences/Prepare.js';
  25. import { Server } from './lib/Server.js';
  26. export {
  27. ConnectionOptions,
  28. SslOptions,
  29. PoolOptions,
  30. PoolClusterOptions,
  31. PoolNamespace,
  32. QueryOptions,
  33. QueryError,
  34. PrepareStatementInfo,
  35. };
  36. export * from './lib/protocol/packets/index.js';
  37. export * from './lib/Auth.js';
  38. export * from './lib/constants/index.js';
  39. export * from './lib/parsers/index.js';
  40. // Expose class interfaces
  41. export interface Connection extends BaseConnection {}
  42. export interface Pool extends BasePool {}
  43. export interface PoolConnection extends BasePoolConnection {}
  44. export interface PoolCluster extends BasePoolCluster {}
  45. export interface Query extends BaseQuery {}
  46. export interface Prepare extends BasePrepare {}
  47. export function createConnection(connectionUri: string): BaseConnection;
  48. export function createConnection(config: ConnectionOptions): BaseConnection;
  49. export function createPool(connectionUri: string): BasePool;
  50. export function createPool(config: PoolOptions): BasePool;
  51. export function createPoolCluster(config?: PoolClusterOptions): PoolCluster;
  52. type TimeZone = 'local' | 'Z' | (string & NonNullable<unknown>);
  53. export function escape(
  54. value: any,
  55. stringifyObjects?: boolean,
  56. timeZone?: TimeZone,
  57. ): string;
  58. export function escapeId(value: any, forbidQualified?: boolean): string;
  59. export function format(sql: string): string;
  60. export function format(
  61. sql: string,
  62. values: any | any[],
  63. stringifyObjects?: boolean,
  64. timeZone?: TimeZone,
  65. ): string;
  66. export function raw(sql: string): {
  67. toSqlString: () => string;
  68. };
  69. export interface ConnectionConfig extends ConnectionOptions {
  70. mergeFlags(defaultFlags: string[], userFlags: string[] | string): number;
  71. getDefaultFlags(options?: ConnectionOptions): string[];
  72. getCharsetNumber(charset: string): number;
  73. getSSLProfile(name: string): { ca: string[] };
  74. parseUrl(url: string): {
  75. host: string;
  76. port: number;
  77. database: string;
  78. user: string;
  79. password: string;
  80. [key: string]: any;
  81. };
  82. }
  83. export function createServer(handler: (conn: BaseConnection) => any): Server;