Bun

interface

SQLOptions

interface SQLOptions

Configuration options for SQL client connection and behavior

const config: SQLOptions = {
  host: 'localhost',
  port: 5432,
  user: 'dbuser',
  password: 'secretpass',
  database: 'myapp',
  idleTimeout: 30,
  max: 20,
  onconnect: (client) => {
    console.log('Connected to database');
  }
};
  • adapter?: string

    Database adapter/driver to use

  • bigint?: boolean

    By default values outside i32 range are returned as strings. If this is true, values outside i32 range are returned as BigInts.

  • connection_timeout?: number

    Maximum time in seconds to wait when establishing a connection (alias for connectionTimeout)

  • connectionTimeout?: number

    Maximum time in seconds to wait when establishing a connection

  • database?: string

    Name of the database to connect to

  • db?: string

    Name of the database to connect to (alias for database)

  • host?: string

    Database server hostname

  • hostname?: string

    Database server hostname (alias for host)

  • idle_timeout?: number

    Maximum time in seconds to wait for connection to become available (alias for idleTimeout)

  • idleTimeout?: number

    Maximum time in seconds to wait for connection to become available

  • max?: number

    Maximum number of connections in the pool

  • max_lifetime?: number

    Maximum lifetime in seconds of a connection (alias for maxLifetime)

  • maxLifetime?: number

    Maximum lifetime in seconds of a connection

  • onclose?: (client: SQL) => void

    Callback function executed when a connection is closed

  • onconnect?: (client: SQL) => void

    Callback function executed when a connection is established

  • pass?: string | () => Promise<string>

    Database password for authentication (alias for password)

  • password?: string | () => Promise<string>

    Database password for authentication

  • port?: string | number

    Database server port number

  • prepare?: boolean

    Automatic creation of prepared statements, defaults to true

  • ssl?: boolean | TLSOptions

    Whether to use TLS/SSL for the connection (alias for tls)

  • tls?: boolean | TLSOptions

    Whether to use TLS/SSL for the connection

  • url?: string | URL

    Connection URL (can be string or URL object)

  • user?: string

    Database user for authentication (alias for username)

  • username?: string

    Database user for authentication