planetscale / database-js

A Fetch API-compatible PlanetScale database driver
https://planetscale.com/docs/tutorials/planetscale-serverless-driver
Apache License 2.0
1.17k stars 35 forks source link

what is the use of connect.refresh #117

Closed shiyuhang0 closed 1 year ago

shiyuhang0 commented 1 year ago

I find there is a refresh method in connect

const config = {
  host: '<host>',
  username: '<user>',
  password: '<password>'
}

const conn = connect(config)
conn.refresh()

I wonder the use of the refresh and in which situation I need to call this method.

I looked through the official doc and this repo but not find the answer

iheanyi commented 1 year ago

Think of it as creating a new session. For context, the session is used for keeping an identifier for a connection over HTTP and keeps that connection warm. This session is implicitly created whenever a query is executed and sent on subsequent queries. You can call refresh immediately after connecting because that will warm up the connection so your first query is faster.