Constructor

SessionPool

new SessionPool(database, options)

Class used to manage connections to Spanner.

You don't need to use this class directly, connections will be handled for you.

Parameter

database

Database

The DB instance.

options

Optional

SessionPoolOptions

Configuration options.

Extends
EventEmitter

Properties

database

read-only

Database

isOpen

read-only

boolean

options

read-only

SessionPoolOptions

Methods

available

available() returns number

Returns the number of available sessions.

Returns

number 

borrowed

borrowed() returns number

Returns the number of borrowed sessions.

Returns

number 

close

close() returns Promise

Closes and the pool.

Fires
SessionPool#event:close
Returns

Promise 

fill

fill() returns Promise

Fills the pool with the minimum number of sessions.

Returns

Promise 

getLeaks

getLeaks() returns Array of string

Returns stack traces for sessions that have not been released.

Returns

Array of string 

getSession

getSession() returns Promise containing Session

Retrieve a read session.

Returns

Promise containing Session 

getWriteSession

getWriteSession() returns Promise containing Session

Retrieve the write session.

Returns

Promise containing Session 

isFull

isFull() returns boolean

Checks to see if the pool is full by calculating the current size and the pending number of sessions being created.

Returns

boolean 

open

open() returns Promise

Opens the pool, filling it to the configured number of read and write sessions.

Fires
SessionPool#event:open
Returns

Promise 

release

release(session)

Releases session back into the pool. If the session is a write session it will also prepare a new transaction before releasing it.

Parameter

session

Session

The session to release.

Fires
SessionPool#event:available
SessionPool#event:error
Throws

Error 

For unknown sessions.

request

request(config, callback)

Make an API request, first assuring an active session is used.

Parameter

config

object

callback

function()

requestStream

requestStream(config) returns Stream

Make an API request as a stream, first assuring an active session is used.

Parameter

config

object

Returns

Stream 

size

size() returns number

Returns the current size of the pool.

Returns

number